bluekai 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: 2e6f268e501ed2d86040a3e6267273dcf13c7a9a
4
- data.tar.gz: cc98c3655b05748e9cb5f0e37372c72e3aa0ec7a
3
+ metadata.gz: 51af5eb445beb71937839077803c711846d636b1
4
+ data.tar.gz: 8358216076ae1562c321988381de79a700c24b36
5
5
  SHA512:
6
- metadata.gz: 45b3f3c233cdc04d4d932288e28fb6ceeb52b05ac6f722092310452413960469f7d3d5871093b531ce375ac52c6aee955e91adda6fbcc2e8ad082a2c3cd2eb72
7
- data.tar.gz: 0241700e4064701a9c834969b087068490e76547abf60c45d50f023494440819e55c43156fe507005e5da4245e875718972ca2e9c1dfe792b66eb85dc25ffd3c
6
+ metadata.gz: e6ab9bf86b7975e822786df0d50458f5f9051dc59477013ae9149cd9e1f219473ab5f9b15b29fa6dc8da54ecb50ddd6428b06fe5c254f3334e2977e811205e1c
7
+ data.tar.gz: 68e0deae9ecc2f9f95e745ab3607667927cad730bfcf83b35c7a31671dd3ce2acb3987fbe6db1f14770a8d61ea3cad0d56c3745b199e02f021137c500358a112
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- Before you start, please ensure the following variables are correctly set in your environment: `ENV['BLUEKAI_DOMAIN']`, `ENV['BLUEKAI_API_USER_KEY']`, `ENV['BLUEKAI_API_PRIVATE_KEY']` and `ENV['BLUEKAI_PARTNER_ID']`
24
+ Before you start, please ensure the following variables are correctly set in your environment: `ENV['BLUEKAI_API_USER_KEY']`, `ENV['BLUEKAI_API_PRIVATE_KEY']` and `ENV['BLUEKAI_PARTNER_ID']`
25
25
 
26
26
 
27
27
  List all self-classification categories
data/lib/bluekai.rb CHANGED
@@ -1,9 +1,10 @@
1
- require 'bluekai/version'
2
1
  require 'bluekai/client'
3
2
  require 'bluekai/error'
4
- require 'bluekai/rule'
3
+ require 'bluekai/request'
5
4
  require 'bluekai/category'
5
+ require 'bluekai/rule'
6
6
  require 'bluekai/user_data'
7
+ require 'bluekai/version'
7
8
 
8
9
  module Bluekai
9
10
  # Your code goes here...
@@ -141,5 +141,40 @@ module Bluekai
141
141
  def category_update(category_id, body)
142
142
  request('PUT', "/Services/WS/classificationCategories/#{category_id}", {}, body)
143
143
  end
144
+
145
+ # Public: Given the path of a category as array it
146
+ # returns the Bluekai CategoryID, if category path was
147
+ # not found it returns nil
148
+ #
149
+ # name_arr:array_of_string - Self-classification category Path,
150
+ # e.g., ['Self-Classification','Cake','Conversion']
151
+ # for Self-Classification->Cake->Conversion
152
+ # Returns: Bluekai category id
153
+ def category_id(name_arr)
154
+ @category_id_lookup ||= create_category_lookup
155
+ category_id_lookup[name_arr.map(&:downcase)]
156
+ end
157
+
158
+ private
159
+
160
+ attr_accessor :category_id_lookup
161
+
162
+ def construct_category_path(id, categories, path = [])
163
+ entry = categories[id]
164
+ return path.compact unless entry && entry[:name]
165
+ path.unshift(entry[:name])
166
+ construct_category_path(entry[:parent_id], categories, path)
167
+ end
168
+
169
+ def create_category_lookup
170
+ categories_by_id = category_list.each_with_object({}) do |category, acc|
171
+ acc[category[:id]] = category
172
+ end
173
+
174
+ categories_by_id.keys.each_with_object({}) do |category_id, acc|
175
+ key = construct_category_path(category_id, categories_by_id)
176
+ acc[key.map(&:downcase)] = category_id
177
+ end
178
+ end
144
179
  end
145
180
  end
