gun_broker 1.3.1 → 1.3.2

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: ee62a2f7ba855ae1ab273fb835e4f409618ec80f
4
- data.tar.gz: 9a82f711c82e128281e4a1a8008770958f5b6ffa
3
+ metadata.gz: 37428cdf48dee77029ac60d1d952c99f4a3cc8bb
4
+ data.tar.gz: 67b8e2d282ba3d25e79cbd942c9100892e54bb68
5
5
  SHA512:
6
- metadata.gz: ff7a88de4b27ed07c443324fef32ed2e3e5e728d4b7878decd0a7040971e597ee5ffa78df7a5574a8b8bd1de3ba9bc680a92266378f3cee54e8b73f991080dec
7
- data.tar.gz: 2866e8691ff60d72212d823a9d510b99a7531e790ac0ca7ab8260535a70dbc52c979899527270f75e2717473da7f0a86752435bb3512b3efcc1f79e0b3cc10a7
6
+ metadata.gz: 4f7fb34d4e93485b7f326df30229ff2f0126fc1703acc2dd5e56180ac7f170f238244822b0f61231dd5f60b2b23a2cf4e3fcacd6eb7127738e892a3bdf5f9d8e
7
+ data.tar.gz: 3ff24c0755be1b05abe2ac403534fb9c59ea92acb56e76819f05dc83445ac6474471ce135aad5afc3bc132938d70d13478150e10cd531f40ed8304105ab456b5
@@ -16,7 +16,7 @@ module GunBroker
16
16
  PAGE_SIZE = 300
17
17
 
18
18
  # Defaults to 12 (View Last 30 Days), so we need to specify 1 (View All Completed) to get everything.
19
- TIME_FRAME = 1
19
+ TIME_FRAME_FOR_ALL_RESULTS = 1
20
20
 
21
21
  USER_AGENT = "gun_broker rubygems.org/gems/gun_broker v(#{GunBroker::VERSION})"
22
22
 
@@ -12,7 +12,6 @@ module GunBroker
12
12
  @attributes[:params].merge!({
13
13
  'PageIndex' => @attributes[:page_index],
14
14
  'PageSize' => @attributes[:page_size],
15
- 'TimeFrame' => GunBroker::API::TIME_FRAME,
16
15
  })
17
16
  response = GunBroker::API.get(@attributes[:endpoint], @attributes[:params], @attributes[:token_header])
18
17
 
@@ -24,7 +24,7 @@ module GunBroker
24
24
  # @return [Array<ItemsAsPage>]
25
25
  def all
26
26
  # NOTE: this endpoint will not return items that were sold
27
- @all ||= build_pages_for(:Items, { 'SellerName' => @user.username })
27
+ @all ||= build_pages_for(:Items, params_for(:sellername))
28
28
  end
29
29
 
30
30
  # Returns pages for all items the User has bid on.
@@ -38,35 +38,35 @@ module GunBroker
38
38
  # @note {API#get! GET} /ItemsNotWon
39
39
  # @return [Array<ItemsAsPage>]
40
40
  def not_won
41
- @not_won ||= build_pages_for(:ItemsNotWon)
41
+ @not_won ||= build_pages_for(:ItemsNotWon, params_for(:timeframe))
42
42
  end
43
43
 
44
44
  # Returns pages for items that are currently selling.
45
45
  # @note {API#get! GET} /Items
46
46
  # @return [Array<ItemsAsPage>]
47
47
  def selling
48
- @selling ||= build_pages_for(:Items, { 'SellerName' => @user.username })
48
+ @selling ||= build_pages_for(:Items, params_for(:sellername))
49
49
  end
50
50
 
51
51
  # Returns pages for items the User has sold.
52
52
  # @note {API#get! GET} /ItemsSold
53
53
  # @return [Array<ItemsAsPage>]
54
54
  def sold
55
- @sold ||= build_pages_for(:ItemsSold)
55
+ @sold ||= build_pages_for(:ItemsSold, params_for(:timeframe))
56
56
  end
57
57
 
58
58
  # Returns pages for items that were listed, but not sold.
59
59
  # @note {API#get! GET} /ItemsUnsold
60
60
  # @return [Array<ItemsAsPage>]
61
61
  def unsold
