attune 0.0.2 → 0.0.3

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: a768188791c5cf1b4dbb0d9bb7639c79be622f49
4
- data.tar.gz: 0b55667d588255b97df0fc7fbc7d7571f2a3a420
3
+ metadata.gz: 71b45b8b01601ab2b240d6c5243a39c0991a23d9
4
+ data.tar.gz: fd29c20cac7f27e6cb3aa00f9a6c8ec4c54070a9
5
5
  SHA512:
6
- metadata.gz: a90ccfd4d4aa1893c315e161545a3bd04cdddcdaabdc98f7e4daf809a7a8acbefd3e15d03344fd933ae83e290b7ff3f4bdd2c15b0180565d4b00597c4c7d9e74
7
- data.tar.gz: 1686b9cfa601e45f89590446c8c69a65f9c6f80b775f4031056fc6f9438c790514f836d7f00622ce31b0562d92e62c643aa19da5a53491c92d08cb2289be1ec8
6
+ metadata.gz: 830ae6660ed070894351cb69c13da91827fbb9abaa43a79377e527d1f8d339be1c6c20391280f4b9a315363c8cb7d24f344e6e9ccc0ba166d327651cbe9549f5
7
+ data.tar.gz: b7dd011b6e0003d0fa5d7e7a69cb53666dd3773e1cd50de389e870bb928ba75d9a1e4506d73b4af124d37a8eeac464a1b14cf66bf7473241fe7bbc618201844b
data/README.md CHANGED
@@ -64,7 +64,7 @@ class ProductsController
64
64
 
65
65
  private
66
66
  def sorted products
67
- ranking = attune_client.get_ranking(
67
+ ranking = attune_client.get_rankings(
68
68
  id: session[:attune_id],
69
69
  view: request.fullpath,
70
70
  collection: 'products',
data/lib/attune/client.rb CHANGED
@@ -42,7 +42,7 @@ module Attune
42
42
  # @option options [String] :user_agent The user agent for the application used by the anonymous users
43
43
  # @return id [String]
44
44
  # @raise [ArgumentError] if user_agent is not provided
45
- # @raise [Faraday::Error] if the request fails or exceeds the timeout
45
+ # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
46
46
  def create_anonymous(options)
47
47
  raise ArgumentError, "user_agent required" unless options[:user_agent]
48
48
  if id = options[:id]
@@ -76,7 +76,7 @@ module Attune
76
76
  # @option options [String] :customer id of customer (optional)
77
77
  # @return ranking [Array<String>] The entities in their ranked order
78
78
  # @raise [ArgumentError] if required parameters are missing
79
- # @raise [Faraday::Error] if the request fails or exceeds the timeout
79
+ # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
80
80
  def get_rankings(options)
81
81
  qs = encoded_ranking_params(options)
82
82
  if response = get("rankings/#{qs}", customer: options.fetch(:customer, 'none'))
@@ -90,7 +90,7 @@ module Attune
90
90
  # Get multiple rankings in one call
91
91
  #
92
92
  # @example
93
- # rankings = client.get_rankings([
93
+ # rankings = client.multi_get_rankings([
94
94
  # {
95
95
  # id: '0cddbc0-6114-11e3-949a-0800200c9a66',
96
96
  # view: 'b/mens-pants',
@@ -106,15 +106,20 @@ module Attune
106
106
  # ])
107
107
  # @param [Array<Hash>] multi_options An array of options (see #get_rankings)
108
108
  # @return [Array<Array<String>>] rankings
109
- # @raise [Faraday::Error] if the request fails or exceeds the timeout
109
+ # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
110
110
  def multi_get_rankings(multi_options)
111
111
  requests = multi_options.map do |options|
112
112
  encoded_ranking_params(options)
113
113
  end
114
114
  if response = get("rankings", ids: requests)
115
115
  results = JSON.parse(response.body)['results']
116
- results.values.map do |result|
117
- result['ranking']
116
+
117
+ # Order of encoded paramaters may change, so we must parse them
118
+ results = Hash[results.map do |request, result|
119
+ [CGI.parse(request), result]
120
+ end]
121
+ requests.map do |request|
122
+ results[CGI.parse(request)]['ranking']
118
123
  end
119
124
  else
120
125
  # In mock mode: return the entities in the order passed in
@@ -133,7 +138,7 @@ module Attune
133
138
  # '25892e17-80f6-415f-9c65-7395632f022',
134
139
  # 'cd171f7c-560d-4a62-8d65-16b87419a58'
135
140
  # )
136
- # @raise [Faraday::Error] if the request fails or exceeds the timeout
141
+ # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
137
142
  def bind(id, customer_id)
138
143
  put("bindings/anonymous=#{id}&customer=#{customer_id}")
139
144
  true
@@ -1,3 +1,3 @@
1
1
  module Attune
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -116,9 +116,33 @@ describe Attune::Client do
116
116
  expect(rankings).to eq(%W[1004 1003 1002 1001])
117
117
  end
118
118
 
119
+ 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' }
120
+ 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' }
119
121
  it "can multi_get_rankings" do
120
122
  stubs.get("/rankings?ids=anonymous%3D0cddbc0-6114-11e3-949a-0800200c9a66%26view%3Db%252Fmens-pants%26entity_collection%3Dproducts%26entities%3D1001%252C%252C1002%252C%252C1003%252C%252C1004%26ip%3Dnone&ids=anonymous%3D0cddbc0-6114-11e3-949a-0800200c9a66%26view%3Db%252Fmens-pants%26entity_collection%3Dproducts%26entities%3D2001%252C%252C2002%252C%252C2003%252C%252C2004%26ip%3Dnone") do
121
- [200, {}, %[{"results":{"fake0":{"ranking":["1004","1003","1002","1001"]},"fake1":{"ranking":["2004","2003","2002","2001"]}}}]]
123
+ [200, {}, <<-JSON]
124
+ {
125
+ "errors": {},
126
+ "results": {
127
+ "anonymous=0cddbc0-6114-11e3-949a-0800200c9a66&entities=1001%2C%2C1002%2C%2C1003%2C%2C1004&entity_collection=products&ip=none&view=b%2Fmens-pants": {
128
+ "ranking": [
129
+ "1004",
130
+ "1003",
131
+ "1002",
132
+ "1001"
133
+ ]
134
+ },
135
+ "anonymous=0cddbc0-6114-11e3-949a-0800200c9a66&entities=2001%2C%2C2002%2C%2C2003%2C%2C2004&entity_collection=products&ip=none&view=b%2Fmens-pants": {
136
+ "ranking": [
137
+ "2004",
138
+ "2003",
139
+ "2002",
140
+ "2001"
141
+ ]
142
+ }
143
+ }
144
+ }
145
+ JSON
122
146
  end
123
147
  rankings = client.multi_get_rankings([
124
148
  {
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-31 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday