Class: Quill::Client::Endpoint
- Inherits:
-
Object
- Object
- Quill::Client::Endpoint
- Defined in:
- lib/quill/client.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #check_keys(params) ⇒ Object
- #create(params) ⇒ Object
- #find(id, params = {}) ⇒ Object
-
#initialize(api, name, definition) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #list ⇒ Object
- #update(id, params) ⇒ Object
Constructor Details
#initialize(api, name, definition) ⇒ Endpoint
Returns a new instance of Endpoint.
26 27 28 29 30 31 |
# File 'lib/quill/client.rb', line 26 def initialize api, name, definition @api = api @name = name @attributes = definition['attributes'].keys @readonly_attributes = definition['readonly_attributes'].try(:keys) || [] end |
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
24 25 26 |
# File 'lib/quill/client.rb', line 24 def api @api end |
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/quill/client.rb', line 24 def name @name end |
Instance Method Details
#check_keys(params) ⇒ Object
54 55 56 57 58 |
# File 'lib/quill/client.rb', line 54 def check_keys params # raise @readonly_attributes.inspect invalid_keys = params.stringify_keys.keys - @attributes - @readonly_attributes raise InvalidKeys, "Endpoint ##{name} does not support key(s) #{invalid_keys.join(', ')}" unless invalid_keys.empty? end |
#create(params) ⇒ Object
39 40 41 42 43 |
# File 'lib/quill/client.rb', line 39 def create params check_keys(params) response = api.post(name, params) Hashie::Mash.new(response.body['object']) end |
#find(id, params = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/quill/client.rb', line 33 def find id, params = {} check_keys(params) response = api.get([name,id].join('/'), params) Hashie::Mash.new(response.body['object']) end |
#list ⇒ Object
51 52 |
# File 'lib/quill/client.rb', line 51 def list end |
#update(id, params) ⇒ Object
45 46 47 48 49 |
# File 'lib/quill/client.rb', line 45 def update id, params check_keys(params) response = api.put([name,id].join('/'), params) Hashie::Mash.new(response.body['object']) end |