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

Class Method Details

.included(base) ⇒ Object

Parameters:

  • base (Class)


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.

Parameters:

  • client (Client)
  • params (Hash) (defaults to: {})

Returns:

  • (Enumerator<Hash>)

Raises:

  • (ArgumentError)

    if ‘fields’ does not include ‘id’



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_paramsHash

This method is abstract.

Returns:

  • (Hash)


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.

Parameters:

  • client (Client)
  • id (Integer)
  • params (Hash) (defaults to: {})

Returns:

  • (Hash)


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