bluekai 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/bluekai/category.rb +145 -0
- data/lib/bluekai/client.rb +20 -321
- data/lib/bluekai/rule.rb +165 -0
- data/lib/bluekai/user_data.rb +90 -0
- data/lib/bluekai/version.rb +1 -1
- data/lib/bluekai.rb +3 -0
- data/spec/fixtures/signatures/0e01a80ff1ca77f4fd32b58ff48310168539a9a26e4ef527042b7bab78d4648a +1 -0
- data/spec/fixtures/signatures/7fe2b3662915bf82890e1fe870480885e0744b12832569c5d7017a0fc42d5527 +1 -0
- data/spec/fixtures/signatures/8cd7ba76199d2b34be042841a2dd69310619dcac0f3dd4f24bae6b5fb5f9e302 +1 -0
- data/spec/fixtures/signatures/95768bffa5416007061da13a2a0368e52a4bea3451ac2dfede43f6a6841ac402 +1 -0
- data/spec/fixtures/vcr_cassettes/{Bluekai_Client → Bluekai_Category}/creates_a_category.yml +10 -10
- data/spec/fixtures/vcr_cassettes/Bluekai_Category/lists_4_categories.yml +104 -0
- data/spec/fixtures/vcr_cassettes/{Bluekai_Client → Bluekai_Category}/reads_a_category_and_its_reach.yml +1616 -1610
- data/spec/fixtures/vcr_cassettes/{Bluekai_Client → Bluekai_Category}/updates_a_category.yml +9 -9
- data/spec/fixtures/vcr_cassettes/Bluekai_Client/lists_Bluekai_taxonomy_nodes.yml +28225 -27370
- data/spec/fixtures/vcr_cassettes/Bluekai_Client/performs_a_ping.yml +4 -4
- data/spec/fixtures/vcr_cassettes/{Bluekai_Client → Bluekai_Rule}/creates_a_rule.yml +11 -11
- data/spec/fixtures/vcr_cassettes/Bluekai_Rule/lists_10_phint_rules.yml +234 -0
- data/spec/fixtures/vcr_cassettes/{Bluekai_Client → Bluekai_Rule}/reads_a_rule.yml +12 -10
- data/spec/fixtures/vcr_cassettes/{Bluekai_Client → Bluekai_Rule}/updates_a_rule.yml +7 -7
- data/spec/fixtures/vcr_cassettes/Bluekai_UserData/reads_user_information_given_bkuuid.yml +44 -0
- data/spec/lib/bluekai/category_integration_spec.rb +56 -0
- data/spec/lib/bluekai/client_integration_spec.rb +1 -141
- data/spec/lib/bluekai/client_spec.rb +0 -3
- data/spec/lib/bluekai/rule_integration_spec.rb +73 -0
- data/spec/lib/bluekai/user_data_integration_spec.rb +12 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/support/signature_mock.rb +13 -0
- metadata +40 -19
- data/spec/fixtures/vcr_cassettes/Bluekai_Client/lists_10_phint_rules.yml +0 -194
- data/spec/fixtures/vcr_cassettes/Bluekai_Client/lists_4_categories.yml +0 -3569
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 884b8ab4ddf4ef8a43bc1db28ac1debe3aef971e
|
4
|
+
data.tar.gz: bdf076635dca5a8abdba847babceba50a8ad7b35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 664d9bbe62982c47ceffaa5eca7016af38419aadbf8eba0c6266c9c72c9bc769c1239dc48932d8730365fc358b131367278435a1475756239ac8f4cafe477ecb
|
7
|
+
data.tar.gz: a181f51512a3366464432d75d51753cb5a476a66ac4ac82e17a437236c085371100d39de25432def24c9d99c7f694b66bd6abec072a1d57e6422d5ecc4fd2da6
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.1
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module Bluekai
|
2
|
+
class Category < Client
|
3
|
+
####
|
4
|
+
#### Categories
|
5
|
+
####
|
6
|
+
#### API definition can be found here
|
7
|
+
#### https://kb.bluekai.com/display/PD/Self-Classification+Category+API
|
8
|
+
####
|
9
|
+
|
10
|
+
# Public: Lists self classification categories in private taxonomy
|
11
|
+
#
|
12
|
+
# name:string - Returns all self-classification categories based on the specified
|
13
|
+
# name (whole or partial). The name is case-insensitive.
|
14
|
+
#
|
15
|
+
# offset:integer - Specify the starting index from which to return
|
16
|
+
# the self-classification categories.
|
17
|
+
#
|
18
|
+
# size:integer - Specifies the maximum number of categories to be included in
|
19
|
+
# the response. This filter requires the offset filter to be specified.
|
20
|
+
#
|
21
|
+
# parent_id:integer - Returns all self-classification categories
|
22
|
+
# based on the ID of the specified parent category.
|
23
|
+
#
|
24
|
+
# sort_by:string - Enter 'name' or 'id' to sort the returned self-classification categories in
|
25
|
+
# alphabetical or numerical order (based on categoryId)
|
26
|
+
#
|
27
|
+
# sorting_order:string - Enter 'asc' or 'desc' to list the returned
|
28
|
+
# self-classification categories in ascending
|
29
|
+
# or descending order based on the category
|
30
|
+
# name or categoryId.
|
31
|
+
#
|
32
|
+
# Returns array of category hashes
|
33
|
+
def category_list(query = {})
|
34
|
+
query = { sort_by: 'name',
|
35
|
+
sorting_order: 'asc' }.merge(query)
|
36
|
+
request('GET', '/Services/WS/classificationCategories', query)[:categories]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: returns the self-classification category
|
40
|
+
# specified by the category_id
|
41
|
+
#
|
42
|
+
# category_id:integer - MANDATORY The unique ID assigned to the
|
43
|
+
# self-classification category to be retrieved
|
44
|
+
#
|
45
|
+
# stats:string - {'True','False'} Returns the reach (estimated
|
46
|
+
# number of unique users based on 30-day
|
47
|
+
# inventory) for the self-classification category.
|
48
|
+
#
|
49
|
+
# device_type:string - reach for the self-classification category
|
50
|
+
# based on the specified device, which may either
|
51
|
+
# be 'all', 'desktop', or 'mobile'
|
52
|
+
#
|
53
|
+
# intl_code - returns the reach for the self-classification category
|
54
|
+
# based on the specified country. The default country
|
55
|
+
# is ALL. You may enter one of the following country
|
56
|
+
# codes: ALL, US, AU, CA, GB, GER, ESP, NL, MX, IT,
|
57
|
+
# FR, BR, AR, RU, NZ, JP, CL, CN.
|
58
|
+
#
|
59
|
+
# Returns: A hash of Bluekai private category data
|
60
|
+
def category_read(query)
|
61
|
+
fail 'no category_id found in hash' unless query.key?(:category_id)
|
62
|
+
category_id = query.delete(:category_id)
|
63
|
+
request('GET', "/Services/WS/classificationCategories/#{category_id}", query)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Public: Creates a new self-classification category
|
67
|
+
#
|
68
|
+
# name:string - Name of the self-classification category
|
69
|
+
#
|
70
|
+
# parent_id:integer - Unique ID of the parent node for the
|
71
|
+
# self-classification category.
|
72
|
+
#
|
73
|
+
# description:string - Description of uUser attribute
|
74
|
+
# represented by this category.
|
75
|
+
#
|
76
|
+
# analytics_excluded:string - {'True','False'} Specify whether the
|
77
|
+
# self-classification category is to be excluded
|
78
|
+
# from Audience Analytics reports. This property
|
79
|
+
# is false by default.
|
80
|
+
#
|
81
|
+
# navigation_only:string - {'True','False'} Specify whether the
|
82
|
+
# self-classification category functions
|
83
|
+
# exclusively as a parent node that cannot be
|
84
|
+
# selected. This property is false by default.
|
85
|
+
#
|
86
|
+
# mutex_children:string - {'True','False'} Specify whether to limit
|
87
|
+
# the number of the category's child nodes
|
88
|
+
# that can be added to an audience segment to one.
|
89
|
+
# This property is false by default.
|
90
|
+
#
|
91
|
+
# notes:string - (Optional) Enter any notes to be associated with
|
92
|
+
# this self-classification category.
|
93
|
+
#
|
94
|
+
# Example body hash = {name: 'a new category',
|
95
|
+
# parent_id: '2342', description: 'an example category',
|
96
|
+
# analytics_excluded: 'false', navigation_only: 'false',
|
97
|
+
# mutex_children: 'false', notes: 'Just an API test' }
|
98
|
+
#
|
99
|
+
# Returns: hash of created category parameters including its category_id
|
100
|
+
def category_create(body)
|
101
|
+
request('POST', '/Services/WS/classificationCategories', {}, body)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Public: Updates a given self-classification category
|
105
|
+
#
|
106
|
+
# category_id:integer - The unique ID assigned to the self-classification
|
107
|
+
# category to be updated
|
108
|
+
#
|
109
|
+
# name:string - Name of the self-classification category
|
110
|
+
#
|
111
|
+
# parent_id:integer - Unique ID of the parent node for the
|
112
|
+
# self-classification category.
|
113
|
+
#
|
114
|
+
# description:string - Description of uUser attribute
|
115
|
+
# represented by this category.
|
116
|
+
#
|
117
|
+
# analytics_excluded:string - {'True','False'} Specify whether the
|
118
|
+
# self-classification category is to be excluded
|
119
|
+
# from Audience Analytics reports. This property
|
120
|
+
# is false by default.
|
121
|
+
#
|
122
|
+
# navigation_only:string - {'True','False'} Specify whether the
|
123
|
+
# self-classification category functions
|
124
|
+
# exclusively as a parent node that cannot be
|
125
|
+
# selected. This property is false by default.
|
126
|
+
#
|
127
|
+
# mutex_children:string - {'True','False'} Specify whether to limit
|
128
|
+
# the number of the category's child nodes
|
129
|
+
# that can be added to an audience segment to one.
|
130
|
+
# This property is false by default.
|
131
|
+
#
|
132
|
+
# notes:string - (Optional) Enter any notes to be associated with
|
133
|
+
# this self-classification category.
|
134
|
+
#
|
135
|
+
# Example body hash = {category_id: 1234, name: 'a chaged category',
|
136
|
+
# parent_id: '2342', description: 'an example category',
|
137
|
+
# analytics_exclued: 'false', navigation_only: 'false',
|
138
|
+
# mutex_children: 'false', notes: 'Just an API test' }
|
139
|
+
#
|
140
|
+
# Returns: hash of updated category parameters
|
141
|
+
def category_update(category_id, body)
|
142
|
+
request('PUT', "/Services/WS/classificationCategories/#{category_id}", {}, body)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/lib/bluekai/client.rb
CHANGED
@@ -9,8 +9,6 @@ module Bluekai
|
|
9
9
|
attr_reader :domain, :api_user_key
|
10
10
|
|
11
11
|
def initialize(opts = {})
|
12
|
-
@domain = opts.fetch(:domain, ENV['BLUEKAI_DOMAIN']) ||
|
13
|
-
fail(Error, 'BlueKai domain missing')
|
14
12
|
@api_user_key = opts.fetch(:api_user_key, ENV['BLUEKAI_API_USER_KEY']) ||
|
15
13
|
fail(Error, 'BlueKai API user key missing')
|
16
14
|
@api_private_key = opts.fetch(:api_private_key, ENV['BLUEKAI_API_PRIVATE_KEY']) ||
|
@@ -46,337 +44,38 @@ module Bluekai
|
|
46
44
|
request('GET', '/Services/WS/Taxonomy', query)[:nodeList]
|
47
45
|
end
|
48
46
|
|
49
|
-
####
|
50
|
-
#### Categories
|
51
|
-
####
|
52
|
-
#### API definition can be found here
|
53
|
-
#### https://kb.bluekai.com/display/PD/Self-Classification+Category+API
|
54
|
-
####
|
55
|
-
|
56
|
-
# Public: Lists self classification categories in private taxonomy
|
57
|
-
#
|
58
|
-
# name:string - Returns all self-classification categories based on the specified
|
59
|
-
# name (whole or partial). The name is case-insensitive.
|
60
|
-
#
|
61
|
-
# offset:integer - Specify the starting index from which to return
|
62
|
-
# the self-classification categories.
|
63
|
-
#
|
64
|
-
# size:integer - Specifies the maximum number of categories to be included in
|
65
|
-
# the response. This filter requires the offset filter to be specified.
|
66
|
-
#
|
67
|
-
# parent_id:integer - Returns all self-classification categories
|
68
|
-
# based on the ID of the specified parent category.
|
69
|
-
#
|
70
|
-
# sort_by:string - Enter 'name' or 'id' to sort the returned self-classification categories in
|
71
|
-
# alphabetical or numerical order (based on categoryId)
|
72
|
-
#
|
73
|
-
# sorting_order:string - Enter 'asc' or 'desc' to list the returned
|
74
|
-
# self-classification categories in ascending
|
75
|
-
# or descending order based on the category
|
76
|
-
# name or categoryId.
|
77
|
-
#
|
78
|
-
# Returns array of category hashes
|
79
|
-
def category_list(query = {})
|
80
|
-
query = { sort_by: 'name',
|
81
|
-
sorting_order: 'asc' }.merge(query)
|
82
|
-
request('GET', '/Services/WS/classificationCategories', query)[:categories]
|
83
|
-
end
|
84
|
-
|
85
|
-
# Public: returns the self-classification category
|
86
|
-
# specified by the category_id
|
87
|
-
#
|
88
|
-
# category_id:integer - MANDATORY The unique ID assigned to the
|
89
|
-
# self-classification category to be retrieved
|
90
|
-
#
|
91
|
-
# stats:string - {'True','False'} Returns the reach (estimated
|
92
|
-
# number of unique users based on 30-day
|
93
|
-
# inventory) for the self-classification category.
|
94
|
-
#
|
95
|
-
# device_type:string - reach for the self-classification category
|
96
|
-
# based on the specified device, which may either
|
97
|
-
# be 'all', 'desktop', or 'mobile'
|
98
|
-
#
|
99
|
-
# intl_code - returns the reach for the self-classification category
|
100
|
-
# based on the specified country. The default country
|
101
|
-
# is ALL. You may enter one of the following country
|
102
|
-
# codes: ALL, US, AU, CA, GB, GER, ESP, NL, MX, IT,
|
103
|
-
# FR, BR, AR, RU, NZ, JP, CL, CN.
|
104
|
-
#
|
105
|
-
# Returns: A hash of Bluekai private category data
|
106
|
-
def category_read(query)
|
107
|
-
fail 'no category_id found in hash' unless query.key?(:category_id)
|
108
|
-
category_id = query.delete(:category_id)
|
109
|
-
request('GET', "/Services/WS/classificationCategories/#{category_id}", query)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Public: Creates a new self-classification category
|
113
|
-
#
|
114
|
-
# name:string - Name of the self-classification category
|
115
|
-
#
|
116
|
-
# parent_id:integer - Unique ID of the parent node for the
|
117
|
-
# self-classification category.
|
118
|
-
#
|
119
|
-
# description:string - Description of uUser attribute
|
120
|
-
# represented by this category.
|
121
|
-
#
|
122
|
-
# analytics_excluded:string - {'True','False'} Specify whether the
|
123
|
-
# self-classification category is to be excluded
|
124
|
-
# from Audience Analytics reports. This property
|
125
|
-
# is false by default.
|
126
|
-
#
|
127
|
-
# navigation_only:string - {'True','False'} Specify whether the
|
128
|
-
# self-classification category functions
|
129
|
-
# exclusively as a parent node that cannot be
|
130
|
-
# selected. This property is false by default.
|
131
|
-
#
|
132
|
-
# mutex_children:string - {'True','False'} Specify whether to limit
|
133
|
-
# the number of the category's child nodes
|
134
|
-
# that can be added to an audience segment to one.
|
135
|
-
# This property is false by default.
|
136
|
-
#
|
137
|
-
# notes:string - (Optional) Enter any notes to be associated with
|
138
|
-
# this self-classification category.
|
139
|
-
#
|
140
|
-
# Example body hash = {name: 'a new category',
|
141
|
-
# parent_id: '2342', description: 'an example category',
|
142
|
-
# analytics_excluded: 'false', navigation_only: 'false',
|
143
|
-
# mutex_children: 'false', notes: 'Just an API test' }
|
144
|
-
#
|
145
|
-
# Returns: hash of created category parameters including its category_id
|
146
|
-
def category_create(body)
|
147
|
-
request('POST', '/Services/WS/classificationCategories', {}, body)
|
148
|
-
end
|
149
|
-
|
150
|
-
# Public: Updates a given self-classification category
|
151
|
-
#
|
152
|
-
# category_id:integer - The unique ID assigned to the self-classification
|
153
|
-
# category to be updated
|
154
|
-
#
|
155
|
-
# name:string - Name of the self-classification category
|
156
|
-
#
|
157
|
-
# parent_id:integer - Unique ID of the parent node for the
|
158
|
-
# self-classification category.
|
159
|
-
#
|
160
|
-
# description:string - Description of uUser attribute
|
161
|
-
# represented by this category.
|
162
|
-
#
|
163
|
-
# analytics_excluded:string - {'True','False'} Specify whether the
|
164
|
-
# self-classification category is to be excluded
|
165
|
-
# from Audience Analytics reports. This property
|
166
|
-
# is false by default.
|
167
|
-
#
|
168
|
-
# navigation_only:string - {'True','False'} Specify whether the
|
169
|
-
# self-classification category functions
|
170
|
-
# exclusively as a parent node that cannot be
|
171
|
-
# selected. This property is false by default.
|
172
|
-
#
|
173
|
-
# mutex_children:string - {'True','False'} Specify whether to limit
|
174
|
-
# the number of the category's child nodes
|
175
|
-
# that can be added to an audience segment to one.
|
176
|
-
# This property is false by default.
|
177
|
-
#
|
178
|
-
# notes:string - (Optional) Enter any notes to be associated with
|
179
|
-
# this self-classification category.
|
180
|
-
#
|
181
|
-
# Example body hash = {category_id: 1234, name: 'a chaged category',
|
182
|
-
# parent_id: '2342', description: 'an example category',
|
183
|
-
# analytics_exclued: 'false', navigation_only: 'false',
|
184
|
-
# mutex_children: 'false', notes: 'Just an API test' }
|
185
|
-
#
|
186
|
-
# Returns: hash of updated category parameters
|
187
|
-
def category_update(category_id, body)
|
188
|
-
request('PUT', "/Services/WS/classificationCategories/#{category_id}", {}, body)
|
189
|
-
end
|
190
|
-
|
191
|
-
####
|
192
|
-
#### Classification Rules
|
193
|
-
#### API definition can be found here
|
194
|
-
#### https://kb.bluekai.com/display/PD/Self-Classification+Rule+API
|
195
|
-
####
|
196
|
-
|
197
|
-
# Public: List the self-classification rules in your private
|
198
|
-
# taxonomy
|
199
|
-
#
|
200
|
-
# sort_by:string - Enter 'status', 'id', 'created_at', 'updated_at',
|
201
|
-
# or 'type' to sort the returned self-classification
|
202
|
-
# rules by the specified option.
|
203
|
-
#
|
204
|
-
# sorting_order:string - Enter 'asc' or 'desc' to list the returned
|
205
|
-
# self-classification rules in ascending or descending
|
206
|
-
# order based on the specified sort option.
|
207
|
-
#
|
208
|
-
# ids:integer - Returns the self-classification rule matching the specified
|
209
|
-
# rule ID, or returns all the self-classification rules matching
|
210
|
-
# the specified list of rule IDs. Syntax for passing multiple rule IDs:
|
211
|
-
# ruleId1&id=ruleId2 Example: 123&id=125
|
212
|
-
#
|
213
|
-
# type:enum - Enter 'phint' or 'url' to return only the phint or
|
214
|
-
# URL-based self-classification rules.
|
215
|
-
#
|
216
|
-
# site_ids:string - Returns all the self-classification rules under the
|
217
|
-
# specified site ID or list of site IDs. Syntax for
|
218
|
-
# passing multiple site IDs: site_id_1&site_ids=site_id_2
|
219
|
-
# Example: 1234&site_ids=1235
|
220
|
-
#
|
221
|
-
# category_ids:string - Returns all the self-classification rules used
|
222
|
-
# to map the specified catgeory ID or list of category IDs.
|
223
|
-
# Syntax for passing multiple category
|
224
|
-
# IDs: category_id_1&category_ids=category_id_2
|
225
|
-
# Example: 1234&category_ids=1235
|
226
|
-
#
|
227
|
-
# offset:integer - Specify the starting index from which to return the
|
228
|
-
# self-classification rules.
|
229
|
-
#
|
230
|
-
# size:integer - Specify the maximum number of rules to be included in
|
231
|
-
# the response. This filter requires the offset filter
|
232
|
-
# to be specified.
|
233
|
-
#
|
234
|
-
# created_date_range:string - Returns all the self-classification rules
|
235
|
-
# created within the specified list of dates.
|
236
|
-
# Syntax: YYYY-MM-DD&created_date_range=YYYY-MM-DD
|
237
|
-
# Example: 2014-01-01&created_date_range=2014-31-01
|
238
|
-
#
|
239
|
-
# updated_date_range:string - Returns all the self-classification rules updated
|
240
|
-
# within the specified list of dates.
|
241
|
-
# Syntax: YYYY-MM-DD&updated_date_range=YYYY-MM-DD
|
242
|
-
# Example: 2014-01-01&updated_date_range=2014-31-01
|
243
|
-
#
|
244
|
-
# status:string - Enter 'Active' or 'Creating' to return the
|
245
|
-
# self-classification rules based on the specified status referrer
|
246
|
-
# boolean Returns all URL-based self-classification rules that
|
247
|
-
# classify the site URL (False) or the referrer URL (True) in
|
248
|
-
# the collected URL.
|
249
|
-
#
|
250
|
-
# exact:boolean - Returns all URL-based self-classification rules that classify
|
251
|
-
# an exact URL (True) or a top-level URL (False) in the collected URL.
|
252
|
-
# Returns: hash of Bluekai rules
|
253
|
-
def rule_list(query)
|
254
|
-
request('GET', '/Services/WS/classificationRules', query)[:rules]
|
255
|
-
end
|
256
|
-
|
257
|
-
# Public: Reads a self-classification rule
|
258
|
-
#
|
259
|
-
# rule_id:integer - The unique ID assigned to the
|
260
|
-
# self-classification rule to be retrieved
|
261
|
-
#
|
262
|
-
# Returns: hash of Blukkai rule parameters
|
263
|
-
def rule_read(rule_id)
|
264
|
-
request('GET', "/Services/WS/classificationRules/#{rule_id}", {})
|
265
|
-
end
|
266
|
-
|
267
|
-
# Public: Creates a new self-classification rule
|
268
|
-
#
|
269
|
-
# name:string - Enter a string specifying the name of the self-classification rule.
|
270
|
-
#
|
271
|
-
# type:string - {'phint', 'url'} Specify the type of classification rule.
|
272
|
-
#
|
273
|
-
# phints:[{phint}] - If you are creating a phint-based rule,
|
274
|
-
# enter a list of your phint definitions.
|
275
|
-
# Each phint requires the following properties:
|
276
|
-
# key - The phint key operator - The criteria
|
277
|
-
# used for determining how the phint value
|
278
|
-
# is applied ('is' or 'contains')
|
279
|
-
# value - The full or partial phint value,
|
280
|
-
# depending on the specified operator.
|
281
|
-
#
|
282
|
-
# urls:[string(s)] - Provide a list of your URL definitions
|
283
|
-
# if you are creating for URL-based rules.
|
284
|
-
#
|
285
|
-
# referrer:string - {'True','False'} If you are creating a
|
286
|
-
# URL-based rule, specify whether the URL to
|
287
|
-
# be classified is the site URL (False) or
|
288
|
-
# the referrer URL (True).
|
289
|
-
#
|
290
|
-
# exact:string - {'True','False'} If you are creating a
|
291
|
-
# URL-based rule, specify whether the URL collected
|
292
|
-
# from your site must match the URL in your
|
293
|
-
# rule (True) or match a top-level URL (False) so
|
294
|
-
# that you can target users visiting the child pages
|
295
|
-
# without specifying them.
|
296
|
-
#
|
297
|
-
# partner_id:integer - Enter the unique ID assigned to your BlueKai DMP seat.
|
298
|
-
#
|
299
|
-
# site_ids (optional):[interger(s)] - Enter a list of containers/site IDs to which
|
300
|
-
# the self-classification rule applies. If
|
301
|
-
# you do not include this parameter, the
|
302
|
-
# rule is applicable to ALL the
|
303
|
-
# container/site IDs in your seat.
|
304
|
-
#
|
305
|
-
# category_ids:[integer(s)] - a list of category IDs to which
|
306
|
-
# the self-classification rule applies.
|
307
|
-
#
|
308
|
-
# JSON example for Phint-based self-classification rule
|
309
|
-
# {
|
310
|
-
# "name": "Phint Example",
|
311
|
-
# "type": "phint",
|
312
|
-
# "phints": [
|
313
|
-
# {
|
314
|
-
# "key": "x",
|
315
|
-
# "value": "123",
|
316
|
-
# "operator": "is"
|
317
|
-
# }
|
318
|
-
# ],
|
319
|
-
# "partner_id": 123,
|
320
|
-
# "site_ids": [1234],
|
321
|
-
# "category_ids": [12345]
|
322
|
-
# }
|
323
|
-
#
|
324
|
-
# JSON example for URL-based self-classiifcation rule
|
325
|
-
# {
|
326
|
-
# "name": "URL Example",
|
327
|
-
# "type": "url",
|
328
|
-
# "urls": ["http://shop.yoursite.com"],
|
329
|
-
# "referrer": false,
|
330
|
-
# "exact": false,
|
331
|
-
# "partner_id": 123,
|
332
|
-
# "site_ids": [1234],
|
333
|
-
# "category_ids": [123456]
|
334
|
-
# }
|
335
|
-
# Returns: hash of created self-classification rule
|
336
|
-
def rule_create(body)
|
337
|
-
body = { partner_id: @partner_id }.merge(body)
|
338
|
-
request('POST', '/Services/WS/classificationRules', {}, body)
|
339
|
-
end
|
340
|
-
|
341
|
-
# Public: Update a self-classification rule
|
342
|
-
#
|
343
|
-
# rule_id:integer (MANDATORY) - id of classification rule to be updated
|
344
|
-
#
|
345
|
-
# for other parameters refer to documentation of rule_create(body)
|
346
|
-
#
|
347
|
-
# Returns: hash of updated self-classification rule
|
348
|
-
def rule_update(rule_id, body)
|
349
|
-
body = { partner_id: @partner_id }.merge(body)
|
350
|
-
request('PUT', "/Services/WS/classificationRules/#{rule_id}", {}, body)
|
351
|
-
end
|
352
|
-
|
353
47
|
private
|
354
48
|
|
355
49
|
def request(method, path, query, body = nil)
|
356
50
|
method.upcase!
|
357
51
|
signature = sign(method, path, query_values(query), body_sorted(body))
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
52
|
+
url = "#{domain}#{path}?#{query_url_formatted(query)}"\
|
53
|
+
"bkuid=#{api_user_key}&bksig=#{signature}"
|
54
|
+
|
55
|
+
response =
|
56
|
+
case method
|
57
|
+
when 'GET'
|
58
|
+
HTTParty.get(url)
|
59
|
+
when 'POST'
|
60
|
+
HTTParty.post(url, body: body_sorted(body), headers: json_headers)
|
61
|
+
when 'PUT'
|
62
|
+
HTTParty.put(url, body: body_sorted(body), headers: json_headers)
|
63
|
+
else
|
64
|
+
fail ArgumentError, "request method '#{method}' not supported"
|
65
|
+
end.response
|
66
|
+
|
372
67
|
fail "HTTP Request Error: #{response.body}" if response.code != '200'
|
373
68
|
return response.code if response.body == '' || response.body.nil?
|
374
69
|
JSON.parse(response.body, symbolize_names: true)
|
375
70
|
end
|
376
71
|
|
72
|
+
def domain
|
73
|
+
'https://services.bluekai.com'
|
74
|
+
end
|
75
|
+
|
377
76
|
def body_sorted(body)
|
378
77
|
# sort hash according to keys for correct signature computation
|
379
|
-
|
78
|
+
body.sort_by { |key, _value| key.to_s }.to_h.to_json if body
|
380
79
|
end
|
381
80
|
|
382
81
|
def json_headers
|