@@ -1,3 +1,3 @@
1
1
  module Bluekai
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1 @@
1
+ �X�D݆�r���n&�CA�Ȯ�7F�� �F
@@ -0,0 +1,247 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://services.bluekai.com/Services/WS/classificationCategories?bksig=GMFY2UTdhs1yuOD4bibpQ0GjyK4T9A43RpSzC7hGHg4=&bkuid=bluekai-api-user-key&sort_by=name&sorting_order=asc
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Mon, 11 May 2015 12:47:27 GMT
17
+ Set-Cookie:
18
+ - JSESSIONID=393EAFDCCAFB4EC941C71A77CB4B91AB; Path=/Services; HttpOnly
19
+ Content-Type:
20
+ - application/json
21
+ Cneonction:
22
+ - close
23
+ Transfer-Encoding:
24
+ - chunked
25
+ body:
26
+ encoding: UTF-8
27
+ string: |-
28
+ {
29
+ "categories" : [ {
30
+ "name" : "a brand new one",
31
+ "id" : 422741,
32
+ "description" : "Brand new category",
33
+ "leaf" : false,
34
+ "notes" : "too new to be true",
35
+ "parent_id" : 280098,
36
+ "created_at" : "2015-04-01 07:16:01-0500",
37
+ "updated_at" : "2015-04-01 07:16:01-0500",
38
+ "analytics_excluded" : false,
39
+ "mutex_children" : false,
40
+ "navigation_only" : false,
41
+ "rules" : [ ]
42
+ }, {
43
+ "name" : "Bengals",
44
+ "id" : 307234,
45
+ "description" : "Football Team",
46
+ "leaf" : true,
47
+ "notes" : null,
48
+ "parent_id" : 280098,
49
+ "created_at" : "2014-02-26 01:43:51-0600",
50
+ "updated_at" : "2014-09-15 18:44:04-0500",
51
+ "analytics_excluded" : false,
52
+ "mutex_children" : false,
53
+ "navigation_only" : false,
54
+ "rules" : [ {
55
+ "id" : 802,
56
+ "name" : "Bengals"
57
+ } ]
58
+ }, {
59
+ "name" : "BurtCorp - Private",
60
+ "id" : 280097,
61
+ "description" : null,
62
+ "leaf" : false,
63
+ "notes" : null,
64
+ "parent_id" : 344,
65
+ "created_at" : null,
66
+ "updated_at" : "2015-04-07 15:08:42-0500",
67
+ "analytics_excluded" : false,
68
+ "mutex_children" : false,
69
+ "navigation_only" : false,
70
+ "rules" : [ ]
71
+ }, {
72
+ "name" : "Green",
73
+ "id" : 314012,
74
+ "description" : "Users who's favorite color is green",
75
+ "leaf" : true,
76
+ "notes" : null,
77
+ "parent_id" : 280098,
78
+ "created_at" : "2014-03-13 08:48:07-0500",
79
+ "updated_at" : "2014-09-15 18:44:04-0500",
80
+ "analytics_excluded" : false,
81
+ "mutex_children" : false,
82
+ "navigation_only" : false,
83
+ "rules" : [ {
84
+ "id" : 883,
85
+ "name" : "Green Rule"
86
+ } ]
87
+ }, {
88
+ "name" : "new test",
89
+ "id" : 289898,
90
+ "description" : "new test",
91
+ "leaf" : true,
92
+ "notes" : null,
93
+ "parent_id" : 280098,
94
+ "created_at" : "2014-01-09 20:35:17-0600",
95
+ "updated_at" : "2014-09-15 18:44:04-0500",
96
+ "analytics_excluded" : false,
97
+ "mutex_children" : false,
98
+ "navigation_only" : false,
99
+ "rules" : [ ]
100
+ }, {
101
+ "name" : "NewYorkCold",
102
+ "id" : 312784,
103
+ "description" : "Category for Testing Taxonomy Permissioning",
104
+ "leaf" : true,
105
+ "notes" : "Sample notes",
106
+ "parent_id" : 280098,
107
+ "created_at" : "2014-03-06 12:07:56-0600",
108
+ "updated_at" : "2014-03-06 12:07:56-0600",
109
+ "analytics_excluded" : false,
110
+ "mutex_children" : false,
111
+ "navigation_only" : false,
112
+ "rules" : [ ]
113
+ }, {
114
+ "name" : "sanat cat new hello",
115
+ "id" : 289897,
116
+ "description" : "sanat test cat hello",
117
+ "leaf" : true,
118
+ "notes" : null,
119
+ "parent_id" : 280098,
120
+ "created_at" : "2014-01-09 15:37:46-0600",
121
+ "updated_at" : "2014-09-15 18:44:04-0500",
122
+ "analytics_excluded" : false,
123
+ "mutex_children" : false,
124
+ "navigation_only" : false,
125
+ "rules" : [ ]
126
+ }, {
127
+ "name" : "Self-Classification",
128
+ "id" : 280098,
129
+ "description" : null,
130
+ "leaf" : false,
131
+ "notes" : null,
132
+ "parent_id" : 280097,
133
+ "created_at" : "2013-11-20 11:37:55-0600",
134
+ "updated_at" : "2014-09-16 23:06:10-0500",
135
+ "analytics_excluded" : true,
136
+ "mutex_children" : false,
137
+ "navigation_only" : true,
138
+ "rules" : [ ]
139
+ }, {
140
+ "name" : "TaxPermissionTest",
141
+ "id" : 312783,
142
+ "description" : "Category for Testing Taxonomy Permissioning",
143
+ "leaf" : true,
144
+ "notes" : "Sample notes",
145
+ "parent_id" : 280098,
146
+ "created_at" : "2014-03-06 11:45:31-0600",
147
+ "updated_at" : "2014-03-06 11:45:31-0600",
148
+ "analytics_excluded" : false,
149
+ "mutex_children" : false,
150
+ "navigation_only" : false,
151
+ "rules" : [ ]
152
+ }, {
153
+ "name" : "Test Category",
154
+ "id" : 289895,
155
+ "description" : "Category for testing",
156
+ "leaf" : true,
157
+ "notes" : null,
158
+ "parent_id" : 280098,
159
+ "created_at" : "2014-01-09 15:09:50-0600",
160
+ "updated_at" : "2014-09-15 18:44:04-0500",
161
+ "analytics_excluded" : false,
162
+ "mutex_children" : false,
163
+ "navigation_only" : false,
164
+ "rules" : [ ]
165
+ }, {
166
+ "name" : "Test Category 123",
167
+ "id" : 425787,
168
+ "description" : "an example category",
169
+ "leaf" : true,
170
+ "notes" : "Just an API test",
171
+ "parent_id" : 422741,
172
+ "created_at" : "2015-04-14 07:43:34-0500",
173
+ "updated_at" : "2015-04-14 07:43:34-0500",
174
+ "analytics_excluded" : false,
175
+ "mutex_children" : false,
176
+ "navigation_only" : false,
177
+ "rules" : [ ]
178
+ }, {
179
+ "name" : "Test Category 321",
180
+ "id" : 424251,
181
+ "description" : "an example category wohooo",
182
+ "leaf" : true,
183
+ "notes" : "",
184
+ "parent_id" : 422741,
185
+ "created_at" : "2015-04-08 05:21:29-0500",
186
+ "updated_at" : "2015-04-08 05:26:10-0500",
187
+ "analytics_excluded" : false,
188
+ "mutex_children" : false,
189
+ "navigation_only" : false,
190
+ "rules" : [ ]
191
+ }, {
192
+ "name" : "updated name",
193
+ "id" : 422749,
194
+ "description" : "Brand new category",
195
+ "leaf" : true,
196
+ "notes" : "too new to be true",
197
+ "parent_id" : 280098,
198
+ "created_at" : "2015-04-01 09:57:58-0500",
199
+ "updated_at" : "2015-04-01 10:22:17-0500",
200
+ "analytics_excluded" : false,
201
+ "mutex_children" : false,
202
+ "navigation_only" : false,
203
+ "rules" : [ ]
204
+ }, {
205
+ "name" : "User Data API Test Category 1",
206
+ "id" : 289896,
207
+ "description" : "New Test Category",
208
+ "leaf" : true,
209
+ "notes" : null,
210
+ "parent_id" : 280098,
211
+ "created_at" : "2014-01-09 15:13:31-0600",
212
+ "updated_at" : "2014-09-15 18:44:04-0500",
213
+ "analytics_excluded" : false,
214
+ "mutex_children" : false,
215
+ "navigation_only" : false,
216
+ "rules" : [ {
217
+ "id" : 357,
218
+ "name" : "Vcat"
219
+ }, {
220
+ "id" : 663,
221
+ "name" : "User Data API Test Rule for category 293896"
222
+ } ]
223
+ }, {
224
+ "name" : "User Data API Test Category 2",
225
+ "id" : 293885,
226
+ "description" : "Test Category for the User Data API sim",
227
+ "leaf" : true,
228
+ "notes" : null,
229
+ "parent_id" : 280098,
230
+ "created_at" : "2014-01-17 09:08:50-0600",
231
+ "updated_at" : "2014-09-15 18:44:04-0500",
232
+ "analytics_excluded" : false,
233
+ "mutex_children" : false,
234
+ "navigation_only" : false,
235
+ "rules" : [ {
236
+ "id" : 658,
237
+ "name" : "User Data API Test Rule 2 "
238
+ }, {
239
+ "id" : 884,
240
+ "name" : "User Data API Test Rule for 293885 "
241
+ } ]
242
+ } ],
243
+ "total_count" : 15
244
+ }
245
+ http_version:
246
+ recorded_at: Mon, 11 May 2015 12:47:27 GMT
247
+ recorded_with: VCR 2.9.3
@@ -53,4 +53,15 @@ RSpec.describe Bluekai::Category, :vcr do
53
53
  description: 'an example category wohooo'
