class VzaarApi::Lib::Api
Public Class Methods
api_root_url()
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 5 def self.api_root_url "#{VzaarApi.protocol}://#{VzaarApi.hostname}/api/v2" end
resource_url(resource, path = nil)
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 9 def self.resource_url(resource, path = nil) [api_root_url, resource, path].compact.join('/') end
Public Instance Methods
delete(url)
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 13 def delete(url) handle_response http_client.delete(url, {}, headers) end
get(url, query = {})
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 17 def get(url, query = {}) handle_response http_client.get(url, query, headers) end
handle_response(response)
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 30 def handle_response(response) api_response = ApiResponse.new(response) VzaarApi.rate_limit = api_response.rate_limit VzaarApi.rate_limit_remaining = api_response.rate_limit_remaining VzaarApi.rate_limit_reset = api_response.rate_limit_reset return api_response if api_response.ok? raise Error.new(api_response.error) end
headers()
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 45 def headers { 'X-Auth-Token' => VzaarApi.auth_token, 'X-Client-Id' => VzaarApi.client_id, 'Content-Type' => 'application/json' } end
http_client()
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 39 def http_client HTTPClient.new.tap do |c| c.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE end end
patch(url, body = {})
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 21 def patch(url, body = {}) handle_response http_client.patch(url, body.to_json, headers) end
post(url, body = {}) { |body, headers| ... }
click to toggle source
# File lib/vzaar_api/lib/api.rb, line 25 def post(url, body = {}) args = block_given? ? yield(body, headers) : [body.to_json, headers] handle_response http_client.post url, *args end