attune 1.0.5 → 1.0.6

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb1defe49351ac0ececcbee2e6234ecd06dd923e
4
- data.tar.gz: f5d0b12d7b5f6514847b2de1bcd07977b1b6acfb
3
+ metadata.gz: f989d86ece4bbcff8762dbfc11c3879e7b057913
4
+ data.tar.gz: ef029ed4b38d4d0ed4a8dc072646bcf37e474a1e
5
5
  SHA512:
6
- metadata.gz: 0251f285edcf9c2e759928f87ac2407e2e6cd274ee71bceda05b959a87a64eb26a7eadce39744fc5fc8c0c60d654d2b4cae3a1d222d8bffcc7e514cde8afb79c
7
- data.tar.gz: 07d2c0d9cae0cecf2158438e9597832c0fcad15f9e1f455cefde22bde4f2dbf81aa73d14d4f32c4f40cce1ab119f5897a8d9950e7f0c17126f7ee218f1492e36
6
+ metadata.gz: 6f00289644fedfcb042e5cc19a2001d60707f22c2ea0548e4a38a00133ca0f756a865b2b1105c18078618398bbca32ca48f374d1a83a34c391d9f829e41e5672
7
+ data.tar.gz: fbda6bd0e3aa269e23bdbcda5419f6c9292f96d418da688bec8155d8e0d9013f0586097443402bbb37896b9dfb294ea65d65eefcb3ac81f93aae2e9f1adfdaae
data/README.md CHANGED
@@ -31,7 +31,7 @@ Visitors to the application should be tagged with an anonymous user id
31
31
  ``` ruby
32
32
  class ApplicationController
33
33
  before_filter do
34
- session[:attune_id] ||= attune_client.create_anonymous(user_agent: request.env["HTTP_USER_AGENT"])
34
+ session[:attune_id] ||= attune_client.anonymous.create.id
35
35
  end
36
36
 
37
37
  private
@@ -49,7 +49,8 @@ class SessionsController
49
49
 
50
50
  def create
51
51
  # ...
52
- attune_client.bind(session[:attune_id], current_user.id)
52
+ attune_customer = Attune::Model::Customer.new(customer: current_user.id)
53
+ attune_client.anonymous.update(session[:attune_id], attune_customer)
53
54
  end
54
55
  end
55
56
  ```
@@ -64,14 +65,15 @@ class ProductsController
64
65
 
65
66
  private
66
67
  def sorted products
67
- ranking = attune_client.get_rankings(
68
- id: session[:attune_id],
69
- view: request.fullpath,
70
- collection: 'products',
71
- entities: products.map(&:id)
72
- )
68
+ ranking_params = Attune::Model::RankingParams.new
69
+ ranking_params.anonymous = session[:attune_id]
70
+ ranking_params.view = request.fullpath
71
+ ranking_params.entity_type = 'products'
72
+ ranking_params.user_agent = request.env["HTTP_USER_AGENT"]
73
+ ranking_params.ids = products.map(&:id)
74
+ ranking = attune_client.entities.get_rankings(ranking_params)
73
75
  products.sort_by do |product|
74
- ranking[:entities].index(product.id.to_s)
76
+ ranking.ranking.index(product.id.to_s)
75
77
  end
76
78
  end
77
79
  end
data/lib/attune.rb CHANGED
@@ -4,19 +4,20 @@ require "attune/version"
4
4
  require "attune/configurable"
5
5
  require "attune/default"
6
6
  require "attune/client"
7
+ require "attune/mocks"
7
8
  require "attune/api/entities"
8
9
  require "attune/api/anonymous"
9
- require "attune/models/blacklistgetresponse"
10
- require "attune/models/anonymousresult"
11
- require "attune/models/blacklistparams"
12
- require "attune/models/rankedentities"
13
- require "attune/models/rankingparams"
10
+ require "attune/models/blacklist_get_response"
11
+ require "attune/models/anonymous_result"
12
+ require "attune/models/blacklist_params"
13
+ require "attune/models/ranked_entities"
14
+ require "attune/models/ranking_params"
14
15
  require "attune/models/customer"
15
16
  require "attune/models/blacklist"
16
- require "attune/models/batchrankingrequest"
17
- require "attune/models/scopeentry"
18
- require "attune/models/blacklistsaveresponse"
19
- require "attune/models/batchrankingresult"
17
+ require "attune/models/batch_ranking_request"
18
+ require "attune/models/scope_entry"
19
+ require "attune/models/blacklist_save_response"
20
+ require "attune/models/batch_ranking_result"
20
21
 
