Class: Checkmobi::SDK::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/checkmobi/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key = Checkmobi.api_key, api_host = 'api.checkmobi.com', api_version = 'v1') ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
16
17
18
# 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

Instance Method Details

#delete(resource_path) ⇒ Object



45
46
47
48
49
50
51
52
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# 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 = {}) ⇒ Object



20
21
22
23
24
25
# 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) ⇒ Object



38
39
40
41
42
43
# 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