Module: LucidShopify::Resource::Read
- Includes:
- Enumerable
- Defined in:
- lib/lucid_shopify/resource/read.rb
Overview
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #count(credentials, params = {}) ⇒ Integer
- #default_params ⇒ Hash abstract
-
#default_shopify_params ⇒ Hash
Defaults set by Shopify when not specified.
-
#each(credentials, params = {}) {|Hash| ... } ⇒ Enumerator
Iterate over results.
- #find(credentials, id, params = {}) ⇒ Hash
Class Method Details
.included(base) ⇒ Object
37 38 39 40 |
# File 'lib/lucid_shopify/resource/read.rb', line 37 def self.included(base) base.extend(ClassMethods) base.include(Base) end |
Instance Method Details
#count(credentials, params = {}) ⇒ Integer
128 129 130 131 132 |
# File 'lib/lucid_shopify/resource/read.rb', line 128 def count(credentials, params = {}) params = finalize_params(params) client.get(credentials, "#{resource}/count", params)['count'] end |
#default_params ⇒ Hash
This method is abstract.
Use LucidShopify::Resource::Read::ClassMethods#default_params to implement (optional)
47 48 49 |
# File 'lib/lucid_shopify/resource/read.rb', line 47 def default_params {} end |
#default_shopify_params ⇒ Hash
Defaults set by Shopify when not specified.
56 57 58 59 60 |
# File 'lib/lucid_shopify/resource/read.rb', line 56 def default_shopify_params { limit: 50, } end |
#each(credentials, params = {}) {|Hash| ... } ⇒ Enumerator
Iterate over results. If set, the ‘fields’ option must include ‘id’. We would not need this if we used offset pagination, but offset pagination is unreliable.
Throttling is always enabled.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/lucid_shopify/resource/read.rb', line 91 def each(credentials, params = {}) return to_enum(__callee__, credentials, params) unless block_given? assert_fields_id!(params = finalize_params(params)) throttled_client = client.throttled since_id = 1 loop do results = throttled_client.get(credentials, resource, params.merge(since_id: since_id)).values.first results.each do |result| yield result end break if results.empty? since_id = results.last['id'] end end |
#find(credentials, id, params = {}) ⇒ Hash
69 70 71 72 73 |
# File 'lib/lucid_shopify/resource/read.rb', line 69 def find(credentials, id, params = {}) params = finalize_params(params) client.get(credentials, "#{resource}/#{id}", params).values.first end |