akeneo 1.0.0 → 1.1.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: c8a4e07e19a36d3d570b8dc21b683910d558e2876755d8cb0c2e604155d8a70a
4
- data.tar.gz: cfc04059a593500dacb17106847bcc9b2ef8b7c90967693ef193dfda63128c28
3
+ metadata.gz: a82b6a9e634b7a0546533a4f38fe55a8d7d535332a1426b675c6a963d1dbd165
4
+ data.tar.gz: 86fc515d5ac913e36213f8e3e34b28aebe59face66e52655bc28410ca619b3f7
5
5
  SHA512:
6
- metadata.gz: 8b1171a0cab489133295291cd3d8163de7651b8b9e9ba6fd0c5e34ddf66b54b566c85fdf536768759b88a81d4d6515ca09959bdc57096c7191805488c032181e
7
- data.tar.gz: 2d5972a171f1a369d95c73770f472e31abd18be22630cc6aa00fc089b010cd3cd5aeb3339ebadc2c99fa066f3ebc7ad857e2077ad8d1fdf004bc84bec2ace242
6
+ metadata.gz: 46fea6aa7926d012898b73b5e5bd00df2de2d763eeb8e99f8fd7155e47dc389d93182dff0ec9226ff2071184f668f29b14f31406e8efb21274631a4ff6f107d0
7
+ data.tar.gz: 86f85f185ca25353bd532c938a41bf5ae73af585fa77a73f5f01832fe6fed5d24f8f5d84cea257f8ccecf4bbbecfadc9948eeea748190b745dfc6c9d5108ba17
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ PATH
3
3
  specs:
4
4
  akeneo (1.0.0)
5
5
  httparty
6
+ redis
6
7
  semantic_logger
7
8
 
8
9
  GEM
@@ -31,6 +32,7 @@ GEM
31
32
  public_suffix (3.0.3)
32
33
  rainbow (3.0.0)
33
34
  rake (12.3.2)
35
+ redis (4.1.0)
34
36
  rspec (3.8.0)
35
37
  rspec-core (~> 3.8.0)
36
38
  rspec-expectations (~> 3.8.0)
@@ -73,4 +75,4 @@ DEPENDENCIES
73
75
  webmock
74
76
 
75
77
  BUNDLED WITH
76
- 1.17.2
78
+ 1.17.3
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # akeneo
2
+
2
3
  API client for accessing Akeneo.
3
4
 
4
5
  Usage:
@@ -17,3 +18,15 @@ client = Akeneo::API.new(
17
18
  client.product(511707)
18
19
  # => {"identifier"=>"511707", "family"=>"simple_product", "parent"=>nil, "groups"=>[]...
19
20
  ```
21
+
22
+ ## Configuration
23
+
24
+ ### Caching
25
+
26
+ If you want to use redis as a caching layer you have to set the `REDIS_URL` ENV variable.
27
+ By default the request will be cached for 5 Minutes.
28
+ You can alter the cache expiration via the `AKENEO_CACHE_EXPIRES_IN` ENV variable.
29
+
30
+ Caching is enabled by default whenever you have redis running.
31
+ You can disable caching completely by setting
32
+ `Akeneo::Cache.disabled = true` before you use the service.
data/akeneo.gemspec CHANGED
@@ -34,5 +34,6 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'rubocop'
35
35
  spec.add_development_dependency 'webmock'
36
36
  spec.add_dependency 'httparty'
37
+ spec.add_dependency 'redis'
37
38
  spec.add_dependency 'semantic_logger'
38
39
  end
data/lib/akeneo.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  require 'akeneo/api'
4
4
 
5
5
  module Akeneo
6
- VERSION = '1.0.0'
6
+ VERSION = '1.1.0'
7
7
  end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'redis'
4
+
5
+ module Akeneo
6
+ module Cache
7
+ DEFAULT_EXPIRES_IN = 5 * 60
8
+
9
+ @@disabled = false # rubocop:disable Style/ClassVars
10
+
11
+ def self.disabled=(value)
12
+ @@disabled = value # rubocop:disable Style/ClassVars
13
+ end
14
+
15
+ module ClassMethods
16
+ def redis
17
+ @redis ||= Redis.new
18
+ end
19
+ end
20
+
21
+ def self.prepended(base)
22
+ base.extend(ClassMethods)
23
+ end
24
+
25
+ def get_request(path, options = {})
26
+ return super if disabled?
27
+
28
+ key = path.downcase
29
+ key << options[:query].to_s if defined? options[:query]
30
+
31
+ cached_response = read(key)
32
+ return cached_response unless cached_response.nil?
33
+
34
+ response = super
35
+
36
+ write(key, response)
37
+ response
38
+ rescue Redis::CannotConnectError
39
+ super
40
+ end
41
+
42
+ private
43
+
44
+ def read(key)
45
+ serialized_response = self.class.redis.get("akeneo:#{key}")
46
+ load_response(serialized_response) if serialized_response
47
+ end
48
+
49
+ def write(key, response)
50
+ self.class.redis.set("akeneo:#{key}", serialize_response(response), ex: expires_in)
51
+ end
52
+
53
+ def serialize_response(response)
54
+ Marshal.dump(response)
55
+ end
56
+
57
+ def load_response(serialized_response)
58
+ Marshal.load(serialized_response) # rubocop:disable Security/MarshalLoad
59
+ end
60
+
61
+ def disabled?
62
+ @@disabled
63
+ end
64
+
65
+ def expires_in
66
+ ENV.fetch('AKENEO_CACHE_EXPIRES_IN', DEFAULT_EXPIRES_IN)
67
+ end
68
+ end
69
+ end
@@ -3,8 +3,12 @@
3
3
  require 'httparty'
4
4
  require 'semantic_logger'
5
5
 
6
+ require_relative './cache'
7
+
6
8
  module Akeneo
7
9
  class ServiceBase
10
+ prepend Cache
11
+
8
12
  DEFAULT_PAGINATION_TYPE = :search_after
9
13
  DEFAULT_PAGINATION_LIMIT = 100
10
14
 
@@ -23,8 +27,11 @@ module Akeneo
23
27
  { 'Authorization' => "Bearer #{@access_token}" }.merge(json_headers)
24
28
  end
25
29
 
26
- def get_request(path)
27
- HTTParty.get("#{@url}/api/rest/v1/#{path}", headers: default_request_headers)
30
+ def get_request(path, options = {})
31
+ HTTParty.get(
32
+ "#{@url}/api/rest/v1/#{path}",
33
+ options.merge(headers: default_request_headers)
34
+ )
28
35
  end
29
36
 
30
37
  def pagination_param
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.0.0
4
+ version: 1.1.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-07 00:00:00.000000000 Z
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redis
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'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: semantic_logger
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +133,7 @@ files:
119
133
  - lib/akeneo/api.rb
120
134
  - lib/akeneo/attribute_service.rb
121
135
  - lib/akeneo/authorization_service.rb
136
+ - lib/akeneo/cache.rb
122
137
  - lib/akeneo/category_service.rb
123
138
  - lib/akeneo/family_service.rb
124
139
  - lib/akeneo/image_service.rb
@@ -147,8 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
162
  - !ruby/object:Gem::Version
148
163
  version: '0'
149
164
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.6
165
+ rubygems_version: 3.0.2
152
166
  signing_key:
153
167
  specification_version: 4
154
168
  summary: API client for accessing Akeneo