54
54
  )
55
55
  end
56
+
57
+ it 'returns correct category ids' do
58
+ green_id = subject.category_id(['BurtCorp - Private', 'Self-Classification', 'Green'])
59
+ test_id = subject.category_id([
60
+ 'BurtCorp - Private',
61
+ 'Self-Classification',
62
+ 'a brand new one',
63
+ 'Test Category 123'])
64
+ expect(green_id).to eq(314012)
65
+ expect(test_id).to eq(425787)
66
+ end
56
67
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Bluekai::Category do
4
+ describe 'category_id' do
5
+ let(:bluekai_category_list) do
6
+ [
7
+ { name: 'A', id: 1, parent_id: 0 },
8
+ { name: 'B', id: 2, parent_id: 1 },
9
+ { name: 'C', id: 3, parent_id: 2 },
10
+ { name: 'D', id: 4, parent_id: 2 },
11
+ { name: 'E', id: 5, parent_id: 4 }
12
+ ]
13
+ end
14
+
15
+ it 'creates, updates and deletes bluekai rules' do
16
+ expect_any_instance_of(described_class)
17
+ .to receive(:category_list).and_return(bluekai_category_list)
18
+
19
+ expect(subject.category_id(['A'])).to eq(1)
20
+ expect(subject.category_id(%w(A B))).to eq(2)
21
+ expect(subject.category_id(%w(A B C))).to eq(3)
22
+ expect(subject.category_id(%w(A B D))).to eq(4)
23
+ expect(subject.category_id(%w(A B D E))).to eq(5)
24
+
25
+ # case insignificance
26
+ expect(subject.category_id(['a'])).to eq(1)
27
+ expect(subject.category_id(%w(a b c))).to eq(3)
28
+ expect(subject.category_id(%w(A b D e))).to eq(5)
29
+
30
+ # nonexistent paths
31
+ expect(subject.category_id(%w(A B C D))).to be_nil
32
+ expect(subject.category_id([])).to be_nil
33
+ expect(subject.category_id(['B'])).to be_nil
34
+ expect(subject.category_id(%w(B C))).to be_nil
35
+ expect(subject.category_id(%w(B A))).to be_nil
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluekai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ad2games GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -123,6 +123,7 @@ files:
123
123
  - spec/fixtures/signatures/1a4aff70f9ce0f00680a85710f1bcf9d294239c7748dc1a23ce2bc7b3e1dca77
