aboutyou-sdk 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDBmNjhmNzliNGI3N2JjOTk4MDgxODc0NDBjNTYwZjI5N2RlNGIzZA==
4
+ NDI2YWFmYTE1OWEzMDIxM2ZiYzgxN2IwNWExOTc1MjM5MjI3MWRkNw==
5
5
  data.tar.gz: !binary |-
6
- YWZkODI5NmM1ODhhMDFiOWJkNTBmODI3ZjczYTIzYjRjZDJiMzc2OQ==
6
+ OTMyZGRkNjUzOWRiZDAwMGFmMTczMTJjZWMxMDdiOTYxY2IzNThmYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDJhYjY1MGRhYjc3ZjEyOWM4YTNiZDlhMGY0YjZiOGM0Y2UxNWM5YjI1ZTQx
10
- NzY4Y2JiMzljMDBlYzliNTVhYjY4ODNmN2ExYjQyMTlmMDBhY2M3NmUzYzBj
11
- ZDg4YzdlOGZhNzA5Yjg0ZGZmZjdmOGE2YzQyNDc1MWM0MTE3NjI=
9
+ ZDQ4N2MwZjIzODI4NWVmNzUyZDhhZGM3ZTI3ZWM4NWE4MzMxMzI3MTVkNzA3
10
+ MjMwNDk2NmZlYzBhNjhmOGJhZjRjMDAzN2FhODhkODkwNDQyYjU3Y2QzODRi
11
+ NTFlMzM2MjU4MDZiNDBjZGU2YzI1NDQ5NzhmYjI3MDVkOTI4NTI=
12
12
  data.tar.gz: !binary |-
13
- NDAxMWRlNjQyNDdkZWU4ZjU1M2I1OTQ3ZjExMTViNmEwMjFlYzA3NzcyZjg0
14
- MDI2OTg2MmMzMmQzMTRkMmI1Y2U3NmY5ZTQxNjEyZGU5YTUzZjRjYzNiZTJi
15
- NTAyMmYyNDUwMGZmMWE0NWM1N2E4ZTE2NDk2YTA4YmM0MTdlYzM=
13
+ OWZiNzIxNWNiOWNlMTRlZjY3OTE0Y2ZlYzI2ZGE1ZmZhYTRmZjUwZDM4ZGVh
14
+ NTg2YTljMzM3NGQyYTViM2FjNTBiMjkyMTFmYzQ3OTQxY2U5MjAwODU2NDM1
15
+ MTYzYWViOWMzNTM2NTNmZTgzNzlhOGQwODVlNmY2YTM1MzZiYTE=
@@ -63,17 +63,11 @@ class AY
63
63
  appPassword,
64
64
  sessionId = 'SESSION_ID',
65
65
  cache = nil,
66
- cacheServer= nil,
67
66
  apiEndPoint = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE,
68
67
  resultFactory = nil,
69
68
  logger = nil
70
69
  )
71
-
72
- if cacheServer == nil
73
- cacheServer = 'localhost:11211' if cache == 'memcache'
74
- cacheServer = {:host => "localhost", :port => 6379} if cache == 'redis'
75
- end
76
-
70
+
77
71
  self.sessionId = sessionId
78
72
  self.appId = appId
79
73
  self.appPassword = appPassword
@@ -84,9 +78,7 @@ class AY
84
78
  logger
85
79
  )
86
80
 
87
- self.cache = Dalli::Client.new(cacheServer, {:value_max_bytes => 5242880}) if cache == 'memcache'
88
- self.cache = Redis.new(cacheServer) if cache == 'redis'
89
-
81
+ self.cache = cache
90
82
  if resultFactory
91
83
  self.modelFactoryInstance = resultFactory
92
84
  else