62
- @unsold ||= build_pages_for(:ItemsUnsold)
62
+ @unsold ||= build_pages_for(:ItemsUnsold, params_for(:timeframe))
63
63
  end
64
64
 
65
65
  # Returns pages for items the User has won.
66
66
  # @note {API#get! GET} /ItemsWon
67
67
  # @return [Array<ItemsAsPage>]
68
68
  def won
69
- @won ||= build_pages_for(:ItemsWon)
69
+ @won ||= build_pages_for(:ItemsWon, params_for(:timeframe))
70
70
  end
71
71
 
72
72
  private
@@ -93,6 +93,18 @@ module GunBroker
93
93
 
94
94
  items_as_pages
95
95
  end
96
+
97
+ def params_for(key)
98
+ case key
99
+ when :sellername
100
+ { 'SellerName' => @user.username }
101
+ when :timeframe
102
+ { 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS }
103
+ else
104
+ raise GunBroker::Error.new 'Unrecognized `params_for` key.'
105
+ end
106
+ end
107
+
96
108
  end
97
109
  end
98
110
  end
@@ -19,7 +19,7 @@ module GunBroker
19
19
  # @return [Array<Item>]
20
20
  def all
21
21
  # NOTE: this endpoint will not return items that were sold
22
- @all ||= fetch_items(:Items, { 'SellerName' => @user.username })
22
+ @all ||= fetch_items(:Items, params_for(:sellername))
23
23
  end
24
24
 
25
25
  # Returns all the items the User has bid on.
@@ -72,7 +72,7 @@ module GunBroker
72
72
  # @note {API#get! GET} /ItemsNotWon
73
73
  # @return [Array<Item>]
74
74
  def not_won
75
- @not_won ||= fetch_items(:ItemsNotWon)
75
+ @not_won ||= fetch_items(:ItemsNotWon, params_for(:timeframe))
76
76
  end
77
77
 
78
78
  # Returns Items that are currently selling.
@@ -82,10 +82,10 @@ module GunBroker
82
82
  # @raise [GunBroker::Error::RequestError] If there's an issue with the request (usually a `5xx` response).
83
83
  # @return [Array<Item>]
84
84
  def selling(options = {})
85
- params = {
86
- 'ItemID' => (options[:item_id] || options["ItemID"]),
87
- 'SellerName' => @user.username,
88
- }.delete_if { |k, v| v.nil? }
85
+ params = [
86
+ *params_for(:sellername),
87
+ *params_for(:itemid, options)
88
+ ].to_h
89
89
 
90
90
  @selling ||= fetch_items(:Items, params)
91
91
  end
@@ -95,20 +95,23 @@ module GunBroker
95
95
  # @note {API#get! GET} /ItemsSold
96
96
  # @return [Array<Item>]
97
97
  def sold(options = {})
98
- params = {
99
- 'ItemID' => (options[:item_id] || options["ItemID"])
100
- }.delete_if { |k, v| v.nil? }
98
+ params = [
99
+ *params_for(:timeframe),
100
+ *params_for(:itemid, options)
101
+ ].to_h
101
102
 
102
103
  @sold ||= fetch_items(:ItemsSold, params)
103
104
  end
104
105
 
105
106
  # Items that were listed, but not sold.
107
+ # @param options [Hash] {ItemID=>ItemID}.
106
108
  # @note {API#get! GET} /ItemsUnsold
107
109
  # @return [Array<Item>]
108
110
  def unsold(options = {})
109
- params = {
110
- 'ItemID' => (options[:item_id] || options["ItemID"])
111
- }.delete_if { |k, v| v.nil? }
111
+ params = [
112
+ *params_for(:timeframe),
113
+ *params_for(:itemid, options)
114
+ ].to_h
112
115
 
113
116
  @unsold ||= fetch_items(:ItemsUnsold, params)
114
117
  end
@@ -137,16 +140,14 @@ module GunBroker
137
140
  # @note {API#get! GET} /ItemsWon
138
141
  # @return [Array<Item>]
139
142
  def won
140
- @won ||= fetch_items(:ItemsWon)
143
+ @won ||= fetch_items(:ItemsWon, params_for(:timeframe))
141
144
  end
142
145
 
143
146
  private
144
147
 