124
124
  - spec/fixtures/signatures/2db01e685f73149994efc9824c10fa91e704fb7256d748c4305101513444f49f
125
125
  - spec/fixtures/signatures/3c33aa44e5fbea304ffda0390ac2e413a02d187d5425f67c3edab34684b2b18f
126
+ - spec/fixtures/signatures/5d4d1a042f84b68a2fdf2cc376c8d96d284a648d003f6d917557b43372f99bba
126
127
  - spec/fixtures/signatures/78f40f967bf9cb1ae030412e7c28267a8050926a538226c685fb2dec6f23b44a
127
128
  - spec/fixtures/signatures/7fe2b3662915bf82890e1fe870480885e0744b12832569c5d7017a0fc42d5527
128
129
  - spec/fixtures/signatures/8cd7ba76199d2b34be042841a2dd69310619dcac0f3dd4f24bae6b5fb5f9e302
@@ -136,6 +137,7 @@ files:
136
137
  - spec/fixtures/vcr_cassettes/Bluekai_Category/creates_a_category.yml
137
138
  - spec/fixtures/vcr_cassettes/Bluekai_Category/lists_4_categories.yml
138
139
  - spec/fixtures/vcr_cassettes/Bluekai_Category/reads_a_category_and_its_reach.yml
140
+ - spec/fixtures/vcr_cassettes/Bluekai_Category/returns_correct_category_ids.yml
139
141
  - spec/fixtures/vcr_cassettes/Bluekai_Category/updates_a_category.yml
