Class: Akeneo::ProductService
Constant Summary
Constants inherited
from ServiceBase
ServiceBase::API_VERSION, ServiceBase::DEFAULT_PAGINATION_LIMIT, ServiceBase::DEFAULT_PAGINATION_TYPE
Constants included
from Cache
Cache::DEFAULT_EXPIRES_IN
Instance Method Summary
collapse
Methods included from Cache
disabled=, #get_request, prepended
Constructor Details
#initialize(url:, access_token:, product_model_service:, family_service:) ⇒ ProductService
Returns a new instance of ProductService.
7
8
9
10
11
12
|
# File 'lib/akeneo/product_service.rb', line 7
def initialize(url:, access_token:, product_model_service:, family_service:)
@url = url
@access_token = access_token
@product_model_service = product_model_service
@family_service = family_service
end
|
Instance Method Details
#all(with_family: nil, with_completeness: nil, updated_after: nil) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/akeneo/product_service.rb', line 30
def all(with_family: nil, with_completeness: nil, updated_after: nil)
Enumerator.new do |products|
path = build_path(with_family, with_completeness, updated_after)
loop do
response = get_request(path)
(response).each { |product| products << product }
path = (response)
break unless path
end
end
end
|
#brothers_and_sisters(id) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/akeneo/product_service.rb', line 20
def brothers_and_sisters(id)
akeneo_product = find(id)
akeneo_parent = load_akeneo_parent(akeneo_product['parent'])
akeneo_grand_parent = load_akeneo_parent(akeneo_parent['parent']) unless akeneo_parent.nil?
parents = load_parents(akeneo_product['family'], akeneo_parent, akeneo_grand_parent)
load_products(akeneo_product, akeneo_product['family'], parents)
end
|
#create(options) ⇒ Object
47
48
49
|
# File 'lib/akeneo/product_service.rb', line 47
def create(options)
post_request('/products', body: options.to_json)
end
|
#create_or_update(code, options) ⇒ Object
43
44
45
|
# File 'lib/akeneo/product_service.rb', line 43
def create_or_update(code, options)
patch_request("/products/#{code}", body: options.to_json)
end
|
#create_several(product_objects) ⇒ Object
51
52
53
|
# File 'lib/akeneo/product_service.rb', line 51
def create_several(product_objects)
patch_for_collection_request('/products', body: product_objects.to_json)
end
|
#find(id) ⇒ Object
14
15
16
17
18
|
# File 'lib/akeneo/product_service.rb', line 14
def find(id)
response = get_request("/products/#{id}")
response.parsed_response if response.success?
end
|