akeneo 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +76 -0
- data/LICENSE +24 -0
- data/README.md +19 -0
- data/Rakefile +10 -0
- data/akeneo.gemspec +38 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/akeneo/api.rb +118 -0
- data/lib/akeneo/attribute_service.rb +19 -0
- data/lib/akeneo/authorization_service.rb +79 -0
- data/lib/akeneo/category_service.rb +13 -0
- data/lib/akeneo/family_service.rb +19 -0
- data/lib/akeneo/image_service.rb +36 -0
- data/lib/akeneo/measure_family_service.rb +13 -0
- data/lib/akeneo/product_model_service.rb +33 -0
- data/lib/akeneo/product_service.rb +87 -0
- data/lib/akeneo/service_base.rb +50 -0
- data/lib/akeneo/services.rb +51 -0
- data/lib/akeneo.rb +7 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c8a4e07e19a36d3d570b8dc21b683910d558e2876755d8cb0c2e604155d8a70a
|
4
|
+
data.tar.gz: cfc04059a593500dacb17106847bcc9b2ef8b7c90967693ef193dfda63128c28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b1171a0cab489133295291cd3d8163de7651b8b9e9ba6fd0c5e34ddf66b54b566c85fdf536768759b88a81d4d6515ca09959bdc57096c7191805488c032181e
|
7
|
+
data.tar.gz: 2d5972a171f1a369d95c73770f472e31abd18be22630cc6aa00fc089b010cd3cd5aeb3339ebadc2c99fa066f3ebc7ad857e2077ad8d1fdf004bc84bec2ace242
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
akeneo
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at johannes.strampe@hanseventures.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
akeneo (1.0.0)
|
5
|
+
httparty
|
6
|
+
semantic_logger
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
ast (2.4.0)
|
14
|
+
concurrent-ruby (1.1.4)
|
15
|
+
crack (0.4.3)
|
16
|
+
safe_yaml (~> 1.0.0)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
hashdiff (0.3.8)
|
19
|
+
httparty (0.16.3)
|
20
|
+
mime-types (~> 3.0)
|
21
|
+
multi_xml (>= 0.5.2)
|
22
|
+
jaro_winkler (1.5.2)
|
23
|
+
mime-types (3.2.2)
|
24
|
+
mime-types-data (~> 3.2015)
|
25
|
+
mime-types-data (3.2018.0812)
|
26
|
+
multi_xml (0.6.0)
|
27
|
+
parallel (1.12.1)
|
28
|
+
parser (2.5.3.0)
|
29
|
+
ast (~> 2.4.0)
|
30
|
+
powerpack (0.1.2)
|
31
|
+
public_suffix (3.0.3)
|
32
|
+
rainbow (3.0.0)
|
33
|
+
rake (12.3.2)
|
34
|
+
rspec (3.8.0)
|
35
|
+
rspec-core (~> 3.8.0)
|
36
|
+
rspec-expectations (~> 3.8.0)
|
37
|
+
rspec-mocks (~> 3.8.0)
|
38
|
+
rspec-core (3.8.0)
|
39
|
+
rspec-support (~> 3.8.0)
|
40
|
+
rspec-expectations (3.8.2)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.8.0)
|
43
|
+
rspec-mocks (3.8.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.8.0)
|
46
|
+
rspec-support (3.8.0)
|
47
|
+
rubocop (0.62.0)
|
48
|
+
jaro_winkler (~> 1.5.1)
|
49
|
+
parallel (~> 1.10)
|
50
|
+
parser (>= 2.5, != 2.5.1.1)
|
51
|
+
powerpack (~> 0.1)
|
52
|
+
rainbow (>= 2.2.2, < 4.0)
|
53
|
+
ruby-progressbar (~> 1.7)
|
54
|
+
unicode-display_width (~> 1.4.0)
|
55
|
+
ruby-progressbar (1.10.0)
|
56
|
+
safe_yaml (1.0.4)
|
57
|
+
semantic_logger (4.3.1)
|
58
|
+
concurrent-ruby (~> 1.0)
|
59
|
+
unicode-display_width (1.4.1)
|
60
|
+
webmock (3.5.1)
|
61
|
+
addressable (>= 2.3.6)
|
62
|
+
crack (>= 0.3.2)
|
63
|
+
hashdiff
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
akeneo!
|
70
|
+
rake
|
71
|
+
rspec
|
72
|
+
rubocop
|
73
|
+
webmock
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
1.17.2
|
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org>
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# akeneo
|
2
|
+
API client for accessing Akeneo.
|
3
|
+
|
4
|
+
Usage:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
require 'akeneo'
|
8
|
+
|
9
|
+
client = Akeneo::API.new(
|
10
|
+
url: 'https://my.akeneo.instance.com',
|
11
|
+
client_id: '1337',
|
12
|
+
password: 'tb9iiXWKskG2AFsKDaexyNf',
|
13
|
+
secret: 'F3vpu3p0ezUmwW6nit5eVqt',
|
14
|
+
username: 'API Username'
|
15
|
+
)
|
16
|
+
|
17
|
+
client.product(511707)
|
18
|
+
# => {"identifier"=>"511707", "family"=>"simple_product", "parent"=>nil, "groups"=>[]...
|
19
|
+
```
|
data/Rakefile
ADDED
data/akeneo.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'akeneo'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'akeneo'
|
9
|
+
spec.version = Akeneo::VERSION
|
10
|
+
spec.authors = ['AWN Dev Team']
|
11
|
+
spec.email = ['edv@awn.de']
|
12
|
+
|
13
|
+
spec.summary = 'API client for accessing Akeneo'
|
14
|
+
spec.description = 'API client for accessing Akeneo'
|
15
|
+
spec.homepage = 'https://github.com/awniemeyer/akeneo'
|
16
|
+
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
else
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
'public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_development_dependency 'rake'
|
33
|
+
spec.add_development_dependency 'rspec'
|
34
|
+
spec.add_development_dependency 'rubocop'
|
35
|
+
spec.add_development_dependency 'webmock'
|
36
|
+
spec.add_dependency 'httparty'
|
37
|
+
spec.add_dependency 'semantic_logger'
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'akeneo'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require 'irb'
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/akeneo/api.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './services'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class API
|
7
|
+
include Akeneo::Services
|
8
|
+
|
9
|
+
MASTER_CATEGORY_CODE = 'master'
|
10
|
+
|
11
|
+
attr_accessor :access_token, :url, :last_refresh
|
12
|
+
|
13
|
+
def initialize(url:, client_id:, secret:, username:, password:)
|
14
|
+
@url = url
|
15
|
+
authorization_service.authorize!(
|
16
|
+
client_id: client_id,
|
17
|
+
secret: secret,
|
18
|
+
username: username,
|
19
|
+
password: password
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fresh_access_token
|
24
|
+
authorization_service.fresh_access_token
|
25
|
+
end
|
26
|
+
|
27
|
+
def product(sku)
|
28
|
+
product_service.find(sku)
|
29
|
+
end
|
30
|
+
|
31
|
+
def products(with_family: nil)
|
32
|
+
product_service.all(with_family: with_family)
|
33
|
+
end
|
34
|
+
|
35
|
+
def parents(with_family: nil)
|
36
|
+
product_model_service.all(with_family: with_family)
|
37
|
+
end
|
38
|
+
|
39
|
+
def product_parent(code)
|
40
|
+
product_model_service.find(code)
|
41
|
+
end
|
42
|
+
|
43
|
+
def image(code)
|
44
|
+
image_service.find(code)
|
45
|
+
end
|
46
|
+
|
47
|
+
def download_image(code)
|
48
|
+
image_service.download(code)
|
49
|
+
end
|
50
|
+
|
51
|
+
def product_parent_or_grand_parent(code)
|
52
|
+
product_parent = product_model_service.find(code)
|
53
|
+
|
54
|
+
return if product_parent.nil?
|
55
|
+
return product_parent unless product_parent['parent']
|
56
|
+
|
57
|
+
product_model_service.find(product_parent['parent'])
|
58
|
+
end
|
59
|
+
|
60
|
+
def family(family_code)
|
61
|
+
family_service.find(family_code)
|
62
|
+
end
|
63
|
+
|
64
|
+
def family_variant(family_code, family_variant_code)
|
65
|
+
family_service.variant(family_code, family_variant_code)
|
66
|
+
end
|
67
|
+
|
68
|
+
def option_values_of(family_code, family_variant_code)
|
69
|
+
family_variant = family_service.variant(family_code, family_variant_code)
|
70
|
+
return [] unless family_variant
|
71
|
+
|
72
|
+
[
|
73
|
+
find_attribute_code_for_level(family_variant, 1),
|
74
|
+
find_attribute_code_for_level(family_variant, 2)
|
75
|
+
].compact
|
76
|
+
end
|
77
|
+
|
78
|
+
def brothers_and_sisters(id)
|
79
|
+
product_service.brothers_and_sisters(id)
|
80
|
+
end
|
81
|
+
|
82
|
+
def attribute(code)
|
83
|
+
attribute_service.find(code)
|
84
|
+
end
|
85
|
+
|
86
|
+
def attribute_option(code, option_code)
|
87
|
+
attribute_service.option(code, option_code)
|
88
|
+
end
|
89
|
+
|
90
|
+
def measure_family(code)
|
91
|
+
measure_family_service.find(code)
|
92
|
+
end
|
93
|
+
|
94
|
+
def category(code)
|
95
|
+
category_service.find(code)
|
96
|
+
end
|
97
|
+
|
98
|
+
def categories(code, categories: [])
|
99
|
+
category = category_service.find(code)
|
100
|
+
|
101
|
+
return [] if category.nil?
|
102
|
+
|
103
|
+
categories << category
|
104
|
+
|
105
|
+
return categories if category['parent'].nil? || category['parent'] == MASTER_CATEGORY_CODE
|
106
|
+
|
107
|
+
categories(category['parent'], categories: categories)
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def find_attribute_code_for_level(family_variant, level)
|
113
|
+
family_variant['variant_attribute_sets'].find do |attribute_set|
|
114
|
+
attribute_set['level'] == level
|
115
|
+
end.to_h['axes'].to_a.first
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './service_base.rb'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class AttributeService < ServiceBase
|
7
|
+
def find(code)
|
8
|
+
response = get_request("attributes/#{code}")
|
9
|
+
|
10
|
+
response.parsed_response if response.success?
|
11
|
+
end
|
12
|
+
|
13
|
+
def option(code, option_code)
|
14
|
+
response = get_request("attributes/#{code}/options/#{option_code}")
|
15
|
+
|
16
|
+
response.parsed_response if response.success?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './service_base.rb'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class AuthorizationService < ServiceBase
|
7
|
+
REFRESH_RATE_IN_SECONDS = 2000
|
8
|
+
|
9
|
+
attr_accessor :access_token, :refresh_token, :last_refresh
|
10
|
+
|
11
|
+
def initialize(url:)
|
12
|
+
@url = url
|
13
|
+
end
|
14
|
+
|
15
|
+
def authorize!(client_id:, secret:, username:, password:)
|
16
|
+
@client_id = client_id
|
17
|
+
@secret = secret
|
18
|
+
options = {
|
19
|
+
body: authorization_body(username, password),
|
20
|
+
headers: json_headers.merge(basic_authorization_header)
|
21
|
+
}
|
22
|
+
response = HTTParty.post("#{@url}/api/oauth/v1/token", options)
|
23
|
+
store_tokens!(response)
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
def fresh_access_token
|
28
|
+
refresh!
|
29
|
+
@access_token
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def refresh!
|
35
|
+
return unless refresh_necessary?
|
36
|
+
|
37
|
+
options = {
|
38
|
+
body: refresh_body(@refresh_token),
|
39
|
+
headers: json_headers.merge(basic_authorization_header)
|
40
|
+
}
|
41
|
+
response = HTTParty.post("#{@url}/api/oauth/v1/token", options)
|
42
|
+
store_tokens!(response)
|
43
|
+
@last_refresh = Time.now
|
44
|
+
SemanticLogger['AuthorizationService.refresh!'].warn(payload: 'akeneo token refresh')
|
45
|
+
end
|
46
|
+
|
47
|
+
def refresh_necessary?
|
48
|
+
(Time.now.to_i - @last_refresh.to_i) > REFRESH_RATE_IN_SECONDS
|
49
|
+
end
|
50
|
+
|
51
|
+
def store_tokens!(response)
|
52
|
+
raise response.to_hash['message'] unless response.ok?
|
53
|
+
|
54
|
+
@access_token = response['access_token']
|
55
|
+
@refresh_token = response['refresh_token']
|
56
|
+
end
|
57
|
+
|
58
|
+
def basic_authorization_header
|
59
|
+
auth_hash = Base64.strict_encode64("#{@client_id}:#{@secret}")
|
60
|
+
|
61
|
+
{ 'Authorization' => "Basic #{auth_hash}" }
|
62
|
+
end
|
63
|
+
|
64
|
+
def authorization_body(username, password)
|
65
|
+
{
|
66
|
+
username: username,
|
67
|
+
password: password,
|
68
|
+
grant_type: 'password'
|
69
|
+
}.to_json
|
70
|
+
end
|
71
|
+
|
72
|
+
def refresh_body(refresh_token)
|
73
|
+
{
|
74
|
+
refresh_token: refresh_token,
|
75
|
+
grant_type: 'refresh_token'
|
76
|
+
}.to_json
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './service_base.rb'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class CategoryService < ServiceBase
|
7
|
+
def find(code)
|
8
|
+
response = get_request("categories/#{code}")
|
9
|
+
|
10
|
+
response.parsed_response if response.success?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './service_base.rb'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class FamilyService < ServiceBase
|
7
|
+
def find(code)
|
8
|
+
response = get_request("families/#{code}")
|
9
|
+
|
10
|
+
response.parsed_response if response.success?
|
11
|
+
end
|
12
|
+
|
13
|
+
def variant(code, variant_code)
|
14
|
+
response = get_request("families/#{code}/variants/#{variant_code}")
|
15
|
+
|
16
|
+
response.parsed_response if response.success?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
require_relative './service_base.rb'
|
7
|
+
|
8
|
+
module Akeneo
|
9
|
+
class ImageService < ServiceBase
|
10
|
+
def find(code)
|
11
|
+
response = get_request("assets/#{code}")
|
12
|
+
|
13
|
+
response.parsed_response if response.success?
|
14
|
+
end
|
15
|
+
|
16
|
+
def download(code)
|
17
|
+
download_request(code)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def download_request(code)
|
23
|
+
image_stream = StringIO.new
|
24
|
+
|
25
|
+
url = "#{@url}/api/rest/v1/assets/#{code}/reference-files/no-locale/download"
|
26
|
+
response = HTTParty.get(url, headers: default_request_headers) do |fragment|
|
27
|
+
image_stream.write(fragment)
|
28
|
+
end
|
29
|
+
image_stream.rewind
|
30
|
+
|
31
|
+
Base64.strict_encode64(image_stream.read) if response.success?
|
32
|
+
rescue StandardError => e
|
33
|
+
SemanticLogger['AkeneoService#download_image_request'].info("Error downloading file: #{e}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './service_base.rb'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class MeasureFamilyService < ServiceBase
|
7
|
+
def find(code)
|
8
|
+
response = get_request("measure-families/#{code}")
|
9
|
+
|
10
|
+
response.parsed_response if response.success?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './service_base.rb'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class ProductModelService < ServiceBase
|
7
|
+
def find(id)
|
8
|
+
response = get_request("product-models/#{id}")
|
9
|
+
|
10
|
+
response.parsed_response if response.success?
|
11
|
+
end
|
12
|
+
|
13
|
+
def all(with_family: nil)
|
14
|
+
Enumerator.new do |product_models|
|
15
|
+
url = "#{@url}/api/rest/v1/product-models?#{pagination_param}&#{limit_param}"
|
16
|
+
url += search_with_family_param(with_family) if with_family
|
17
|
+
|
18
|
+
loop do
|
19
|
+
response = HTTParty.get(url, headers: default_request_headers)
|
20
|
+
extract_collection_items(response).each { |product_model| product_models << product_model }
|
21
|
+
url = extract_fetch_url(response)
|
22
|
+
break unless url
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def search_with_family_param(family)
|
30
|
+
"&search={\"family\":[{\"operator\":\"IN\",\"value\":[\"#{family}\"]}]}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './service_base.rb'
|
4
|
+
|
5
|
+
module Akeneo
|
6
|
+
class ProductService < ServiceBase
|
7
|
+
def initialize(url:, access_token:, product_model_service:, family_service:)
|
8
|
+
@url = url
|
9
|
+
@access_token = access_token
|
10
|
+
@product_model_service = product_model_service
|
11
|
+
@family_service = family_service
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(id)
|
15
|
+
response = get_request("products/#{id}")
|
16
|
+
|
17
|
+
response.parsed_response if response.success?
|
18
|
+
end
|
19
|
+
|
20
|
+
def brothers_and_sisters(id)
|
21
|
+
akeneo_product = find(id)
|
22
|
+
akeneo_parent = load_akeneo_parent(akeneo_product['parent'])
|
23
|
+
akeneo_grand_parent = load_akeneo_parent(akeneo_parent['parent']) unless akeneo_parent.nil?
|
24
|
+
|
25
|
+
parents = load_parents(akeneo_product['family'], akeneo_parent, akeneo_grand_parent)
|
26
|
+
|
27
|
+
load_products(akeneo_product, akeneo_product['family'], parents)
|
28
|
+
end
|
29
|
+
|
30
|
+
def all(with_family: nil)
|
31
|
+
Enumerator.new do |products|
|
32
|
+
url = "#{@url}/api/rest/v1/products?#{pagination_param}&#{limit_param}"
|
33
|
+
url += search_with_family_param(with_family) if with_family
|
34
|
+
|
35
|
+
loop do
|
36
|
+
response = HTTParty.get(url, headers: default_request_headers)
|
37
|
+
extract_collection_items(response).each { |product| products << product }
|
38
|
+
url = extract_fetch_url(response)
|
39
|
+
break unless url
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def search_with_family_param(family)
|
47
|
+
"&search={\"family\":[{\"operator\":\"IN\",\"value\":[\"#{family}\"]}]}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_akeneo_parent(code)
|
51
|
+
return unless code
|
52
|
+
|
53
|
+
@product_model_service.find(code)
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_parents(family, akeneo_parent, akeneo_grand_parent)
|
57
|
+
return [] if akeneo_parent.nil? || akeneo_grand_parent.nil?
|
58
|
+
|
59
|
+
@product_model_service.all(with_family: family).select do |parent|
|
60
|
+
parent['parent'] == akeneo_grand_parent['code']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def load_products(akeneo_product, family, parents)
|
65
|
+
return [akeneo_product] if parents.empty?
|
66
|
+
|
67
|
+
products = all(with_family: family)
|
68
|
+
parent_codes = parents.map { |parent| parent['code'] }
|
69
|
+
|
70
|
+
products.select do |product|
|
71
|
+
parent_codes.include?(product['parent'])
|
72
|
+
end.flatten
|
73
|
+
end
|
74
|
+
|
75
|
+
def find_product_image_level(family, family_variant)
|
76
|
+
family_variant = @family_service.variant(family, family_variant)
|
77
|
+
|
78
|
+
product_image_attribute_set = family_variant['variant_attribute_sets'].find do |attribute_set|
|
79
|
+
attribute_set['attributes'].include?('product_images')
|
80
|
+
end
|
81
|
+
|
82
|
+
return 0 unless product_image_attribute_set
|
83
|
+
|
84
|
+
product_image_attribute_set.fetch('level', 0)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'semantic_logger'
|
5
|
+
|
6
|
+
module Akeneo
|
7
|
+
class ServiceBase
|
8
|
+
DEFAULT_PAGINATION_TYPE = :search_after
|
9
|
+
DEFAULT_PAGINATION_LIMIT = 100
|
10
|
+
|
11
|
+
def initialize(url:, access_token:)
|
12
|
+
@url = url
|
13
|
+
@access_token = access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def json_headers
|
19
|
+
{ 'Content-Type' => 'application/json' }
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_request_headers
|
23
|
+
{ 'Authorization' => "Bearer #{@access_token}" }.merge(json_headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_request(path)
|
27
|
+
HTTParty.get("#{@url}/api/rest/v1/#{path}", headers: default_request_headers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def pagination_param
|
31
|
+
"pagination_type=#{DEFAULT_PAGINATION_TYPE}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def limit_param
|
35
|
+
"limit=#{DEFAULT_PAGINATION_LIMIT}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def extract_collection_items(response)
|
39
|
+
return [] unless response.success?
|
40
|
+
|
41
|
+
response.parsed_response['_embedded']['items']
|
42
|
+
end
|
43
|
+
|
44
|
+
def extract_fetch_url(response)
|
45
|
+
return unless response.success?
|
46
|
+
|
47
|
+
response.parsed_response.dig('_links', 'next', 'href')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './attribute_service'
|
4
|
+
require_relative './authorization_service'
|
5
|
+
require_relative './category_service'
|
6
|
+
require_relative './family_service'
|
7
|
+
require_relative './image_service'
|
8
|
+
require_relative './measure_family_service'
|
9
|
+
require_relative './product_model_service'
|
10
|
+
require_relative './product_service'
|
11
|
+
|
12
|
+
module Akeneo
|
13
|
+
module Services
|
14
|
+
def authorization_service
|
15
|
+
@authorization_service ||= AuthorizationService.new(url: url)
|
16
|
+
end
|
17
|
+
|
18
|
+
def attribute_service
|
19
|
+
AttributeService.new(url: url, access_token: fresh_access_token)
|
20
|
+
end
|
21
|
+
|
22
|
+
def category_service
|
23
|
+
CategoryService.new(url: url, access_token: fresh_access_token)
|
24
|
+
end
|
25
|
+
|
26
|
+
def family_service
|
27
|
+
FamilyService.new(url: url, access_token: fresh_access_token)
|
28
|
+
end
|
29
|
+
|
30
|
+
def image_service
|
31
|
+
ImageService.new(url: url, access_token: fresh_access_token)
|
32
|
+
end
|
33
|
+
|
34
|
+
def measure_family_service
|
35
|
+
MeasureFamilyService.new(url: url, access_token: fresh_access_token)
|
36
|
+
end
|
37
|
+
|
38
|
+
def product_service
|
39
|
+
ProductService.new(
|
40
|
+
url: url,
|
41
|
+
access_token: fresh_access_token,
|
42
|
+
product_model_service: product_model_service,
|
43
|
+
family_service: family_service
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def product_model_service
|
48
|
+
ProductModelService.new(url: url, access_token: fresh_access_token)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/akeneo.rb
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: akeneo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AWN Dev Team
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: semantic_logger
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: API client for accessing Akeneo
|
98
|
+
email:
|
99
|
+
- edv@awn.de
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".ruby-gemset"
|
108
|
+
- ".ruby-version"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- akeneo.gemspec
|
116
|
+
- bin/console
|
117
|
+
- bin/setup
|
118
|
+
- lib/akeneo.rb
|
119
|
+
- lib/akeneo/api.rb
|
120
|
+
- lib/akeneo/attribute_service.rb
|
121
|
+
- lib/akeneo/authorization_service.rb
|
122
|
+
- lib/akeneo/category_service.rb
|
123
|
+
- lib/akeneo/family_service.rb
|
124
|
+
- lib/akeneo/image_service.rb
|
125
|
+
- lib/akeneo/measure_family_service.rb
|
126
|
+
- lib/akeneo/product_model_service.rb
|
127
|
+
- lib/akeneo/product_service.rb
|
128
|
+
- lib/akeneo/service_base.rb
|
129
|
+
- lib/akeneo/services.rb
|
130
|
+
homepage: https://github.com/awniemeyer/akeneo
|
131
|
+
licenses: []
|
132
|
+
metadata:
|
133
|
+
homepage_uri: https://github.com/awniemeyer/akeneo
|
134
|
+
source_code_uri: https://github.com/awniemeyer/akeneo
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.7.6
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: API client for accessing Akeneo
|
155
|
+
test_files: []
|