140
142
  - spec/fixtures/vcr_cassettes/Bluekai_Client/_ping/when_we_get_a_pong_from_bluekai/.yml
141
143
  - spec/fixtures/vcr_cassettes/Bluekai_Client/lists_Bluekai_taxonomy_nodes.yml
@@ -147,6 +149,7 @@ files:
147
149
  - spec/fixtures/vcr_cassettes/Bluekai_Rule/updates_a_rule.yml
148
150
  - spec/fixtures/vcr_cassettes/Bluekai_UserData/reads_user_information_given_bkuuid.yml
149
151
  - spec/lib/bluekai/category_integration_spec.rb
152
+ - spec/lib/bluekai/category_spec.rb
150
153
  - spec/lib/bluekai/client_integration_spec.rb
151
154
  - spec/lib/bluekai/client_spec.rb
152
155
  - spec/lib/bluekai/request_spec.rb
@@ -174,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
177
  version: '0'
175
178
  requirements: []
176
179
  rubyforge_project:
177
- rubygems_version: 2.4.5
180
+ rubygems_version: 2.4.6
178
181
  signing_key:
179
182
  specification_version: 4
180
183
  summary: Simple client for the BlueKai API
@@ -184,6 +187,7 @@ test_files:
184
187
  - spec/fixtures/signatures/1a4aff70f9ce0f00680a85710f1bcf9d294239c7748dc1a23ce2bc7b3e1dca77
185
188
  - spec/fixtures/signatures/2db01e685f73149994efc9824c10fa91e704fb7256d748c4305101513444f49f
186
189
  - spec/fixtures/signatures/3c33aa44e5fbea304ffda0390ac2e413a02d187d5425f67c3edab34684b2b18f
190
+ - spec/fixtures/signatures/5d4d1a042f84b68a2fdf2cc376c8d96d284a648d003f6d917557b43372f99bba
187
191
  - spec/fixtures/signatures/78f40f967bf9cb1ae030412e7c28267a8050926a538226c685fb2dec6f23b44a
188
192
  - spec/fixtures/signatures/7fe2b3662915bf82890e1fe870480885e0744b12832569c5d7017a0fc42d5527
189
193
  - spec/fixtures/signatures/8cd7ba76199d2b34be042841a2dd69310619dcac0f3dd4f24bae6b5fb5f9e302
@@ -197,6 +201,7 @@ test_files:
197
201
  - spec/fixtures/vcr_cassettes/Bluekai_Category/creates_a_category.yml
198
202
  - spec/fixtures/vcr_cassettes/Bluekai_Category/lists_4_categories.yml
199
203
  - spec/fixtures/vcr_cassettes/Bluekai_Category/reads_a_category_and_its_reach.yml
204
+ - spec/fixtures/vcr_cassettes/Bluekai_Category/returns_correct_category_ids.yml
200
205
  - spec/fixtures/vcr_cassettes/Bluekai_Category/updates_a_category.yml
201
206
  - spec/fixtures/vcr_cassettes/Bluekai_Client/_ping/when_we_get_a_pong_from_bluekai/.yml
202
207
  - spec/fixtures/vcr_cassettes/Bluekai_Client/lists_Bluekai_taxonomy_nodes.yml
@@ -208,6 +213,7 @@ test_files:
208
213
  - spec/fixtures/vcr_cassettes/Bluekai_Rule/updates_a_rule.yml
209
214
  - spec/fixtures/vcr_cassettes/Bluekai_UserData/reads_user_information_given_bkuuid.yml
210
215
  - spec/lib/bluekai/category_integration_spec.rb
216
+ - spec/lib/bluekai/category_spec.rb
211
217
  - spec/lib/bluekai/client_integration_spec.rb
212
218
  - spec/lib/bluekai/client_spec.rb
213
219
  - spec/lib/bluekai/request_spec.rb