21
22
  module Attune
22
23
  def self.client
@@ -10,14 +10,10 @@ module Attune
10
10
  @client = client
11
11
  end
12
12
 
13
- def escapeString(string)
14
- URI.encode(string.to_s)
15
- end
16
-
17
- # Creates an anonymous visitor.
13
+ # Create anonymous visitor
18
14
  #
19
15
  # @return [Attune::Model::AnonymousResult]
20
- # @raise [ArgumentError] if user_agent is not provided
16
+ # @raise [ArgumentError] for invalid inputs
21
17
  # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
22
18
  # @raise [AuthenticationException] if authorization header not accepted
23
19
  def create ()
@@ -38,26 +34,35 @@ module Attune
38
34
  headers = nil
39
35
  post_body = nil
40
36
  response = @client.request(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
41
- Attune::Model::AnonymousResult.new(JSON.parse(response.body))
37
+ if response
38
+ Attune::Model::AnonymousResult.new(JSON.parse(response.body))
39
+ else
40
+ mockProc = MOCKS['Anonymous.create']
41
+ if mockProc
42
+ mockResponse = mockProc.call()
43
+ Attune::Model::AnonymousResult.new(mockResponse)
44
+ else
45
+ nil
46
+ end
47
+ end
48
+
42
49
  end
43
50
 
44
- # Binds one actor to another, allowing activities of those actors to be shared between the two.
51
+ # Returns an anonymous visitor, containing any assigned customer ID.
45
52
  #
46
- # @param [string] anonymous
47
- # @param [Customer] body
48
- # @raise [ArgumentError] if user_agent is not provided
53
+ # @param [String] anonymous
54
+ # @return [Attune::Model::Customer]
55
+ # @raise [ArgumentError] for invalid inputs
49
56
  # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
50
57
  # @raise [AuthenticationException] if authorization header not accepted
51
- def update (anonymous,body)
58
+ def get (anonymous)
52
59
  query_param_keys = []
53
60
 
54
61
  # verify existence of params
55
- raise "anonymous is required" if anonymous.nil?
56
- raise "body is required" if body.nil?
62
+ raise ArgumentError, "anonymous is required" if anonymous.nil?
57
63
  # set default values and merge with input
58
64
  options = {
59
- :anonymous => anonymous,
60
- :body => body}
65
+ :anonymous => anonymous}
61
66
 
62
67
  #resource path
63
68
  path = "/anonymous/{anonymous}".sub('{format}','json').sub('{' + 'anonymous' + '}', escapeString(anonymous))
@@ -70,45 +75,38 @@ module Attune
70
75
 
71
76
  headers = nil
72
77
  post_body = nil
73
- if body != nil
74
- if body.is_a?(Array)
75
- array = Array.new
76
- body.each do |item|
77
- if item.respond_to?("to_body".to_sym)
78
- array.push item.to_body
79
- else
80
- array.push item
81
- end
82
- end
83
- post_body = array
84
-
78
+ response = @client.request(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
79
+ if response
80
+ Attune::Model::Customer.new(JSON.parse(response.body))
81
+ else
82
+ mockProc = MOCKS['Anonymous.get']
83
+ if mockProc
84
+ mockResponse = mockProc.call(anonymous)
85
+ Attune::Model::Customer.new(mockResponse)
85
86
  else
86
- if body.respond_to?("to_body".to_sym)
87
- post_body = body.to_body
88
- else
89
- post_body = body
90
- end
87
+ nil
91
88
  end
92
89
  end
93
- @client.request(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body})
94
90
 
95
91
  end
96
92
 
97
- # get
93
+ # Binds one actor to another, allowing activities of those actors to be shared between the two.
98
94
  #
99
- # @param [string] anonymous
100
- # @return [Attune::Model::Customer]
101
- # @raise [ArgumentError] if user_agent is not provided
95
+ # @param [String] anonymous
96
+ # @param [Attune::Model::Customer] body
97
+ # @raise [ArgumentError] for invalid inputs
102
98
  # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
103
99
  # @raise [AuthenticationException] if authorization header not accepted
104
- def get (anonymous)
100
+ def update (anonymous,body)
105
101
  query_param_keys = []
106
102
 
107
103
  # verify existence of params
