-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheloqua-ruby-request.rb
More file actions
55 lines (43 loc) · 1.17 KB
/
eloqua-ruby-request.rb
File metadata and controls
55 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'net/https'
class EloquaRequest
attr_reader :site, :user
def initialize(site=nil, user=nil, password=nil, baseUrl=nil)
@site = site
@user = user
@password = password
@https = Net::HTTP.new(baseUrl, 443)
@https.use_ssl = true
@https.verify_mode = OpenSSL::SSL::VERIFY_PEER
@https.ca_file = OpenSSL::X509::DEFAULT_CERT_FILE
end
METHODS = {
:get => ::Net::HTTP::Get,
:post => ::Net::HTTP::Post,
:put => ::Net::HTTP::Put,
:delete => ::Net::HTTP::Delete
}
REST_API_PATH = "/API/REST/1.0"
def delete(path, params={})
request(:delete, path, params)
end
def get(path, params={})
request(:get, path, params)
end
def post(path, params={}, body={})
request(:post, path, params, body)
end
def put(path, params={}, body={})
request(:put, path, params, body)
end
def request(method, path, params={}, body={})
request = METHODS[method].new(REST_API_PATH + '/' + path)
request.initialize_http_header(params) if params
request.basic_auth @site + '\\' + @user, @password
case method
when :post, :put
request.body = body
end
response = @https.request(request)
return response
end
end