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.
@@ -1,40 +1,37 @@
1
1
  module Attune
2
2
  module Model
3
- # customer associated with an anonymous user
3
+ # Customer associated with an anonymous user
4
+ #
5
+ # @attr [String] customer
4
6
  class Customer
5
7
  attr_accessor :customer
6
8
 
7
9
 
8
- # :internal => :external
9
- def self.attribute_map
10
- {
11
- :customer => :customer
12
-
13
- }
14
- end
15
-
16
10
  def initialize(attributes = {})
17
11
  return if attributes.empty?
18
- # Morph attribute keys into undescored rubyish style
19
- if self.class.attribute_map[:"customer"]
20
- # Workaround since JSON.parse has accessors as strings rather than symbols
21
- @customer = attributes["customer"] || attributes[:"customer"]
22
- end
12
+ # Workaround since JSON.parse has accessors as strings rather than symbols
13
+ @customer = attributes["customer"] || attributes[:"customer"]
23
14
 
24
15
 
25
16
  end
26
17
 
27
18
  def to_body
28
- body = {}
29
- self.class.attribute_map.each_pair do |key, value|
30
- body[value] = self.send(key) unless self.send(key).nil?
31
- end
32
- body
19
+ Hash[ATTRIBUTE_MAP.map do |internal, external|
20
+ next unless value = send(internal)
21
+ [external, value]
22
+ end.compact]
33
23
  end
34
24
 
35
25
  def to_json(options = {})
36
26
  to_body.to_json
37
27
  end
28
+
29
+ private
30
+ # :internal => :external
31
+ ATTRIBUTE_MAP = {
32
+ :customer => :customer
33
+
34
+ }
38
35
  end
39
36
  end
40
37
  end
@@ -0,0 +1,55 @@
1
+ module Attune
2
+ module Model
3
+ # List of ids in ranked order. If an error occurs, returns message and status code.
4
+ #
5
+ # @attr [String] message
6
+ # @attr [Integer] status
7
+ # @attr [Array<String>] ranking
8
+ class RankedEntities
9
+ attr_accessor :message
10
+
11
+
12
+ attr_accessor :status
13
+
14
+
15
+ attr_accessor :ranking
16
+
17
+
18
+ def initialize(attributes = {})
19
+ return if attributes.empty?
20
+ # Workaround since JSON.parse has accessors as strings rather than symbols
21
+ @message = attributes["message"] || attributes[:"message"]
22
+ # Workaround since JSON.parse has accessors as strings rather than symbols
23
+ @status = attributes["status"] || attributes[:"status"]
24
+ value = attributes["ranking"] || attributes[:"ranking"]
25
+ if value.is_a?(Array)
26
+ @ranking = value
27
+
28
+ end
29
+
30
+
31
+ end
32
+
33
+ def to_body
34
+ Hash[ATTRIBUTE_MAP.map do |internal, external|
35
+ next unless value = send(internal)
36
+ [external, value]
37
+ end.compact]
38
+ end
39
+
40
+ def to_json(options = {})
41
+ to_body.to_json
42
+ end
43
+
44
+ private
45
+ # :internal => :external
46
+ ATTRIBUTE_MAP = {
47
+ :message => :message,
48
+ :status => :status,
49
+ :ranking => :ranking
50
+
51
+ }
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,93 @@
1
+ module Attune
2
+ module Model
3
+ # Inputs for ranking a set of ids for a particular user.
4
+ #
5
+ # @attr [Array<Attune::Model::ScopeEntry>] scope
6
+ # @attr [String] anonymous
7
+ # @attr [String] customer
8
+ # @attr [String] user_agent
9
+ # @attr [String] entity_type
10
+ # @attr [Array<String>] ids
11
+ # @attr [String] ip
12
+ # @attr [String] view
13
+ class RankingParams
14
+ attr_accessor :scope
15
+
16
+
17
+ attr_accessor :anonymous
18
+
19
+
20
+ attr_accessor :customer
21
+
22
+
23
+ attr_accessor :user_agent
24
+
25
+
26
+ attr_accessor :entity_type
27
+
28
+
29
+ attr_accessor :ids
30
+
31
+
32
+ attr_accessor :ip
33
+
34
+
35
+ attr_accessor :view
36
+
37
+
38
+ def initialize(attributes = {})
39
+ return if attributes.empty?
40
+ value = attributes["scope"] || attributes[:"scope"]
41
+ if value.is_a?(Array)
42
+ @scope = value.map{ |v| ScopeEntry.new(v) }
43
+
44
+ end
45
+ # Workaround since JSON.parse has accessors as strings rather than symbols
46
+ @anonymous = attributes["anonymous"] || attributes[:"anonymous"]
47
+ # Workaround since JSON.parse has accessors as strings rather than symbols
48
+ @customer = attributes["customer"] || attributes[:"customer"]
49
+ # Workaround since JSON.parse has accessors as strings rather than symbols
50
+ @user_agent = attributes["userAgent"] || attributes[:"user_agent"]
51
+ # Workaround since JSON.parse has accessors as strings rather than symbols
52
+ @entity_type = attributes["entityType"] || attributes[:"entity_type"]
53
+ value = attributes["ids"] || attributes[:"ids"]
54
+ if value.is_a?(Array)
55
+ @ids = value
56
+
57
+ end
58
+ # Workaround since JSON.parse has accessors as strings rather than symbols
59
+ @ip = attributes["ip"] || attributes[:"ip"]
60
+ # Workaround since JSON.parse has accessors as strings rather than symbols
61
+ @view = attributes["view"] || attributes[:"view"]
62
+
63
+
64
+ end
65
+
66
+ def to_body
67
+ Hash[ATTRIBUTE_MAP.map do |internal, external|
68
+ next unless value = send(internal)
69
+ [external, value]
70
+ end.compact]
71
+ end
72
+
73
+ def to_json(options = {})
74
+ to_body.to_json
75
+ end
76
+
77
+ private
78
+ # :internal => :external
79
+ ATTRIBUTE_MAP = {
80
+ :scope => :scope,
81
+ :anonymous => :anonymous,
82
+ :customer => :customer,
83
+ :user_agent => :userAgent,
84
+ :entity_type => :entityType,
85
+ :ids => :ids,
86
+ :ip => :ip,
87
+ :view => :view
88
+
89
+ }
90
+ end
91
+ end
92
+ end
93
+
@@ -0,0 +1,45 @@
1
+ module Attune
2
+ module Model
3
+ # Name value pairs indicating the context where a ranking will be displayed.
4
+ #
5
+ # @attr [String] name
6
+ # @attr [String] value
7
+ class ScopeEntry
8
+ attr_accessor :name
9
+
10
+
11
+ attr_accessor :value
12
+
13
+
14
+ def initialize(attributes = {})
15
+ return if attributes.empty?
16
+ # Workaround since JSON.parse has accessors as strings rather than symbols
17
+ @name = attributes["name"] || attributes[:"name"]
18
+ # Workaround since JSON.parse has accessors as strings rather than symbols
19
+ @value = attributes["value"] || attributes[:"value"]
20
+
21
+
22
+ end
23
+
24
+ def to_body
25
+ Hash[ATTRIBUTE_MAP.map do |internal, external|
26
+ next unless value = send(internal)
27
+ [external, value]
28
+ end.compact]
29
+ end
30
+
31
+ def to_json(options = {})
32
+ to_body.to_json
33
+ end
34
+
35
+ private
36
+ # :internal => :external
37
+ ATTRIBUTE_MAP = {
38
+ :name => :name,
39
+ :value => :value
40
+
41
+ }
42
+ end
43
+ end
44
+ end
45
+
@@ -1,4 +1,4 @@
1
1
  module Attune
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
4
4
 