108
- raise "anonymous is required" if anonymous.nil?
104
+ raise ArgumentError, "anonymous is required" if anonymous.nil?
105
+ raise ArgumentError, "body is required" if body.nil?
109
106
  # set default values and merge with input
110
107
  options = {
111
- :anonymous => anonymous}
108
+ :anonymous => anonymous,
109
+ :body => body}
112
110
 
113
111
  #resource path
114
112
  path = "/anonymous/{anonymous}".sub('{format}','json').sub('{' + 'anonymous' + '}', escapeString(anonymous))
@@ -121,11 +119,35 @@ module Attune
121
119
 
122
120
  headers = nil
123
121
  post_body = nil
124
- response = @client.request(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
125
- Attune::Model::Customer.new(JSON.parse(response.body))
122
+ if body != nil
123
+ if body.is_a?(Array)
124
+ array = Array.new
125
+ body.each do |item|
126
+ if item.respond_to?("to_body".to_sym)
127
+ array.push item.to_body
128
+ else
129
+ array.push item
130
+ end
131
+ end
132
+ post_body = array
133
+
134
+ else
135
+ if body.respond_to?("to_body".to_sym)
136
+ post_body = body.to_body
137
+ else
138
+ post_body = body
139
+ end
140
+ end
141
+ end
142
+ @client.request(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body})
143
+
126
144
  end
127
145
 
146
+ private
147
+ def escapeString(string)
148
+ URI.encode(string.to_s)
128
149
  end
150
+ end
129
151
  end
130
152
  end
131
153
 
@@ -10,14 +10,10 @@ module Attune
10
10
  @client = client
11
11
  end
12
12
 
13
- def escapeString(string)
14
- URI.encode(string.to_s)
15
- end
16
-
17
- # blacklistGet
13
+ # List all blacklist entries for your account.
18
14
  #
19
15
  # @return [Attune::Model::BlacklistGetResponse]
20
- # @raise [ArgumentError] if user_agent is not provided
16
+ # @raise [ArgumentError] for invalid inputs
21
17
  # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
22
18
  # @raise [AuthenticationException] if authorization header not accepted
23
19
  def blacklist_get ()
@@ -38,14 +34,25 @@ module Attune
38
34
  headers = nil
39
35
  post_body = nil
