Module: Protip::Resource::SearchMethods
- Defined in:
- lib/protip/resource/search_methods.rb
Overview
Internal handlers for index/show actions. Never use these directly; instead, use ‘.all` and `.find` on the resource you’re working with, since those methods will adjust their signatures to correctly parse a set of query parameters if supported.
Class Method Summary collapse
-
.index(resource_class, query) ⇒ Array
Fetch a list from the server at the collection’s base endpoint.
-
.show(resource_class, id, query) ⇒ Protip::Resource
Fetch a single resource from the server.
Class Method Details
.index(resource_class, query) ⇒ Array
Fetch a list from the server at the collection’s base endpoint. Expects the server response to be an array containing encoded messages that can be used to instantiate our resource.
14 15 16 17 18 19 20 21 22 |
# File 'lib/protip/resource/search_methods.rb', line 14 def self.index(resource_class, query) response = resource_class.client.request path: resource_class.base_path, method: Net::HTTP::Get, message: query, response_type: Protip::Messages::Array response..map do || resource_class.new resource_class..decode() end end |
.show(resource_class, id, query) ⇒ Protip::Resource
Fetch a single resource from the server.
31 32 33 34 35 36 37 |
# File 'lib/protip/resource/search_methods.rb', line 31 def self.show(resource_class, id, query) response = resource_class.client.request path: "#{resource_class.base_path}/#{id}", method: Net::HTTP::Get, message: query, response_type: resource_class. resource_class.new response end |