class VeezoLocationApi::Client
Constants
- BASE_URI
Public Class Methods
new(tenant_id)
click to toggle source
# File lib/veezo_location_api/client.rb, line 12 def initialize(tenant_id) @tenant_id = tenant_id end
Public Instance Methods
locations(occurence: Time.now)
click to toggle source
# File lib/veezo_location_api/client.rb, line 16 def locations(occurence: Time.now) uri = URI(resolve_uri('/locations')) body = { occurence: occurence } get = generate_get(uri, body) request(uri, get) end
Private Instance Methods
generate_get(uri, body = nil)
click to toggle source
# File lib/veezo_location_api/client.rb, line 30 def generate_get(uri, body = nil) get = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json') get['Accept'] = 'application/json' get.body = body.to_json if body.is_a?(Hash) get end
request(uri, request)
click to toggle source
# File lib/veezo_location_api/client.rb, line 37 def request(uri, request) http_client = Net::HTTP.new(uri.host, uri.port).tap do |client| client.use_ssl = (uri.scheme == 'https') end response = http_client.request(request) response(response) rescue => error raise(VeezoLocationApiClientError, error) end
resolve_uri(path)
click to toggle source
# File lib/veezo_location_api/client.rb, line 26 def resolve_uri(path) "#{BASE_URI}/api/v1/#{@tenant_id}#{path}" end
response(response)
click to toggle source
# File lib/veezo_location_api/client.rb, line 48 def response(response) code = response.code.to_i success = (code == 200) if success data = JSON.parse(response.body) end Response.new( success: success, status_code: code, data: data ) end