Module: ShopifyClient::Resource::Read
- Defined in:
- lib/shopify-client/resource/read.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#all(client, params = {}) ⇒ Enumerator<Hash>
Find all results.
- #default_params ⇒ Hash abstract
-
#find_by_id(client, id, params = {}) ⇒ Hash
Find a single result.
Class Method Details
.included(base) ⇒ Object
20 21 22 23 24 |
# File 'lib/shopify-client/resource/read.rb', line 20 def self.included(base) base.extend(ClassMethods) base.include(Base) end |
Instance Method Details
#all(client, params = {}) ⇒ Enumerator<Hash>
Find all results.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shopify-client/resource/read.rb', line 54 def all(client, params = {}) raise ArgumentError, 'missing id field' unless has_id?(params) Enumerator.new do |yielder| response = client.get(resource_name, params) loop do response.data[resource_name].each { |result| yielder << result } response = response.next_page || break end end end |
#default_params ⇒ Hash
This method is abstract.
Use ShopifyClient::Resource::Read::ClassMethods#default_params to implement (optional)
29 30 31 |
# File 'lib/shopify-client/resource/read.rb', line 29 def default_params {} end |
#find_by_id(client, id, params = {}) ⇒ Hash
Find a single result.
40 41 42 43 44 |
# File 'lib/shopify-client/resource/read.rb', line 40 def find_by_id(client, id, params = {}) params = default_params.merge(params) client.get("#{resource_name}/#{id}", params).data[resource_name_singular] end |