Class: Copperegg::Client
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/copperegg/client.rb
Constant Summary
collapse
- JSON =
{'content-type' => 'application/json'}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
11
12
13
|
# File 'lib/copperegg/client.rb', line 11
def initialize
@api_base_uri = 'https://api.copperegg.com/v2/'
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, resource, *args) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/copperegg/client.rb', line 26
def method_missing(method, resource, *args)
if method.to_s =~ /\?$/
method = method.to_s.sub!(/\?$/, '')
result = self.send(method.to_sym, resource, *args)
return result if result.code == 200
end
end
|
Instance Attribute Details
#api_base_uri ⇒ Object
Returns the value of attribute api_base_uri.
9
10
11
|
# File 'lib/copperegg/client.rb', line 9
def api_base_uri
@api_base_uri
end
|
Instance Method Details
#auth_setup(api_key) ⇒ Object
15
16
17
18
|
# File 'lib/copperegg/client.rb', line 15
def auth_setup(api_key)
@auth = {:basic_auth => {:username => api_key, :password => 'U'}}
return self
end
|
#delete(resource, *args) ⇒ Object
42
43
44
|
# File 'lib/copperegg/client.rb', line 42
def delete(resource, *args)
HTTParty.delete(@api_base_uri + resource, @auth.to_hash)
end
|
#get(resource, *args) ⇒ Object
20
21
22
|
# File 'lib/copperegg/client.rb', line 20
def get(resource, *args)
HTTParty.get(@api_base_uri + resource, @auth.to_hash)
end
|