Class: LucidShopify::Resource::Read Abstract
- Inherits:
-
Object
- Object
- LucidShopify::Resource::Read
- Includes:
- Enumerable, LucidShopify
- Defined in:
- lib/lucid_shopify/resource/read.rb
Overview
This class is abstract.
Instance Attribute Summary collapse
- #client ⇒ LucidShopify::Client readonly
Class Method Summary collapse
-
.default_params(params) ⇒ Object
Set the default query params.
-
.resource(resource_name) ⇒ Object
Set the remote API resource name for the subclass.
Instance Method Summary collapse
- #count(client, 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
-
#initialize(client: Client.new(send_request: SendThrottledRequest.new)) ⇒ Read
constructor
A new instance of Read.
- #resource ⇒ String abstract
Constructor Details
#initialize(client: Client.new(send_request: SendThrottledRequest.new)) ⇒ Read
Returns a new instance of Read.
22 23 24 |
# File 'lib/lucid_shopify/resource/read.rb', line 22 def initialize(client: Client.new(send_request: SendThrottledRequest.new)) @client = client end |
Instance Attribute Details
#client ⇒ LucidShopify::Client (readonly)
27 28 29 |
# File 'lib/lucid_shopify/resource/read.rb', line 27 def client @client end |
Class Method Details
.default_params(params) ⇒ Object
Set the default query params. Note that ‘fields’ may be passed as an array of strings.
59 60 61 |
# File 'lib/lucid_shopify/resource/read.rb', line 59 def self.default_params(params) define_method(:default_params) { params } end |
.resource(resource_name) ⇒ Object
Set the remote API resource name for the subclass.
37 38 39 |
# File 'lib/lucid_shopify/resource/read.rb', line 37 def self.resource(resource_name) define_method(:resource) { resource_name.to_s } end |
Instance Method Details
#count(client, params = {}) ⇒ Integer
147 148 149 150 151 |
# File 'lib/lucid_shopify/resource/read.rb', line 147 def count(client, params = {}) params = finalize_params(params) client.get("#{resource}/count", params)['count'] end |
#default_params ⇒ Hash
This method is abstract.
68 69 70 |
# File 'lib/lucid_shopify/resource/read.rb', line 68 def default_params {} end |
#default_shopify_params ⇒ Hash
Defaults set by Shopify when not specified.
77 78 79 80 81 |
# File 'lib/lucid_shopify/resource/read.rb', line 77 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.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/lucid_shopify/resource/read.rb', line 112 def each(credentials, params = {}) return to_enum(__callee__) unless block_given? assert_fields_id!(params = finalized_params(params)) since_id = 1 loop do results = client.get(credentials, resource, params.merge(since_id: since_id)) results.each do |result| yield result end break if results.empty? since_id = results.last['id'] end end |
#find(credentials, id, params = {}) ⇒ Hash
90 91 92 93 94 |
# File 'lib/lucid_shopify/resource/read.rb', line 90 def find(credentials, id, params = {}) params = finalized_params(params) client.get(credentials, "#{resource}/#{id}", params)[resource] end |
#resource ⇒ String
This method is abstract.
46 47 48 |
# File 'lib/lucid_shopify/resource/read.rb', line 46 def resource raise NotImplementedError end |