class Checkmobi::SDK::Client
Public Class Methods
new(api_key = Checkmobi.api_key, api_host = 'api.checkmobi.com', api_version = 'v1')
click to toggle source
# File lib/checkmobi/client.rb, line 7 def initialize(api_key = Checkmobi.api_key, api_host = 'api.checkmobi.com', api_version = 'v1') endpoint = endpoint_generator(api_host, api_version) @http_client = RestClient::Resource.new(endpoint, headers: { :Authorization => api_key, :content_type => 'application/json' }) end
Public Instance Methods
delete(resource_path)
click to toggle source
# File lib/checkmobi/client.rb, line 45 def delete(resource_path) begin response = @http_client[resource_path].delete Checkmobi::SDK::Response.new(response) rescue => err raise communication_error err end end
get(resource_path, params = nil)
click to toggle source
# File lib/checkmobi/client.rb, line 27 def get(resource_path, params = nil) if params response = @http_client[resource_path].get(params: params) else response = @http_client[resource_path].get() end Checkmobi::SDK::Response.new(response) rescue => err raise communication_error err end
post(resource_path, data, headers = {})
click to toggle source
# File lib/checkmobi/client.rb, line 20 def post(resource_path, data, headers = {}) response = @http_client[resource_path].post(data.to_json, headers) Checkmobi::SDK::Response.new(response) rescue => err raise communication_error err end
put(resource_path, data)
click to toggle source
# File lib/checkmobi/client.rb, line 38 def put(resource_path, data) response = @http_client[resource_path].put(data.to_json) Checkmobi::SDK::Response.new(response) rescue => err raise communication_error err end
Private Instance Methods
communication_error(e)
click to toggle source
# File lib/checkmobi/client.rb, line 61 def communication_error(e) return CommunicationError.new(e.message, e.response) if e.respond_to? :response CommunicationError.new(e.message) end
endpoint_generator(api_host, api_version)
click to toggle source
# File lib/checkmobi/client.rb, line 56 def endpoint_generator(api_host, api_version) scheme = 'https' "#{scheme}://#{api_host}/#{api_version}" end