aboutyou-sdk 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWI2YjA3YmNlNTE2ZTE4YzQ4YWM0NGZkMTYyYTQ5ZjM4MjZiNDQxOQ==
4
+ NDQzMDNhYThmZmVhMjk4MTQzZDMxZDBhMWE1MWQzZWYxY2EwYjgzYQ==
5
5
  data.tar.gz: !binary |-
6
- ODZhYjdhYWZlOWFkOGY3MzdhMDg0NjhjMmM1ZWJiODM4NzZkNDIyNQ==
6
+ MjJiMWEyZTg1ZTFkY2NhMjg4ZjY0NWY5M2Q0OWM1NGM1YjAyZmM0Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODBmNGUxMGUzMzk3MmJjODk5NjhmZDllZDJjYTc1YmMzNGZlMjZhYWE1ZDBk
10
- NjdkMmVmZmRjNmJhODJjODNhMDhmZmIwMDRmMDJlZGJlODE1MDU2ODA5ODdj
11
- ZTgwMTA5MTVjNDdmNzc1YWViYmNhNjlhOWZkMWY2Y2NlY2VlZDI=
9
+ ZmU3ZDljM2UwYmE0ODgzZjNkZTk3MGRmOTFhNWEyYmVmMGVmYzAwMDQ2ZmYz
10
+ ZjZkZmFlZjE1MTk0MTk3ZmU2NWZhMmEzOGY0ZmY3OTA0NmRmN2U4ZGZhMDY3
11
+ ZWY3OWM5MjY4ODA1ZDU3YjA3ODg3NTk4NDNiOTk5Y2RiYmI0ZWM=
12
12
  data.tar.gz: !binary |-
13
- YWY3NzA5ZTgwZTRjZDQ1NzdiYTdlOTUwMmRiYjVmNjgzZGJhYWQ0ZWFlZDUw
14
- YWQ1NzhkNDYxZTVlYmYwZDFmMmZiNWNjMmM1YTgzZGFhYzY1NzMzNGUyZDE1
15
- MzM1NDRjYWI2MTgwYzljYjczMWJjNjYyM2JkYmE5NjY5NzY5OGY=
13
+ NGI0OWFkYTFiOGM4ZDM0MzhiODMxOGRhMzQ5NjIxMzdiMDdmZjQ4NmFkNDE2
14
+ MmZhMDU4YmYxZmVkMmE4ODI2ZGQwMzgxZGYxYjJjYmI3MjI3OWUzYjAzN2Nk
15
+ ZDdiYzQzN2E5ZDk5ZThlYjdjYWExYjMyZTA0ZGI5Y2JlMzFlYTY=
@@ -60,6 +60,7 @@ class AY
60
60
  appPassword,
61
61
  sessionId = 'SESSION_ID',
62
62
  cache = nil,
63
+ cacheServer= 'localhost:11211',
63
64
  apiEndPoint = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE,
64
65
  resultFactory = nil,
65
66
  logger = nil
@@ -85,7 +86,7 @@ class AY
85
86
  end
86
87
  if cache == 'memcache'
87
88
  require 'dalli'
88
- self.cache = Dalli::Client.new('localhost:11211')
89
+ self.cache = Dalli::Client.new(cacheServer, {:value_max_bytes => 5242880})
89
90
  end
90
91
  resultFactory ? self.modelFactoryInstance = resultFactory : initDefaultFactory(self.cache)
91
92
  end
@@ -374,10 +375,10 @@ class AY
374
375
  # - Instance of AboutYou::SDK::Model::Facet
375
376
  ###
376
377
  def fetchFacets(groupIds=[])
377
-
378
- query.fetchFacets(groupIds).executeSingle
379
-
380
- self.modelFactoryInstance.facetManager.facets
378
+ if self.modelFactoryInstance.facetManager.isEmpty
379
+ query.fetchFacets.executeSingle
380
+ end
381
+ self.modelFactoryInstance.facetManager.facetsByGroupIds(groupIds)
381
382
  end
382
383
 
383
384
 
@@ -582,8 +583,8 @@ class AY
582
583
  ###
583
584
  def initDefaultFactory(cache = nil)
584
585
  resultFactory = AboutYou::SDK::Factory::DefaultModelFactory.new(self,
585
- AboutYou::SDK::Model::FacetManager::DefaultFacetManager.new,
586
- AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager.new(cache, self.appId)
586
+ AboutYou::SDK::Model::FacetManager::DefaultFacetManager.new(cache, self.appId, self),
587
+ AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager.new(cache, self.appId, self)
587
588
  )
588
589
  resultFactory.baseImageUrl=(self.baseImageUrl)
589
590
 
@@ -187,7 +187,7 @@ module AboutYou
187
187
  # * *Returns* :
188
188
  # - a Hash containing pairs of facetKey => AboutYou::SDK::Model::Facet
