Class: Charger::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, subdomain) ⇒ Client

Returns a new instance of Client.



6
7
8
9
# File 'lib/charger/client.rb', line 6

def initialize api_key, subdomain
  @api_key = api_key
  @subdomain = subdomain
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



4
5
6
# File 'lib/charger/client.rb', line 4

def api_key
  @api_key
end

#subdomainObject

Returns the value of attribute subdomain.



4
5
6
# File 'lib/charger/client.rb', line 4

def subdomain
  @subdomain
end

Instance Method Details

#delete(resource, headers = {}) ⇒ Object



29
30
31
32
33
# File 'lib/charger/client.rb', line 29

def delete resource, headers={}
  JSON.parse(RestClient.delete(resource_url(resource), rest_headers(headers)))
rescue RestClient::Exception => e
  raise Charger::Exception.new(e.response)
end

#get(resource, headers = {}) ⇒ Object



11
12
13
14
15
# File 'lib/charger/client.rb', line 11

def get resource, headers={}
  JSON.parse(RestClient.get(resource_url(resource), rest_headers(headers)))
rescue RestClient::Exception => e
  raise Charger::Exception.new(e.response)
end

#post(resource, payload, headers = {}) ⇒ Object



17
18
19
20
21
# File 'lib/charger/client.rb', line 17

def post resource, payload, headers={}
  JSON.parse(RestClient.post(resource_url(resource), payload, rest_headers(headers)))
rescue RestClient::Exception => e
  raise Charger::Exception.new(e.response)
end

#put(resource, payload, headers = {}) ⇒ Object



23
24
25
26
27
# File 'lib/charger/client.rb', line 23

def put resource, payload, headers={}
  JSON.parse(RestClient.put(resource_url(resource), payload, rest_headers(headers)))
rescue RestClient::Exception => e
  raise Charger::Exception.new(e.response)
end