akeneo 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a82b6a9e634b7a0546533a4f38fe55a8d7d535332a1426b675c6a963d1dbd165
4
- data.tar.gz: 86fc515d5ac913e36213f8e3e34b28aebe59face66e52655bc28410ca619b3f7
3
+ metadata.gz: 2587eb09691ebb7e543ef907edfc47c4296b62fe3c2c84654bb1316723f116c2
4
+ data.tar.gz: 04df15b3d09324a723e656a55b4e6843ec5fcf45a0a0ce9eb3fc3a53bfc604cb
5
5
  SHA512:
6
- metadata.gz: 46fea6aa7926d012898b73b5e5bd00df2de2d763eeb8e99f8fd7155e47dc389d93182dff0ec9226ff2071184f668f29b14f31406e8efb21274631a4ff6f107d0
7
- data.tar.gz: 86f85f185ca25353bd532c938a41bf5ae73af585fa77a73f5f01832fe6fed5d24f8f5d84cea257f8ccecf4bbbecfadc9948eeea748190b745dfc6c9d5108ba17
6
+ metadata.gz: fd5db20c91e190e41fbb52136e93dbf5810e990284b525269d0075d3c38fe36f3508083ac9cdd3b55747a5e4c76b7f78e0eae3a69ecd8c59a2198b1e34c253e0
7
+ data.tar.gz: deb5f602b4c0c3366d3e27dae7cdb0ce2505f56239e92216183fbf3a108ad883e8db100445e9ccfcdfdfa43ac07e38818929cb74055d875e189a85ed4109fa23
@@ -0,0 +1,25 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.5.1
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: Which bundler?
10
+ command: bundle -v
11
+ - restore_cache:
12
+ keys:
13
+ - cache-{{ checksum "Gemfile.lock" }}
14
+ - cache-
15
+ - run:
16
+ name: Bundle Install
17
+ command: bundle check || bundle install
18
+ - save_cache:
19
+ key: cache-{{ checksum "Gemfile.lock" }}
20
+ paths:
21
+ - vendor/bundle
22
+ - run:
23
+ name: Run cop and rspec
24
+ command: |
25
+ bundle exec rake
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- akeneo (1.0.0)
4
+ akeneo (1.1.0)
5
5
  httparty
6
6
  redis
