Class: Phono::Client
- Inherits:
-
Object
- Object
- Phono::Client
- Includes:
- HTTParty, HTTParty::Icebox
- Defined in:
- lib/phono/client.rb
Instance Method Summary collapse
- #all(ref, params = {}) ⇒ Object
- #create(ref, attributes = {}) ⇒ Object
- #destroy(ref, id) ⇒ Object
- #find(ref, id, params = {}) ⇒ Object
-
#initialize(api_key, params = {}) ⇒ Client
constructor
A new instance of Client.
- #update(ref, id, params = {}) ⇒ Object
Constructor Details
#initialize(api_key, params = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/phono/client.rb', line 13 def initialize(api_key, params = {}) @api_key = api_key self.class.cache(:timeout => params[:cache_timeout] || 60) end |
Instance Method Details
#all(ref, params = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/phono/client.rb', line 19 def all(ref, params = {}) params.stringify_keys! method = params.delete('cache').nil? ? :get : :get_without_caching self.class.send(method, "/#{ref}.json", { :query => base_params.merge!(params) }) end |
#create(ref, attributes = {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/phono/client.rb', line 37 def create(ref, attributes = {}) self.class.post("/#{ref}.json", { :query => base_params.merge!({ ref.singularize.to_sym => attributes }) }) end |
#destroy(ref, id) ⇒ Object
53 54 55 56 57 |
# File 'lib/phono/client.rb', line 53 def destroy(ref, id) self.class.delete("/#{ref}/#{id}.json", { :query => base_params }) end |
#find(ref, id, params = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/phono/client.rb', line 28 def find(ref, id, params = {}) params.stringify_keys! method = params.delete('cache').nil? ? :get : :get_without_caching self.class.send(method, "/#{ref}/#{id}.json", { :query => base_params }) end |
#update(ref, id, params = {}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/phono/client.rb', line 45 def update(ref, id, params = {}) self.class.put("/#{ref}/#{id}.json", { :query => base_params.merge!({ ref.singularize.to_sym => attributes }) }) end |