189
189
  ###
190
- def createFacetsList(jsonObject, query)
190
+ def createFacetsList(jsonObject, query=nil)
191
191
  self.createFacetList(jsonObject["facet"], query)
192
192
  end
193
193
 
@@ -515,7 +515,7 @@ module AboutYou
515
515
  # - +query+ -> the query sent to the api
516
516
  ###
517
517
  def updateFacetManager(jsonObject, query)
518
- self.facetManager.facets=(self.createFacetsList(jsonObject, query))
518
+ self.facetManager.parseJson(jsonObject, self, query)
519
519
  end
520
520
 
521
521
  ###
@@ -20,6 +20,7 @@ module AboutYou
20
20
  attr_accessor :cache
21
21
  # the cache key for the app
22
22
  attr_accessor :cacheKey
23
+ attr_accessor :shopApi
23
24
 
24
25
  ###
25
26
  # the Constructor for the AY class
@@ -31,7 +32,8 @@ module AboutYou
31
32
  # * *Returns* :
32
33
  # - Instance of AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager
33
34
  ###
34
- def initialize(cache = nil, appId = '')
35
+ def initialize(cache = nil, appId = '', shopApi)
36
+ self.shopApi = shopApi
35
37
  self.cache = cache
36
38
  self.cacheKey = 'AY:SDK:' + String(appId) + ':categories'
37
39
  self.loadCachedCategories
@@ -42,17 +44,16 @@ module AboutYou
42
44
  ###
43
45
  def loadCachedCategories
44
46
  if self.cache
45
- self.categories = self.cache.get(self.cacheKey) ? self.cache.get(self.cacheKey) : nil
47
+ parseJson(self.cache.get(self.cacheKey), self.shopApi.modelFactoryInstance)
46
48
  end
47
49
  end
48
50
 
49
51
  ###
50
52
  # This method caches the currently read-in categories
51
53
  ###
52
- def cacheCategories
54
+ def cacheCategories(jsonObject)
53
55
  if self.cache
54
- binding.pry
55
- self.cache.set(self.cacheKey, self.categories, DEFAULT_CACHE_DURATION)
56
+ self.cache.set(self.cacheKey, jsonObject, DEFAULT_CACHE_DURATION)
56
57
  end
57
58
  end
58
59
 
@@ -78,13 +79,13 @@ module AboutYou
78
79
  ###
79
80
  def parseJson(jsonObject, factory)
80
81
  self.categories = {}
81
- self.parentChildIds = jsonObject["parent_child"]
82
-
83
- jsonObject["ids"].each do |id, jsonCategory|
84
- self.categories[id] = factory.createCategory(jsonCategory)
82
+ if jsonObject
83
+ self.cacheFacets(jsonObject)
84
+ self.parentChildIds = jsonObject["parent_child"]
85
+ jsonObject["ids"].each do |id, jsonCategory|
86
+ self.categories[id] = factory.createCategory(jsonCategory)
87
+ end
85
88
  end
86
- self.cacheCategories()
87
- self
88
89
  end
89
90
 
90
91
  ###
@@ -15,16 +15,17 @@ module AboutYou
15
15
  attr_accessor :cache
16
16
 
17
17
  # @var string */
18
- @cacheKey;
19
18
  attr_accessor :cacheKey
19
+ attr_accessor :shopApi
20
20
 
21
21
  ###
22
22
  # @param Cache $cache
23
23
  # @param string $appId
24
24
  ###
25
- def initialize(cache = nil, appId = '')
25
+ def initialize(cache = nil, appId = '', shopApi)
26
26
 
27
27
  self.cache = cache;
28
+ self.shopApi = shopApi
28
29
  self.cacheKey = 'AY:SDK:' + String(appId) + ':facets';
29
30
  self.facets = Hash.new
30
31
 
@@ -34,14 +35,14 @@ module AboutYou
34
35
  def loadCachedFacets()
35
36
 
36
37
  if (self.cache)
37
- self.facets = (self.cache.fetch(self.cacheKey)) ? self.cache.fetch(self.cacheKey): nil;
38
+ parseJson(self.cache.get(self.cacheKey), self.shopApi.modelFactoryInstance)
38
39
  end
39
40
  end
40
41
 
41
- def cacheFacets()
42
+ def cacheFacets(jsonObject)
42
43
 
43
- if (self.cache)
44
- self.cache.save(self.cacheKey, self.facets, DEFAULT_CACHE_DURATION);
44
+ if (self.cache)
45
+ self.cache.set(self.cacheKey, jsonObject, DEFAULT_CACHE_DURATION);
45
46
  end
46
47
  end
47
48
 
@@ -51,16 +52,16 @@ module AboutYou
51
52
  self.cache.delete(self.cacheKey);
52
53
  end
53
54
  end
54
-
55
- def isEmpty()
56
55
 
