attune 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/attune/client.rb +18 -6
- data/lib/attune/version.rb +1 -1
- data/spec/attune/client_spec.rb +81 -56
- data/spec/remote_spec.rb +21 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cdd1d33ca1623326bd2c704e63db89f4fcd2108
|
4
|
+
data.tar.gz: 3c0959d27267e602ed662f979601d96cf0afa9f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d925942d0c3305bbdeb954f4d434f865b83930980ccd133738d67333dc7ab90e1ce075362bd29a866c5b2c20fb474fbaf21c49da4dc7a2bcf15a7a4c68c21f31
|
7
|
+
data.tar.gz: 209966761a7586eedc8234452f3fff3dac1d02928a4170d11f1ce255097ffe3a699b1fb52854956e0c4f5077cd971b3e05e92176c9022fbb5fdbfef252da9b41
|
data/README.md
CHANGED
data/lib/attune/client.rb
CHANGED
@@ -112,18 +112,24 @@ module Attune
|
|
112
112
|
# @option options [Array<String>] :entities entities to be ranked. These should be numeric strings or integers.
|
113
113
|
# @option options [String] :ip ip address of remote user. Used for geolocation (optional)
|
114
114
|
# @option options [String] :customer id of customer (optional)
|
115
|
-
# @return
|
115
|
+
# @return [Hash{Symbol => Hash, Array<String>}]
|
116
|
+
# * :headers the attune headers indicating ranking performed
|
117
|
+
# * :entities entities in their ranked order
|
116
118
|
# @raise [ArgumentError] if required parameters are missing
|
117
119
|
# @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
|
118
120
|
# @raise [AuthenticationException] if authorization header not accepted
|
119
121
|
def get_rankings(options)
|
120
122
|
qs = encoded_ranking_params(options)
|
123
|
+
rankings = {}
|
121
124
|
if response = get("rankings/#{qs}", customer: options.fetch(:customer, 'none'))
|
122
|
-
|
125
|
+
rankings[:headers] = response.headers.select { |k,v| k =~ /^attune/ }
|
126
|
+
rankings[:entities] = JSON.parse(response.body)['ranking']
|
123
127
|
else
|
124
128
|
# In mock mode: return the entities in the order passed in
|
125
|
-
|
129
|
+
rankings[:headers] = {"attune-cell"=>"mock", "attune-ranking"=>"mock"}
|
130
|
+
rankings[:entities] = options[:entities]
|
126
131
|
end
|
132
|
+
rankings
|
127
133
|
end
|
128
134
|
|
129
135
|
# Get multiple rankings in one call
|
@@ -144,29 +150,35 @@ module Attune
|
|
144
150
|
# }
|
145
151
|
# ])
|
146
152
|
# @param [Array<Hash>] multi_options An array of options (see #get_rankings)
|
147
|
-
# @return [Array<Array<String>>]
|
153
|
+
# @return [Hash{Symbol => Hash, Array<Array<String>>}]
|
154
|
+
# * :headers the attune headers indicating ranking performed
|
155
|
+
# * :entities entities in their ranked order
|
148
156
|
# @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
|
149
157
|
# @raise [AuthenticationException] if authorization header not accepted
|
150
158
|
def multi_get_rankings(multi_options)
|
151
159
|
requests = multi_options.map do |options|
|
152
160
|
encoded_ranking_params(options)
|
153
161
|
end
|
162
|
+
rankings = {}
|
154
163
|
if response = get("rankings", ids: requests)
|
155
164
|
results = JSON.parse(response.body)['results']
|
165
|
+
rankings[:headers] = response.headers.select { |k,v| k =~ /^attune/ }
|
156
166
|
|
157
167
|
# Order of encoded paramaters may change, so we must parse them
|
158
168
|
results = Hash[results.map do |request, result|
|
159
169
|
[CGI.parse(request), result]
|
160
170
|
end]
|
161
|
-
requests.map do |request|
|
171
|
+
rankings[:entities] = requests.map do |request|
|
162
172
|
results[CGI.parse(request)]['ranking']
|
163
173
|
end
|
164
174
|
else
|
165
175
|
# In mock mode: return the entities in the order passed in
|
166
|
-
|
176
|
+
rankings[:headers] = {"attune-cell"=>"mock", "attune-ranking"=>"mock"}
|
177
|
+
rankings[:entities] = multi_options.map do |options|
|
167
178
|
options[:entities]
|
168
179
|
end
|
169
180
|
end
|
181
|
+
rankings
|
170
182
|
end
|
171
183
|
|
172
184
|
# Binds an anonymous user to a customer id
|
data/lib/attune/version.rb
CHANGED
data/spec/attune/client_spec.rb
CHANGED
@@ -80,7 +80,11 @@ describe Attune::Client do
|
|
80
80
|
collection: 'products',
|
81
81
|
entities: %w[1001, 1002, 1003, 1004]
|
82
82
|
)
|
83
|
-
|
83
|
+
expected = {
|
84
|
+
headers: {"attune-cell"=>"mock", "attune-ranking"=>"mock"},
|
85
|
+
entities: %w[1001, 1002, 1003, 1004]
|
86
|
+
}
|
87
|
+
expect(result).to eq expected
|
84
88
|
end
|
85
89
|
it "mocks multi_get_rankings" do
|
86
90
|
result = client.multi_get_rankings([
|
@@ -89,7 +93,11 @@ describe Attune::Client do
|
|
89
93
|
collection: 'products',
|
90
94
|
entities: %w[1001, 1002, 1003, 1004]
|
91
95
|
])
|
92
|
-
|
96
|
+
expected = {
|
97
|
+
headers: {"attune-cell"=>"mock", "attune-ranking"=>"mock"},
|
98
|
+
entities: [%w[1001, 1002, 1003, 1004]]
|
99
|
+
}
|
100
|
+
expect(result).to eq expected
|
93
101
|
end
|
94
102
|
end
|
95
103
|
end
|
@@ -125,66 +133,83 @@ describe Attune::Client do
|
|
125
133
|
expect(id).to eq('abcd123')
|
126
134
|
end
|
127
135
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
136
|
+
describe "get_rankings" do
|
137
|
+
before(:each) do
|
138
|
+
stubs.get("rankings/anonymous=abcd123&entities=1001%2C%2C1002%2C%2C1003%2C%2C1004&entity_collection=products&ip=none&view=b%2Fmens-pants"){ [200, {"attune-ranking"=>"test", "attune-cell"=>"test"}, %[{"ranking":["1004","1003","1002","1001"]}]] }
|
139
|
+
@rankings = client.get_rankings(
|
140
|
+
id: 'abcd123',
|
141
|
+
view: 'b/mens-pants',
|
142
|
+
collection: 'products',
|
143
|
+
entities: %w[1001, 1002, 1003, 1004]
|
144
|
+
)
|
145
|
+
stubs.verify_stubbed_calls
|
146
|
+
end
|
147
|
+
|
148
|
+
it "can get ranked entities" do
|
149
|
+
expect(@rankings[:entities]).to eq(%W[1004 1003 1002 1001])
|
150
|
+
end
|
137
151
|
|
138
|
-
|
152
|
+
it "can get ranking headers" do
|
153
|
+
expect(@rankings[:headers]).to eq({"attune-ranking"=>"test", "attune-cell"=>"test"})
|
154
|
+
end
|
139
155
|
end
|
140
156
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
157
|
+
describe "multi_get_rankings" do
|
158
|
+
let(:req1){ CGI::escape 'anonymous=0cddbc0-6114-11e3-949a-0800200c9a66&view=b%2Fmens-pants&entity_collection=products&entities=1001%2C%2C1002%2C%2C1003%2C%2C1004&ip=none' }
|
159
|
+
let(:req2){ CGI::escape 'anonymous=0cddbc0-6114-11e3-949a-0800200c9a66&view=b%2Fmens-pants&entity_collection=products&entities=2001%2C%2C2002%2C%2C2003%2C%2C2004&ip=none' }
|
160
|
+
|
161
|
+
before(:each) do
|
162
|
+
stubs.get("/rankings?ids=anonymous%3D0cddbc0-6114-11e3-949a-0800200c9a66%26entities%3D1001%252C%252C1002%252C%252C1003%252C%252C1004%26entity_collection%3Dproducts%26ip%3Dnone%26view%3Db%252Fmens-pants&ids=anonymous%3D0cddbc0-6114-11e3-949a-0800200c9a66%26entities%3D2001%252C%252C2002%252C%252C2003%252C%252C2004%26entity_collection%3Dproducts%26ip%3Dnone%26view%3Db%252Fmens-pants") do
|
163
|
+
[200, {"attune-ranking"=>"test", "attune-cell"=>"test"}, <<-JSON]
|
164
|
+
{
|
165
|
+
"errors": {},
|
166
|
+
"results": {
|
167
|
+
"anonymous=0cddbc0-6114-11e3-949a-0800200c9a66&entities=1001%2C%2C1002%2C%2C1003%2C%2C1004&entity_collection=products&ip=none&view=b%2Fmens-pants": {
|
168
|
+
"ranking": [
|
169
|
+
"1004",
|
170
|
+
"1003",
|
171
|
+
"1002",
|
172
|
+
"1001"
|
173
|
+
]
|
174
|
+
},
|
175
|
+
"anonymous=0cddbc0-6114-11e3-949a-0800200c9a66&entities=2001%2C%2C2002%2C%2C2003%2C%2C2004&entity_collection=products&ip=none&view=b%2Fmens-pants": {
|
176
|
+
"ranking": [
|
177
|
+
"2004",
|
178
|
+
"2003",
|
179
|
+
"2002",
|
180
|
+
"2001"
|
181
|
+
]
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
JSON
|
186
|
+
end
|
187
|
+
@rankings = client.multi_get_rankings([
|
188
|
+
{
|
189
|
+
id: '0cddbc0-6114-11e3-949a-0800200c9a66',
|
190
|
+
view: 'b/mens-pants',
|
191
|
+
collection: 'products',
|
192
|
+
entities: %w[1001, 1002, 1003, 1004]
|
156
193
|
},
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
"2001"
|
163
|
-
]
|
194
|
+
{
|
195
|
+
id: '0cddbc0-6114-11e3-949a-0800200c9a66',
|
196
|
+
view: 'b/mens-pants',
|
197
|
+
collection: 'products',
|
198
|
+
entities: %w[2001, 2002, 2003, 2004]
|
164
199
|
}
|
165
|
-
|
166
|
-
|
167
|
-
JSON
|
200
|
+
])
|
201
|
+
stubs.verify_stubbed_calls
|
168
202
|
end
|
169
|
-
rankings = client.multi_get_rankings([
|
170
|
-
{
|
171
|
-
id: '0cddbc0-6114-11e3-949a-0800200c9a66',
|
172
|
-
view: 'b/mens-pants',
|
173
|
-
collection: 'products',
|
174
|
-
entities: %w[1001, 1002, 1003, 1004]
|
175
|
-
},
|
176
|
-
{
|
177
|
-
id: '0cddbc0-6114-11e3-949a-0800200c9a66',
|
178
|
-
view: 'b/mens-pants',
|
179
|
-
collection: 'products',
|
180
|
-
entities: %w[2001, 2002, 2003, 2004]
|
181
|
-
}
|
182
|
-
])
|
183
|
-
stubs.verify_stubbed_calls
|
184
203
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
204
|
+
it "can get ranked entities" do
|
205
|
+
expect(@rankings[:entities]).to eq [
|
206
|
+
%W[1004 1003 1002 1001],
|
207
|
+
%W[2004 2003 2002 2001]
|
208
|
+
]
|
209
|
+
end
|
210
|
+
|
211
|
+
it "can get ranking headers" do
|
212
|
+
expect(@rankings[:headers]).to eq({"attune-ranking"=>"test", "attune-cell"=>"test"})
|
213
|
+
end
|
189
214
|
end
|
190
215
|
end
|
data/spec/remote_spec.rb
CHANGED
@@ -35,24 +35,35 @@ describe "remote requests" do
|
|
35
35
|
client.bind(id, '654321')
|
36
36
|
end
|
37
37
|
|
38
|
+
let(:entities){ [202875,202876,202874,202900,202902,202898,202905,200182,200181,185940,188447,185932,190589,1238689589] }
|
38
39
|
describe "get_rankings" do
|
39
|
-
|
40
|
-
it "can get rankings" do
|
40
|
+
before(:each) do
|
41
41
|
id = client.create_anonymous(id: '123456', user_agent: 'Mozilla/5.0')
|
42
42
|
client.bind(id, '654321')
|
43
|
-
result = client.get_rankings(id: '123456', view: 'b/mens-pants', collection: 'products', entities: entities)
|
44
|
-
|
45
|
-
|
43
|
+
@result = client.get_rankings(id: '123456', view: 'b/mens-pants', collection: 'products', entities: entities)
|
44
|
+
end
|
45
|
+
it "can get ranked entities" do
|
46
|
+
@result[:entities].should be_an Array
|
47
|
+
@result[:entities].sort.should == entities.map(&:to_s).sort
|
46
48
|
end
|
49
|
+
specify { expect(@result[:headers]).to be_a Hash }
|
50
|
+
specify { expect(@result[:headers]).to have_key "attune-ranking" }
|
51
|
+
specify { expect(@result[:headers]).to have_key "attune-cell" }
|
52
|
+
end
|
47
53
|
|
48
|
-
|
54
|
+
describe "multi_get_rankings" do
|
55
|
+
before(:each) do
|
49
56
|
id = client.create_anonymous(id: '123456', user_agent: 'Mozilla/5.0')
|
50
57
|
client.bind(id, '654321')
|
51
|
-
results = client.multi_get_rankings([id: '123456', view: 'b/mens-pants', collection: 'products', entities: entities])
|
52
|
-
|
53
|
-
|
54
|
-
|
58
|
+
@results = client.multi_get_rankings([id: '123456', view: 'b/mens-pants', collection: 'products', entities: entities])
|
59
|
+
end
|
60
|
+
it "can batch get rankings" do
|
61
|
+
@results[:entities].should be_an Array
|
62
|
+
result, = *@results[:entities]
|
55
63
|
result.sort.should == entities.map(&:to_s).sort
|
56
64
|
end
|
65
|
+
specify { expect(@results[:headers]).to be_a Hash }
|
66
|
+
specify { expect(@results[:headers]).to have_key "attune-ranking" }
|
67
|
+
specify { expect(@results[:headers]).to have_key "attune-cell" }
|
57
68
|
end
|
58
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|