Class: FinerWorks::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/finerworks/request.rb

Constant Summary collapse

BASE_URL =
"http://api.finerworks.com/api"
TIME_ZONE_ID =
"UTC"

Class Method Summary collapse

Class Method Details

.get(client, path, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/finerworks/request.rb', line 9

def self.get(client, path, options = {})
  path.prepend("/") if !path.start_with?("/")
  params = ""
  options.each do |option|
    params = params + "&#{option[0].to_s}=#{option[1]}"
  end
  uri = URI.parse("#{BASE_URL}#{path}?AccountApiKey=#{client.}&TimeZoneID=#{TIME_ZONE_ID}#{params}")
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  FinerWorks::Response.new(response)
end

.post(client, path, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/finerworks/request.rb', line 22

def self.post(client, path, options = {})
  path.prepend("/") if !path.start_with?("/")
  uri = URI.parse("#{BASE_URL}#{path}?AccountApiKey=#{client.}&TimeZoneID=#{TIME_ZONE_ID}")
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)
  request.body = options.to_json
  request.content_type = "application/json"
  response = http.request(request)
  FinerWorks::Response.new(response)
end