57
- return (self.facets.empty?);
56
+ def parseJson(jsonObject, factory, query=nil)
57
+ if jsonObject
58
+ self.cacheFacets(jsonObject)
59
+ self.facets = factory.createFacetsList(jsonObject, query)
60
+ end
58
61
  end
59
62
 
60
- def facets=(facets)
61
-
62
- @facets = facets;
63
- self.cacheFacets();
63
+ def isEmpty()
64
+ return (self.facets.empty?);
64
65
  end
65
66
 
66
67
  ###
@@ -71,6 +72,11 @@ module AboutYou
71
72
  lookupKey = AboutYou::SDK::Model::Facet.new(0, "", [], 0, "").uniqueKey(groupId, id);
72
73
  return (self.facets[lookupKey]) ? self.facets[lookupKey] : nil;
73
74
  end
75
+
76
+ def facetsByGroupIds(groupIds = [])
77
+ groupIds = groupIds.map { |gId| Integer(gId) }
78
+ self.facets.select { |key, facet| groupIds.include?(facet.groupId) }
79
+ end
74
80
  end
75
81
  end
76
82
  end
@@ -106,6 +106,10 @@ module AboutYou
106
106
 
107
107
  return self
108
108
  end
109
+
110
+ def fetchFacets(groupIds=[])
111
+ super(groupIds)
112
+ end
109
113
 
110
114
  ###
111
115
  # wrapper-method for fetchProductsByIds which coordinates Category- and Facet-Manager
@@ -0,0 +1,35 @@
1
+ require 'sinatra'
2
+ require "pry_debug"
3
+ require_relative'../lib/aboutyou-sdk.rb'
4
+
5
+ get "/doCache" do
6
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
7
+ shop.fetchProductsByIds(
8
+ [661132, 660971, 661367, 661361],
9
+ [AboutYou::SDK::Criteria::ProductFields::CATEGORIES,
10
+ AboutYou::SDK::Criteria::ProductFields::VARIANTS]
11
+ )
12
+ end
13
+
14
+ get "/getCache" do
15
+ result = ""
16
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
17
+
18
+ shop.fetchCategoryTree.categories.each do |key, cate|
19
+ result = result + cate.name + ' '
20
+ end
21
+
22
+ return result
23
+ end
24
+
25
+ get "/noCache" do
26
+ result = ""
27
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
28
+ shop.cache.delete('AY:SDK:281:categories')
29
+
30
+ shop.fetchCategoryTree.categories.each do |key, cate|
31
+ result = result + cate.name + ' '
32
+ end
33
+
34
+ return result
35
+ end
@@ -0,0 +1,31 @@
1
+ require 'sinatra'
2
+ require "pry_debug"
3
+ require_relative'../lib/aboutyou-sdk.rb'
4
+
5
+ get "/doCache" do
6
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
7
+ shop.fetchFacets(["0"])
8
+ return "done"
9
+ end
10
+
11
+ get "/getCache" do
12
+ result = ""
13
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
14
+
15
+ shop.fetchFacets(["0"]).each do |key, facet|
16
+ result = result + key + '</br>'
17
+ end
18
+
19
+ return result
20
+ end
21
+
22
+ get "/noCache" do
23
+ result = ""
24
+ shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
25
+ puts shop.cache.delete('AY:SDK:281:facets')
26
+ shop.fetchFacets(["0"]).each do |key, facet|
27
+ result = result + key + '</br>'
28
+ end
29
+
30
+ return result
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aboutyou-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferenc Beutel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dalli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Use the Ruby SDK to build apps for the ABOUT YOU platform.
56
70
  email: ferenc1993beutel@gmx.de
57
71
  executables: []
@@ -104,7 +118,8 @@ files:
104
118
  - tests/testAutocomplete.rb
105
119
  - tests/testCatFilter.rb
106
120
  - tests/testCatTree.rb
107
- - tests/testDalli.rb
121
+ - tests/testCategoryCaching.rb
122
+ - tests/testFacetCaching.rb
108
123
  - tests/testFacetTypes.rb
109
124
  - tests/testFacets.rb
110
125
  - tests/testFetchFacet.rb
@@ -1,15 +0,0 @@
1
- require 'sinatra'
2
- require "pry_debug"
3
- require_relative'../lib/aboutyou-sdk.rb'
4
-
5
- shop = AY.new(281, 'e6068c4ca020262613d06122663cb300', 'sessionId', 'memcache')
6
-
7
- shop.fetchProductsByIds(
8
- [661132, 660971, 661367, 661361],
9
- [AboutYou::SDK::Criteria::ProductFields::CATEGORIES,
10
- AboutYou::SDK::Criteria::ProductFields::VARIANTS]
11
- )
12
- get "/" do
13
- binding.pry
14
- return shop.cache.get('AY:SDK:281:categories')
15
- end