@@ -0,0 +1,28 @@
1
+ module AboutYou
2
+ module SDK
3
+ module CacheProvider
4
+ class Dalli
5
+ attr_accessor :client
6
+ def initialize(client)
7
+ self.client = client
8
+ end
9
+
10
+ def set(key, value, duration)
11
+ self.client.set(key, value, duration)
12
+ end
13
+
14
+ def get(key)
15
+ self.client.get(key)
16
+ end
17
+
18
+ def delete(key)
19
+ self.client.delete(key)
20
+ end
21
+
22
+ def exists(key)
23
+ self.client.get(key) != nil
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module AboutYou
2
+ module SDK
3
+ module CacheProvider
4
+ class Redis
5
+ attr_accessor :client
6
+ def initialize(client)
7
+ self.client = client
8
+ end
9
+
10
+ def set(key, value, duration)
11
+ value = value.to_json unless value.is_a?(String)
12
+ self.client.set(key, value)
13
+ self.client.expire(key, duration)
14
+ end
15
+
16
+ def get(key)
17
+ JSON.parse(self.client.get(key))
18
+ end
19
+
20
+ def delete(key)
21
+ self.client.del(key)
22
+ end
23
+
24
+ def exists(key)
25
+ self.client.exists(key)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -44,27 +44,21 @@ module AboutYou
44
44
  # Gets the cached Categories for this app
45
45
  ###
46
46
  def loadCachedCategories
47
- parseJson(self.cache.get(self.cacheKey), self.shopApi.modelFactoryInstance) if self.cache && self.cache.get(self.cacheKey)
47
+ parseJson(self.cache.get(self.cacheKey), self.shopApi.modelFactoryInstance) if self.cache && self.cache.exists(self.cacheKey)
48
48
  end
49
49
 
50
50
  ###
51
51
  # This method caches the currently read-in categories
52
52
  ###
53
53
  def cacheCategories(jsonObject)
54
- self.cache.set(self.cacheKey, jsonObject, DEFAULT_CACHE_DURATION) if self.cache.instance_of?(Dalli::Client)
55
- if self.cache.instance_of?(Redis)
56
- jsonObject = jsonObject.to_json unless jsonObject.is_a? String
57
- self.cache.set(self.cacheKey, jsonObject)
58
- self.cache.expire(self.cacheKey, DEFAULT_CACHE_DURATION)
59
- end
54
+ self.cache.set(self.cacheKey, jsonObject, DEFAULT_CACHE_DURATION)
60
55
  end
61
56
 
62
57
  ###
63
58
  # This method clears the cache
64
59
  ###
65
60
  def clearCache
66
- self.cache.delete(self.cacheKey) if self.cache.instance_of?(Dalli::Client)
67
- self.cache.del(self.cacheKey) if self.cache.instance_of?(Redis)
61
+ self.cache.delete(self.cacheKey)
68
62
  end
69
63
 
70
64
  ###
@@ -81,7 +75,6 @@ module AboutYou
81
75
  def parseJson(jsonObject, factory)
82
76
  unless self.categories
83
77
  self.categories = {}
84
- jsonObject = JSON.parse(jsonObject) if jsonObject.is_a? String
85
78
 
86
79
  if jsonObject
87
80
  self.cacheCategories(jsonObject)
@@ -32,26 +32,19 @@ module AboutYou
32
32
  end
33
33
 
34
34
  def loadCachedFacets
35
- parseJson(self.cache.get(self.cacheKey), self.shopApi.modelFactoryInstance) if self.cache && self.cache.get(self.cacheKey)
35
+ parseJson(self.cache.get(self.cacheKey), self.shopApi.modelFactoryInstance) if self.cache && self.cache.exists(self.cacheKey)
36
36
  end
37
37
 
38
38
  def cacheFacets(jsonObject)
39
- self.cache.set(self.cacheKey, jsonObject, DEFAULT_CACHE_DURATION) if self.cache.instance_of?(Dalli::Client)
40
- if self.cache.instance_of?(Redis)
41
- jsonObject = jsonObject.to_json unless jsonObject.is_a?(String)
42
- self.cache.set(self.cacheKey, jsonObject)
43
- self.cache.expire(self.cacheKey, DEFAULT_CACHE_DURATION)
44
- end
39
+ self.cache.set(self.cacheKey, jsonObject, DEFAULT_CACHE_DURATION)
45
40
  end
46
41
 
47
42
  def clearCache
48
- self.cache.delete(self.cacheKey) if self.cache.instance_of?(Dalli::Client)
49
- self.cache.del(self.cacheKey) if self.cache.instance_of?(Redis)
43
+ self.cache.delete(self.cacheKey)
50
44
  end
51
45
 
52
46
  def parseJson(jsonObject, factory, query=nil)