@@ -72,35 +72,28 @@ describe Attune::Client do
72
72
  result = client.get_auth_token("id", "secret")
73
73
  expect(result).to match(/^[a-z0-9\-]+$/)
74
74
  end
75
- it "mocks create_anonymous with an id" do
76
- result = client.anonymous.create(id: '12345', user_agent: 'Mozilla/5.0')
77
- expect(result).to eq('12345')
78
- end
75
+
79
76
  it "mocks create_anonymous with no id" do
80
- result = client.anonymous.create(user_agent: 'Mozilla/5.0')
81
- expect(result).to match(/^[a-z0-9\-]+$/)
77
+ result = client.anonymous.create
78
+ expect(result.id).to match(/^[a-z0-9\-]+$/)
82
79
  end
83
80
  describe "mocks get_rankings" do
84
81
  let(:entities) { %w[1001 1002 1003 1004] }
85
- let(:expected) do
86
- {
87
- headers: {"attune-cell"=>"mock", "attune-ranking"=>"mock"},
88
- entities: entities.map { |e| e.to_s }
89
- }
90
- end
82
+ let(:expected) { entities.map { |e| e.to_s } }
91
83
 
92
84
  before(:each) do
93
- @result = client.entities.get_rankings(
94
- id: 'abcd123',
85
+ params = Attune::Model::RankingParams.new(
86
+ anonymous: 'abcd123',
95
87
  view: 'b/mens-pants',
96
- collection: 'products',
97
- entities: entities
88
+ entity_type: 'products',
89
+ ids: entities
98
90
  )
91
+ @result = client.entities.get_rankings(params)
99
92
  end
100
93
 
101
94
  context "with entities sent as strings" do
102
95
  it "returns entities in order sent" do
103
- expect(@result).to eq expected
96
+ expect(@result.ranking).to eq expected
104
97
  end
105
98
  end
106
99
 
@@ -108,31 +101,30 @@ describe Attune::Client do
108
101
  let(:entities) { [1001, 1002, 1003, 1004] }
109
102
 
110
103
  it "returns entities in order sent as strings" do
111
- expect(@result).to eq expected
104
+ expect(@result.ranking).to eq expected
112
105
  end
113
106
  end
114
107
  end
115
108
  describe "mocks multi_get_rankings" do
116
109
  let(:entities) { %w[1001 1002 1003 1004] }
117
- let(:expected) do
118
- {
119
- headers: {"attune-cell"=>"mock", "attune-ranking"=>"mock"},
120
- entities: [ entities.map { |e| e.to_s } ]
121
- }
122
- end
110
+ let(:expected) { [entities.map { |e| e.to_s }] }
123
111
 
124
112
  before(:each) do
125
- @result = client.multi_get_rankings([
126
- id: 'abcd123',
113
+ params = Attune::Model::RankingParams.new(
114
+ anonymous: 'abcd123',
127
115
  view: 'b/mens-pants',
128
- collection: 'products',
129
- entities: entities
130
- ])
116
+ entity_type: 'products',
117
+ ids: entities
118
+ )
119
+ batch_request = Attune::Model::BatchRankingRequest.new
120
+ batch_request.requests = [params]
121
+ @result = client.entities.batch_get_rankings(batch_request)
131
122
  end
132
123
 
133
124
  context "with entities sent as strings" do
134
125
  it "returns entities in order sent" do
135
- expect(@result).to eq expected
126
+ rankings = @result.results.map(&:ranking)
127
+ expect(rankings).to eq expected
136
128
  end
137
129
  end
138
130
 
@@ -140,7 +132,8 @@ describe Attune::Client do
140
132
  let(:entities) { [1001, 1002, 1003, 1004] }
141
133
 
142
134
  it "returns entities in order sent as strings" do
143
- expect(@result).to eq expected
135
+ rankings = @result.results.map(&:ranking)
136
+ expect(rankings).to eq expected
144
137
  end
145
138
  end
146
139
  end
data/spec/attune_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe Attune do
6
6
  end
7
7
  describe 'defaults' do
8
8
  subject { Attune::Default }
9
- specify { expect(subject.endpoint).to eq 'http://localhost/' }
9
+ specify { expect(subject.endpoint).to eq 'https://api.attune-staging.co' }
10
10
  specify { expect(subject.disabled).to eq false }
11
11
  end
12
12
  describe 'configure' do
data/spec/remote_spec.rb CHANGED
@@ -11,7 +11,7 @@ describe "remote requests" do
11
11
  pending "REMOTE_ENDPOINT required for remote spec" unless endpoint
12
12
  pending "AUTH_TOKEN required for remote spec" unless auth_token
13
13
  end
14
- let!(:client){ Attune::Client.new(endpoint: endpoint, auth_token: auth_token) }
14
+ let!(:client){ Attune::Client.new(endpoint: endpoint, auth_token: auth_token, timeout: 2) }
15
15
 
16
16
  it "can request an auth_token given a client id and secret" do
17
17
  pending "CLIENT_ID required for get_auth_token spec" unless client_id
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attune
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-03 00:00:00.000000000 Z
12
+ date: 2014-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -148,17 +148,18 @@ files:
148
148
  - lib/attune/configurable.rb
149
149
  - lib/attune/default.rb
150
150
  - lib/attune/json_logger.rb
151
- - lib/attune/models/anonymousresult.rb
152
- - lib/attune/models/batchrankingrequest.rb
153
- - lib/attune/models/batchrankingresult.rb
151
+ - lib/attune/mocks.rb
152
+ - lib/attune/models/anonymous_result.rb
153
+ - lib/attune/models/batch_ranking_request.rb
154
+ - lib/attune/models/batch_ranking_result.rb
154
155
  - lib/attune/models/blacklist.rb
155
- - lib/attune/models/blacklistgetresponse.rb
156
- - lib/attune/models/blacklistparams.rb
157
- - lib/attune/models/blacklistsaveresponse.rb
156
+ - lib/attune/models/blacklist_get_response.rb
157
+ - lib/attune/models/blacklist_params.rb
158
+ - lib/attune/models/blacklist_save_response.rb
158
159
  - lib/attune/models/customer.rb
159
- - lib/attune/models/rankedentities.rb
160
- - lib/attune/models/rankingparams.rb
161
- - lib/attune/models/scopeentry.rb
160
+ - lib/attune/models/ranked_entities.rb
161
+ - lib/attune/models/ranking_params.rb
162
+ - lib/attune/models/scope_entry.rb
162
163
  - lib/attune/net_http_persistent.rb
163
164
  - lib/attune/param_flattener.rb
164
165
  - lib/attune/version.rb
@@ -1,41 +0,0 @@
1
- module Attune
2
- module Model
3
- #
4
- class AnonymousResult
5
- attr_accessor :id
6
-
7
-
8
- # :internal => :external
9
- def self.attribute_map
10
- {
11
- :id => :id
12
-
13
- }
14
- end
15
-
16
- def initialize(attributes = {})
17
- return if attributes.empty?
18
- # Morph attribute keys into undescored rubyish style
19
- if self.class.attribute_map[:"id"]
20
- # Workaround since JSON.parse has accessors as strings rather than symbols
21
- @id = attributes["id"] || attributes[:"id"]
22
- end
23
-
24
-
25
- end
26
-
27
- def to_body
28
- body = {}
29
- self.class.attribute_map.each_pair do |key, value|
30
- body[value] = self.send(key) unless self.send(key).nil?
31
- end
32
- body
33
- end
34
-
35
- def to_json(options = {})
36
- to_body.to_json
37
- end
38
- end
39
- end
40
- end
41
-