Module: Jeckle::RESTActions::Collection

Defined in:
lib/jeckle/rest_actions.rb

Instance Method Summary collapse

Instance Method Details

#find(id) ⇒ Object



8
9
10
11
12
13
# File 'lib/jeckle/rest_actions.rb', line 8

def find(id)
  endpoint = "#{resource_name}/#{id}"
  attributes = run_request(endpoint).response.body

  new attributes
end

#search(params = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/jeckle/rest_actions.rb', line 15

def search(params = {})
  custom_resource_name = params.delete(:resource_name) if params.kind_of?(Hash)

  response   = run_request(custom_resource_name || resource_name, params: params).response.body || []
  collection = response.kind_of?(Array) ? response : response[resource_name]

  Array(collection).collect { |attrs| new attrs }
end