53
47
  unless self.facets
54
- jsonObject = JSON.parse(jsonObject) if jsonObject.is_a?(String)
55
48
  if jsonObject
56
49
  self.cacheFacets(jsonObject)
57
50
  self.facets = factory.createFacetsList(jsonObject, query)
@@ -3,13 +3,13 @@ require "pry_debug"
3
3
  require_relative'../lib/aboutyou-sdk.rb'
4
4
 
5
5
  get "/doCache" do
6
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
7
- shop.fetchProductsByIds([661132, 660971, 661367, 661361], [AboutYou::SDK::Criteria::ProductFields::CATEGORIES])
6
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Dalli.new(Dalli::Client.new))
7
+ shop.fetchProductsByIds([661132, 660971, 661367, 661361], [AboutYou::SDK::Criteria::ProductFields::CATEGORIES])
8
8
  end
9
9
 
10
10
  get "/getCache" do
11
11
  result = ""
12
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
12
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Dalli.new(Dalli::Client.new))
13
13
 
14
14
  shop.fetchCategoryTree.categories.each do |key, cate|
15
15
  result = result + cate.name + ' '
@@ -20,7 +20,7 @@ end
20
20
 
21
21
  get "/noCache" do
22
22
  result = ""
23
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
23
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Dalli.new(Dalli::Client.new))
24
24
  shop.cache.delete('AY:SDK:281:categories')
25
25
 
26
26
  shop.fetchCategoryTree.categories.each do |key, cate|
@@ -3,14 +3,14 @@ require "pry_debug"
3
3
  require_relative'../lib/aboutyou-sdk.rb'
4
4
 
5
5
  get "/doCache" do
6
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
7
- shop.fetchFacets(["0"])
8
- return "done"
6
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Dalli.new(Dalli::Client.new))
7
+ shop.fetchFacets(["0"])
8
+ return "done"
9
9
  end
10
10
 
11
11
  get "/getCache" do
12
12
  result = ""
13
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
13
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Dalli.new(Dalli::Client.new))
14
14
 
15
15
  shop.fetchFacets(["0"]).each do |key, facet|
16
16
  result = result + key + '</br>'
@@ -21,7 +21,7 @@ end
21
21
 
22
22
  get "/noCache" do
23
23
  result = ""
24
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
24
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Dalli.new(Dalli::Client.new))
25
25
  puts shop.cache.delete('AY:SDK:281:facets')
26
26
  shop.fetchFacets(["0"]).each do |key, facet|
27
27
  result = result + key + '</br>'
@@ -3,13 +3,13 @@ require "pry_debug"
3
3
  require_relative'../lib/aboutyou-sdk.rb'
4
4
 
5
5
  get "/doCache" do
6
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'redis')
7
- shop.fetchProductsByIds([661132, 660971, 661367, 661361], [AboutYou::SDK::Criteria::ProductFields::CATEGORIES])
6
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Redis.new(Redis.new))
7
+ shop.fetchProductsByIds([661132, 660971, 661367, 661361], [AboutYou::SDK::Criteria::ProductFields::CATEGORIES])
8
8
  end
9
9
 
10
10
  get "/getCache" do
11
11
  result = ""
12
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'redis')
12
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Redis.new(Redis.new))
13
13
 
14
14
  shop.fetchCategoryTree.categories.each do |key, cate|
15
15
  result = result + cate.name + ' '
@@ -20,7 +20,7 @@ end
20
20
 
21
21
  get "/noCache" do
22
22
  result = ""
23
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'redis')
23
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', AboutYou::SDK::CacheProvider::Redis.new(Redis.new))
24
24
  shop.cache.delete('AY:SDK:281:categories')
25
25
 
26
26
  shop.fetchCategoryTree.categories.each do |key, cate|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aboutyou-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferenc Beutel
@@ -73,6 +73,8 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - lib/aboutyou-sdk.rb
76
+ - lib/aboutyou-sdk/CacheProvider/Dalli.rb
77
+ - lib/aboutyou-sdk/CacheProvider/Redis.rb
76
78
  - lib/aboutyou-sdk/Client.rb
77
79
  - lib/aboutyou-sdk/Constants.rb
78
80
  - lib/aboutyou-sdk/Criteria/ProductFields.rb