Class: SBF::Client::KidEndpoint

Inherits:
EntityEndpoint show all
Defined in:
lib/stbaldricks/endpoints/kid.rb

Instance Attribute Summary

Attributes inherited from EntityEndpoint

#orig_target_class

Instance Method Summary collapse

Methods inherited from EntityEndpoint

#aggregate, #create, #delete, #find, #find_first, #get, #initialize, #save, #update

Constructor Details

This class inherits a constructor from SBF::Client::EntityEndpoint

Instance Method Details

#find_random(filter = [], limit = 20, with = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stbaldricks/endpoints/kid.rb', line 6

def find_random(filter = [], limit = 20, with = {})
  filter = filter.to_json unless filter.is_a? String
  with = normalize_with(with)

  response = SBF::Client::Api::Request.get_request("#{base_uri}/find_random", filter: filter, limit: limit, with: with)
  parsed_response_body = JSON.parse(response.body).symbolize!

  if ok?(response)
    parsed_response_body[:results].map! { |entity_data| target_class.new(entity_data) }
    data = parsed_response_body
  else
    error = SBF::Client::ErrorEntity.new(parsed_response_body)
  end

  SBF::Client::Api::Response.new(http_code: response.code, data: data, error: error)
end