7
7
  semantic_logger
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![CircleCI](https://circleci.com/gh/awniemeyer/akeneo.svg?style=svg&circle-token=1d727274a65e61f2bd5f2208f5c33bf532ebaac5)](https://circleci.com/gh/awniemeyer/akeneo)
2
+
1
3
  # akeneo
2
4
 
3
5
  API client for accessing Akeneo.
data/akeneo.gemspec CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'akeneo'
6
5
 
7
6
  Gem::Specification.new do |spec|
8
7
  spec.name = 'akeneo'
9
- spec.version = Akeneo::VERSION
8
+ spec.version = '1.2.0'
10
9
  spec.authors = ['AWN Dev Team']
11
10
  spec.email = ['edv@awn.de']
12
11
 
data/lib/akeneo.rb CHANGED
@@ -3,5 +3,4 @@
3
3
  require 'akeneo/api'
4
4
 
5
5
  module Akeneo
6
- VERSION = '1.1.0'
7
6
  end
data/lib/akeneo/api.rb CHANGED
@@ -32,6 +32,10 @@ module Akeneo
32
32
  product_service.all(with_family: with_family)
33
33
  end
34
34
 
35
+ def published_products(updated_after: nil)
36
+ published_product_service.published_products(updated_after: updated_after)
37
+ end
38
+
35
39
  def parents(with_family: nil)
36
40
  product_model_service.all(with_family: with_family)
37
41
  end
@@ -5,13 +5,13 @@ require_relative './service_base.rb'
5
5
  module Akeneo
6
6
  class AttributeService < ServiceBase
7
7
  def find(code)
8
- response = get_request("attributes/#{code}")
8
+ response = get_request("/attributes/#{code}")
9
9
 
10
10
  response.parsed_response if response.success?
11
11
  end
12
12
 
13
13
  def option(code, option_code)
14
- response = get_request("attributes/#{code}/options/#{option_code}")
14
+ response = get_request("/attributes/#{code}/options/#{option_code}")
15
15
 
16
16
  response.parsed_response if response.success?
17
17
  end
@@ -5,7 +5,7 @@ require_relative './service_base.rb'
5
5
  module Akeneo
6
6
  class CategoryService < ServiceBase
7
7
  def find(code)
8
- response = get_request("categories/#{code}")
8
+ response = get_request("/categories/#{code}")
9
9
 
10
10
  response.parsed_response if response.success?
11
11
  end
@@ -5,13 +5,13 @@ require_relative './service_base.rb'
5
5
  module Akeneo
6
6
  class FamilyService < ServiceBase
7
7
  def find(code)
8
- response = get_request("families/#{code}")
8
+ response = get_request("/families/#{code}")
9
9
 
10
10
  response.parsed_response if response.success?
11
11
  end
12
12
 
13
13
  def variant(code, variant_code)
14
- response = get_request("families/#{code}/variants/#{variant_code}")
14
+ response = get_request("/families/#{code}/variants/#{variant_code}")
15
15
 
16
16
  response.parsed_response if response.success?
17
17
  end
@@ -8,7 +8,7 @@ require_relative './service_base.rb'
8
8
  module Akeneo
9
9
  class ImageService < ServiceBase
10
10
  def find(code)
11
- response = get_request("assets/#{code}")
11
+ response = get_request("/assets/#{code}")
12
12
 
13
13
  response.parsed_response if response.success?
14
14
  end
@@ -20,15 +20,9 @@ module Akeneo
20
20
  private
21
21
 
22
22
  def download_request(code)
23
- image_stream = StringIO.new
23
+ response = get_request("/assets/#{code}/reference-files/no-locale/download")
24
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?
25
+ Base64.strict_encode64(response.body) if response.success?
32
26
  rescue StandardError => e
33
27
  SemanticLogger['AkeneoService#download_image_request'].info("Error downloading file: #{e}")
34
28
  end
@@ -5,7 +5,7 @@ require_relative './service_base.rb'
5
5
  module Akeneo
6
6
  class MeasureFamilyService < ServiceBase
7
7
  def find(code)
8
- response = get_request("measure-families/#{code}")
8
+ response = get_request("/measure-families/#{code}")
9
9
 
10
10
  response.parsed_response if response.success?
11
11
  end
@@ -5,21 +5,21 @@ require_relative './service_base.rb'
5
5
  module Akeneo
6
6
  class ProductModelService < ServiceBase
7
7
  def find(id)
8
- response = get_request("product-models/#{id}")
8
+ response = get_request("/product-models/#{id}")
9
9
 
10
10
  response.parsed_response if response.success?
11
11
  end
12
12
 
13
13
  def all(with_family: nil)
14
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
15
+ path = "/product-models?#{pagination_param}&#{limit_param}"
16
+ path += search_with_family_param(with_family) if with_family
17
17
 
18
18
  loop do
19
- response = HTTParty.get(url, headers: default_request_headers)
19
+ response = get_request(path)
20
20
  extract_collection_items(response).each { |product_model| product_models << product_model }
21
- url = extract_fetch_url(response)
22
- break unless url
21
+ path = extract_next_page_path(response)
22
+ break unless path
23
23
  end
24
24
  end
25
25
  end
@@ -12,7 +12,7 @@ module Akeneo
12
12
  end
13
13
 
14
14
  def find(id)
15
- response = get_request("products/#{id}")
15
+ response = get_request("/products/#{id}")
16
16
 
17
17
  response.parsed_response if response.success?
18
18
  end
@@ -29,14 +29,14 @@ module Akeneo
29
29
 
30
30
  def all(with_family: nil)
31
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
32
+ path = "/products?#{pagination_param}&#{limit_param}"
33
+ path += search_with_family_param(with_family) if with_family
34
34
 
35
35
  loop do
36
- response = HTTParty.get(url, headers: default_request_headers)
36
+ response = get_request(path)
37
37
  extract_collection_items(response).each { |product| products << product }
38
- url = extract_fetch_url(response)
39
- break unless url
38
+ path = extract_next_page_path(response)
39
+ break unless path
40
40
  end
41
41
  end
42
42
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './service_base.rb'
4
+
5
+ module Akeneo
6
+ class PublishedProductService < ServiceBase
7
+ def initialize(url:, access_token:)
8
+ @url = url
9
+ @access_token = access_token
10
+ end
11
+
12
+ def published_products(updated_after: nil)
13
+ Enumerator.new do |products|
14
+ path = "/published-products?#{pagination_param}"
15
+ path += "&#{search_param(updated_after)}" if updated_after
16
+
17
+ loop do
18
+ response = get_request(path)
19
+ extract_products(response).each { |product| products << product }
20
+ path = extract_next_page_path(response)
21
+ break unless path
22
+ end
23
+ end.lazy
24
+ end
25
+
26
+ private
27
+
28
+ def search_param(updated_after)
29
+ return unless updated_after
30
+
31
+ format('search={"updated":[{"operator":">","value":"%<date>s"}]}', date: updated_after.strftime('%F %T'))
32
+ end
33
+
34
+ def extract_products(response)
35
+ return [] unless response.success?
36
+
37
+ response.parsed_response['_embedded']['items']
38
+ end
39
+ end
40
+ end
@@ -29,7 +29,7 @@ module Akeneo
29
29
 
30
30
  def get_request(path, options = {})
31
31
  HTTParty.get(
32
- "#{@url}/api/rest/v1/#{path}",
32
+ "#{@url}/api/rest/v1#{path}",
33
33
  options.merge(headers: default_request_headers)
34
34
  )
35
35
  end
@@ -48,10 +48,11 @@ module Akeneo
48
48
  response.parsed_response['_embedded']['items']
49
49
  end
50
50
 
51
- def extract_fetch_url(response)
51
+ def extract_next_page_path(response)
52
52
  return unless response.success?
53
53
 
54
- response.parsed_response.dig('_links', 'next', 'href')
54
+ url = response.parsed_response.dig('_links', 'next', 'href')
55
+ url.to_s.split('/api/rest/v1').last
55
56
  end
56
57
  end
57
58
  end
@@ -8,6 +8,7 @@ require_relative './image_service'
8
8
  require_relative './measure_family_service'
9
9
  require_relative './product_model_service'
10
10
  require_relative './product_service'
11
+ require_relative './published_product_service'
11
12
 
12
13
  module Akeneo
13
14
  module Services
@@ -47,5 +48,9 @@ module Akeneo
47
48
  def product_model_service
48
49
  ProductModelService.new(url: url, access_token: fresh_access_token)
49
50
  end
51
+
52
+ def published_product_service
53
+ PublishedProductService.new(url: url, access_token: fresh_access_token)
54
+ end
50
55
  end
51
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akeneo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AWN Dev Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-08 00:00:00.000000000 Z
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".circleci/config.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".rubocop.yml"
@@ -140,6 +141,7 @@ files:
140
141
  - lib/akeneo/measure_family_service.rb
141
142
  - lib/akeneo/product_model_service.rb
142
143
  - lib/akeneo/product_service.rb
144
+ - lib/akeneo/published_product_service.rb
143
145
  - lib/akeneo/service_base.rb
144
146
  - lib/akeneo/services.rb
145
147
  homepage: https://github.com/awniemeyer/akeneo
@@ -162,7 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
164
  - !ruby/object:Gem::Version
163
165
  version: '0'
164
166
  requirements: []
165
- rubygems_version: 3.0.2
167
+ rubyforge_project:
168
+ rubygems_version: 2.7.6
166
169
  signing_key:
167
170
  specification_version: 4
168
171
  summary: API client for accessing Akeneo