40
36
  response = @client.request(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
41
- Attune::Model::BlacklistGetResponse.new(JSON.parse(response.body))
37
+ if response
38
+ Attune::Model::BlacklistGetResponse.new(JSON.parse(response.body))
39
+ else
40
+ mockProc = MOCKS['Entities.blacklist_get']
41
+ if mockProc
42
+ mockResponse = mockProc.call()
43
+ Attune::Model::BlacklistGetResponse.new(mockResponse)
44
+ else
45
+ nil
46
+ end
47
+ end
48
+
42
49
  end
43
50
 
44
- # blacklistSave
51
+ # Save a new blacklist entry.
45
52
  #
46
- # @param [BlacklistParams] body
53
+ # @param [Attune::Model::BlacklistParams] body
47
54
  # @return [Attune::Model::BlacklistSaveResponse]
48
- # @raise [ArgumentError] if user_agent is not provided
55
+ # @raise [ArgumentError] for invalid inputs
49
56
  # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
50
57
  # @raise [AuthenticationException] if authorization header not accepted
51
58
  def blacklist_save (body)
@@ -79,28 +86,39 @@ module Attune
79
86
 
80
87
  else
81
88
  if body.respond_to?("to_body".to_sym)
82
- post_body = body.to_body
83
- else
84
- post_body = body
85
- end
89
+ post_body = body.to_body
90
+ else
91
+ post_body = body
92
+ end
86
93
  end
87
94
  end
88
95
  response = @client.request(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
89
- Attune::Model::BlacklistSaveResponse.new(JSON.parse(response.body))
96
+ if response
97
+ Attune::Model::BlacklistSaveResponse.new(JSON.parse(response.body))
98
+ else
99
+ mockProc = MOCKS['Entities.blacklist_save']
100
+ if mockProc
101
+ mockResponse = mockProc.call(body)
102
+ Attune::Model::BlacklistSaveResponse.new(mockResponse)
103
+ else
104
+ nil
105
+ end
106
+ end
107
+
90
108
  end
91
109
 
92
- # getRankings
110
+ # Returns a ranking of the specified entities for the current user.
93
111
  #
94
- # @param [RankingParams] body
112
+ # @param [Attune::Model::RankingParams] body
95
113
  # @return [Attune::Model::RankedEntities]
96
- # @raise [ArgumentError] if user_agent is not provided
114
+ # @raise [ArgumentError] for invalid inputs
97
115
  # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
98
116
  # @raise [AuthenticationException] if authorization header not accepted
99
117
  def get_rankings (body)
100
118
  query_param_keys = []
101
119
 
102
120
  # verify existence of params
103
- raise "body is required" if body.nil?
121
+ raise ArgumentError, "body is required" if body.nil?
104
122
  # set default values and merge with input
105
123
  options = {
106
124
  :body => body}
@@ -129,28 +147,39 @@ module Attune
129
147
 
130
148
  else
131
149
  if body.respond_to?("to_body".to_sym)
132
- post_body = body.to_body
133
- else
134
- post_body = body
135
- end
150
+ post_body = body.to_body
151
+ else
152
+ post_body = body
153
+ end
136
154
  end
137
155
  end
138
156
  response = @client.request(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
139
- Attune::Model::RankedEntities.new(JSON.parse(response.body))
157
+ if response
158
+ Attune::Model::RankedEntities.new(JSON.parse(response.body))
159
+ else
160
+ mockProc = MOCKS['Entities.get_rankings']
161
+ if mockProc
162
+ mockResponse = mockProc.call(body)
163
+ Attune::Model::RankedEntities.new(mockResponse)
164
+ else
165
+ nil
166
+ end
167
+ end
168
+
140
169
  end
141
170
 
142
- # batchGetRankings
171
+ # Returns multiple rankings of the specified entities for the current user.
143
172
  #
144
- # @param [BatchRankingRequest] body
173
+ # @param [Attune::Model::BatchRankingRequest] body
145
174
  # @return [Attune::Model::BatchRankingResult]
146
- # @raise [ArgumentError] if user_agent is not provided
175
+ # @raise [ArgumentError] for invalid inputs
147
176
  # @raise [Faraday::Error::ClientError] if the request fails or exceeds the timeout
148
177
  # @raise [AuthenticationException] if authorization header not accepted
149
178
  def batch_get_rankings (body)
150
179
  query_param_keys = []
151
180
 
152
181
  # verify existence of params
153
- raise "body is required" if body.nil?
182
+ raise ArgumentError, "body is required" if body.nil?
154
183
  # set default values and merge with input
155
184
  options = {
156
185
  :body => body}
@@ -179,17 +208,32 @@ module Attune
179
208
 
180
209
  else
181
210
  if body.respond_to?("to_body".to_sym)
182
- post_body = body.to_body
183
- else
184
- post_body = body
185
- end
211
+ post_body = body.to_body
212
+ else
213
+ post_body = body
214
+ end
186
215
  end
187
216
  end
188
217
  response = @client.request(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
189
- Attune::Model::BatchRankingResult.new(JSON.parse(response.body))
218
+ if response
219
+ Attune::Model::BatchRankingResult.new(JSON.parse(response.body))
220
+ else
221
+ mockProc = MOCKS['Entities.batch_get_rankings']
222
+ if mockProc
223
+ mockResponse = mockProc.call(body)
224
+ Attune::Model::BatchRankingResult.new(mockResponse)
225
+ else
226
+ nil
227
+ end
228
+ end
229
+
190
230
  end
191
231
 
232
+ private
233
+ def escapeString(string)
234
+ URI.encode(string.to_s)
192
235
  end
236
+ end
193
237
  end
194
238
  end
195
239
 
data/lib/attune/client.rb CHANGED
@@ -67,8 +67,6 @@ module Attune
67
67
 
68
68
  def request(http_method, path, opts)
69
69
  adapter_method = adapter.method(http_method.downcase)
70
- headers = {'Content-Type' => 'application/json' }
71
- headers.merge! opts[:headers] if opts[:headers]
72
70
  adapter_method.call do |req|
73
71
  req.url path
74
72
  req.headers['Content-Type'] = 'application/json'
@@ -8,7 +8,7 @@ module Attune
8
8
  module Default
9
9
  extend Configurable
10
10
 
11
- ENDPOINT = "http://localhost/".freeze
11
+ ENDPOINT = "https://api.attune-staging.co".freeze
12
12
 
13
13
  # user our version of NetHttpPersistent adapter
14
14
  Faraday::Adapter.register_middleware(attune_http_persistent: NetHttpPersistent)