145
- def fetch_items(endpoint, params = {})\
146
- params.merge!({
147
- 'PageSize' => GunBroker::API::PAGE_SIZE,
148
- 'TimeFrame' => GunBroker::API::TIME_FRAME,
149
- })
148
+ def fetch_items(endpoint, params = {})
149
+ cleanup_nil_params(params)
150
+ params.merge!('PageSize' => GunBroker::API::PAGE_SIZE)
150
151
 
151
152
  endpoint = ['/', endpoint.to_s].join
152
153
  response = GunBroker::API.get(endpoint, params, token_header(@user.token))
@@ -174,6 +175,23 @@ module GunBroker
174
175
  results.map { |result| GunBroker::Item.new(result) }
175
176
  end
176
177
 
178
+ def params_for(key, options = {})
179
+ case key
180
+ when :sellername
181
+ { 'SellerName' => @user.username }
182
+ when :timeframe
183
+ { 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS }
184
+ when :itemid
185
+ { 'ItemID' => (options[:item_id] || options["ItemID"]) }
186
+ else
187
+ raise GunBroker::Error.new 'Unrecognized `params_for` key.'
188
+ end
189
+ end
190
+
191
+ def cleanup_nil_params(params)
192
+ params.delete_if { |k, v| v.nil? }
193
+ end
194
+
177
195
  end
178
196
  end
179
197
  end
@@ -1,3 +1,3 @@
1
1
  module GunBroker
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -17,7 +17,7 @@ describe GunBroker::User::ItemsDelegate do
17
17
  headers: headers('X-AccessToken' => token),
18
18
  query: {
19
19
  'SellerName' => user.username,
20
- 'PageSize' => GunBroker::API::PAGE_SIZE
20
+ 'PageSize' => GunBroker::API::PAGE_SIZE
21
21
  }
22
22
  )
23
23
  .to_return(body: response_fixture('items'))
@@ -34,7 +34,7 @@ describe GunBroker::User::ItemsDelegate do
34
34
  headers: headers('X-AccessToken' => token),
35
35
  query: {
36
36
  'SellerName' => user.username,
37
- 'PageSize' => GunBroker::API::PAGE_SIZE
37
+ 'PageSize' => GunBroker::API::PAGE_SIZE
38
38
  }
39
39
  )
40
40
  .to_return(body: response_fixture('not_authorized'), status: 401)
@@ -52,7 +52,9 @@ describe GunBroker::User::ItemsDelegate do
52
52
  stub_request(:get, endpoint)
53
53
  .with(
54
54
  headers: headers('X-AccessToken' => token),
55
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
55
+ query: {
56
+ 'PageSize' => GunBroker::API::PAGE_SIZE
57
+ }
56
58
  )
57
59
  .to_return(body: response_fixture('items'))
58
60
 
@@ -67,7 +69,9 @@ describe GunBroker::User::ItemsDelegate do
67
69
  stub_request(:get, endpoint)
68
70
  .with(
69
71
  headers: headers('X-AccessToken' => token),
70
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
72
+ query: {
73
+ 'PageSize' => GunBroker::API::PAGE_SIZE
74
+ }
71
75
  )
72
76
  .to_return(body: response_fixture('not_authorized'), status: 401)
73
77
 
@@ -89,7 +93,7 @@ describe GunBroker::User::ItemsDelegate do
89
93
  headers: headers('X-AccessToken' => token),
90
94
  query: {
91
95
  'SellerName' => user.username,
92
- 'PageSize' => GunBroker::API::PAGE_SIZE
96
+ 'PageSize' => GunBroker::API::PAGE_SIZE
93
97
  }
94
98
  )
95
99
  .to_return(body: response_fixture('items'))
@@ -110,7 +114,7 @@ describe GunBroker::User::ItemsDelegate do
110
114
  headers: headers('X-AccessToken' => token),
111
115
  query: {
112
116
  'SellerName' => user.username,
113
- 'PageSize' => GunBroker::API::PAGE_SIZE
117
+ 'PageSize' => GunBroker::API::PAGE_SIZE
114
118
  }
115
119
  )
116
120
  .to_return(body: response_fixture('items'))
@@ -134,7 +138,7 @@ describe GunBroker::User::ItemsDelegate do
134
138
  headers: headers('X-AccessToken' => token),
