Class: EcwidApi::Api::ProductCombinations

Inherits:
Base
  • Object
show all
Includes:
EcwidApi::Api, Enumerable
Defined in:
lib/ecwid_api/api/product_combinations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, client) ⇒ ProductCombinations

Returns a new instance of ProductCombinations.



9
10
11
12
# File 'lib/ecwid_api/api/product_combinations.rb', line 9

def initialize(product, client)
  @product = product
  super(client)
end

Instance Attribute Details

#productObject (readonly)

Returns the value of attribute product.



7
8
9
# File 'lib/ecwid_api/api/product_combinations.rb', line 7

def product
  @product
end

Instance Method Details

#allObject



14
15
16
17
18
19
20
21
22
# File 'lib/ecwid_api/api/product_combinations.rb', line 14

def all
  response = client.get("products/#{product.id}/combinations")

  if response.success?
    response.body.map do |data|
      ProductCombination.new(data, client: client, product: product)
    end
  end
end

#create(params) ⇒ Object



38
39
40
41
# File 'lib/ecwid_api/api/product_combinations.rb', line 38

def create(params)
  response = client.post("products/#{product.id}/combinations", params)
  find(response.body["id"])
end

#delete_all!Object



43
44
45
# File 'lib/ecwid_api/api/product_combinations.rb', line 43

def delete_all!
  client.delete("products/#{product.id}/combinations")
end

#each(&block) ⇒ Object



24
25
26
27
28
# File 'lib/ecwid_api/api/product_combinations.rb', line 24

def each(&block)
  all = self.all || []

  all.each(&block)
end

#find(id) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/ecwid_api/api/product_combinations.rb', line 30

def find(id)
  response = client.get("products/#{product.id}/combinations/#{id}")

  if response.success?
    ProductCombination.new(response.body, product: product, client: client)
  end
end