Class: Quill::Client::Endpoint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#apiObject

Returns the value of attribute api.



24
25
26
# File 'lib/quill/client.rb', line 24

def api
  @api
end

#nameObject

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

Raises:



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

#listObject



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