135
139
  query: {
136
140
  'SellerName' => user.username,
137
- 'PageSize' => GunBroker::API::PAGE_SIZE
141
+ 'PageSize' => GunBroker::API::PAGE_SIZE
138
142
  }
139
143
  )
140
144
  .to_return(body: response_fixture('items'))
@@ -154,7 +158,10 @@ describe GunBroker::User::ItemsDelegate do
154
158
  stub_request(:get, endpoint)
155
159
  .with(
156
160
  headers: headers('X-AccessToken' => token),
157
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
161
+ query: {
162
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
163
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
164
+ }
158
165
  )
159
166
  .to_return(body: response_fixture('items'))
160
167
 
@@ -169,7 +176,10 @@ describe GunBroker::User::ItemsDelegate do
169
176
  stub_request(:get, endpoint)
170
177
  .with(
171
178
  headers: headers('X-AccessToken' => token),
172
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
179
+ query: {
180
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
181
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
182
+ }
173
183
  )
174
184
  .to_return(body: response_fixture('not_authorized'), status: 401)
175
185
 
@@ -187,7 +197,10 @@ describe GunBroker::User::ItemsDelegate do
187
197
  stub_request(:get, endpoint)
188
198
  .with(
189
199
  headers: headers('X-AccessToken' => token),
190
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
200
+ query: {
201
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
202
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
203
+ }
191
204
  )
192
205
  .to_return(body: response_fixture('items'))
193
206
 
@@ -200,9 +213,10 @@ describe GunBroker::User::ItemsDelegate do
200
213
  stub_request(:get, endpoint)
201
214
  .with(
202
215
  headers: headers('X-AccessToken' => token),
203
- query: {
204
- 'PageSize' => GunBroker::API::PAGE_SIZE,
205
- 'ItemID' => '123'
216
+ query: {
217
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
218
+ 'ItemID' => '123',
219
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
206
220
  }
207
221
  )
208
222
  .to_return(body: response_fixture('item_id'))
@@ -218,7 +232,10 @@ describe GunBroker::User::ItemsDelegate do
218
232
  stub_request(:get, endpoint)
219
233
  .with(
220
234
  headers: headers('X-AccessToken' => token),
221
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
235
+ query: {
236
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
237
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
238
+ }
222
239
  )
223
240
  .to_return(body: response_fixture('not_authorized'), status: 401)
224
241
 
@@ -236,7 +253,10 @@ describe GunBroker::User::ItemsDelegate do
236
253
  stub_request(:get, endpoint)
237
254
  .with(
238
255
  headers: headers('X-AccessToken' => token),
239
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
256
+ query: {
257
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
258
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
259
+ }
240
260
  )
241
261
  .to_return(body: response_fixture('items'))
242
262
 
@@ -251,7 +271,10 @@ describe GunBroker::User::ItemsDelegate do
251
271
  stub_request(:get, endpoint)
252
272
  .with(
253
273
  headers: headers('X-AccessToken' => token),
254
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
274
+ query: {
275
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
276
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
277
+ }
255
278
  )
256
279
  .to_return(body: response_fixture('not_authorized'), status: 401)
257
280
 
@@ -269,7 +292,10 @@ describe GunBroker::User::ItemsDelegate do
269
292
  stub_request(:get, endpoint)
270
293
  .with(
271
294
  headers: headers('X-AccessToken' => token),
272
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
295
+ query: {
296
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
297
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
298
+ }
273
299
  )
274
300
  .to_return(body: response_fixture('items'))
275
301
 
@@ -284,7 +310,10 @@ describe GunBroker::User::ItemsDelegate do
284
310
  stub_request(:get, endpoint)
285
311
  .with(
286
312
  headers: headers('X-AccessToken' => token),
287
- query: { 'PageSize' => GunBroker::API::PAGE_SIZE }
313
+ query: {
314
+ 'PageSize' => GunBroker::API::PAGE_SIZE,
315
+ 'TimeFrame' => GunBroker::API::TIME_FRAME_FOR_ALL_RESULTS,
316
+ }
288
317
  )
289
318
  .to_return(body: response_fixture('not_authorized'), status: 401)
290
319
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gun_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell