gun_broker 1.1.3.1 → 1.2.0

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: ef5c51c9081d64a792ac5f6dc071c1c88d3ee28a
4
- data.tar.gz: 786b854259925ba6a6e693e7bee046d7cf03376f
3
+ metadata.gz: 35088d1521500d853c13b13d7e54afde855e103d
4
+ data.tar.gz: fc53414ee8fd9799d8f28e51e0fcc5cb63c45948
5
5
  SHA512:
6
- metadata.gz: 448d71ea7efba60b16b415e5b127be6bff511bf19cf6c6180cb05f6082708c3c5a6febcc0191dd7c134facfd64f67932912f41d2a805daa103ef7597626c3133
7
- data.tar.gz: 0424e6adac3448fa85139142ceb793d23e00eca85d8669cac166da344932cac7a4c119bd298dbb79059bbe78f2a167454a9fb09c4e3212d64429b571d40f1381
6
+ metadata.gz: 4190c49fd7a4da4bfdaff0a0a091c455a8b3863d941afc2dfd146d049927386df8ec57944305e9a7b5628e7d8b4288849cac1ed439611e16efc36845b3923636
7
+ data.tar.gz: 3e7e5427e40f43a13bc2a839b4587424e864998a5f39d03bc0a40b2c2369e342d359ac09025d7e1a070baca741ed807c0f86d56f5cc899f26563eeb2e204dbd1
@@ -19,11 +19,10 @@ module GunBroker
19
19
  # @return [Array<Item>]
20
20
  def all
21
21
  # NOTE: this endpoint will not return items that were sold
22
- response = GunBroker::API.get('/Items', {
23
- 'SellerName' => @user.username,
24
- 'PageSize' => GunBroker::API::PAGE_SIZE
25
- }, token_header(@user.token))
26
- items_from_results(response['results'])
22
+ endpoint = :Items
23
+ params = { 'SellerName' => @user.username }
24
+
25
+ fetch_items(endpoint, params)
27
26
  end
28
27
 
29
28
  # Returns all the items the User has bid on.
@@ -31,10 +30,9 @@ module GunBroker
31
30
  # @raise (see #all)
32
31
  # @return [Array<Item>]
33
32
  def bid_on
34
- response = GunBroker::API.get('/ItemsBidOn', {
35
- 'PageSize' => GunBroker::API::PAGE_SIZE
36
- }, token_header(@user.token))
37
- items_from_results(response['results'])
33
+ endpoint = :ItemsBidOn
34
+
35
+ fetch_items(endpoint)
38
36
  end
39
37
 
40
38
  # Sends a multipart/form-data POST request to create an Item with the given `attributes`.
@@ -84,10 +82,9 @@ module GunBroker
84
82
  # @raise (see #all)
85
83
  # @return [Array<Item>]
86
84
  def not_won
87
- response = GunBroker::API.get('/ItemsNotWon', {
88
- 'PageSize' => GunBroker::API::PAGE_SIZE
89
- }, token_header(@user.token))
90
- items_from_results(response['results'])
85
+ endpoint = :ItemsNotWon
86
+
87
+ fetch_items(endpoint)
91
88
  end
92
89
 
93
90
  # Returns Items that are currently selling.
@@ -97,14 +94,13 @@ module GunBroker
97
94
  # @raise [GunBroker::Error::RequestError] If there's an issue with the request (usually a `5xx` response).
98
95
  # @return [Array<Item>]
99
96
  def selling(options = {})
100
- parameters = {
97
+ endpoint = :Items
98
+ params = {
101
99
  'ItemID' => (options[:item_id] || options["ItemID"]),
102
- 'PageSize' => GunBroker::API::PAGE_SIZE,
103
100
  'SellerName' => @user.username,
104
101
  }.delete_if { |k, v| v.nil? }
105
102
 
106
- response = GunBroker::API.get('/Items', parameters, token_header(@user.token))
107
- items_from_results(response['results'])
103
+ fetch_items(endpoint, params)
108
104
  end
109
105
 
110
106
  # Items the User has sold.
@@ -113,13 +109,12 @@ module GunBroker
113
109
  # @raise (see #all)
114
110
  # @return [Array<Item>]
115
111
  def sold(options = {})
116
- parameters = {
117
- 'PageSize' => GunBroker::API::PAGE_SIZE,
118
- 'ItemID' => (options[:item_id] || options["ItemID"]),
112
+ endpoint = :ItemsSold
113
+ params = {
114
+ 'ItemID' => (options[:item_id] || options["ItemID"])
119
115
  }.delete_if { |k, v| v.nil? }
120
116
 
121
- response = GunBroker::API.get('/ItemsSold', parameters, token_header(@user.token))
122
- items_from_results(response['results'])
117
+ fetch_items(endpoint, params)
123
118
  end
124
119
 
125
120
  # Items that were listed, but not sold.
@@ -127,13 +122,12 @@ module GunBroker
127
122
  # @raise (see #all)
128
123
  # @return [Array<Item>]
129
124
  def unsold(options = {})
130
- parameters = {
131
- 'PageSize' => GunBroker::API::PAGE_SIZE,
132
- 'ItemID' => (options[:item_id] || options["ItemID"]),
125
+ endpoint = :ItemsUnsold
126
+ params = {
127
+ 'ItemID' => (options[:item_id] || options["ItemID"])
133
128
  }.delete_if { |k, v| v.nil? }
134
129
 
135
- response = GunBroker::API.get('/ItemsUnsold', parameters, token_header(@user.token))
136
- items_from_results(response['results'])
130
+ fetch_items(endpoint, params)
137
131
  end
138
132
 
139
133
  # Updates an {Item} with the given attributes.
@@ -161,14 +155,37 @@ module GunBroker
161
155
  # @raise (see #all)
162
156
  # @return [Array<Item>]
163
157
  def won
164
- response = GunBroker::API.get('/ItemsWon', {
165
- 'PageSize' => GunBroker::API::PAGE_SIZE
166
- }, token_header(@user.token))
167
- items_from_results(response['results'])
158
+ endpoint = :ItemsWon
159
+
160
+ fetch_items(endpoint)
168
161
  end
169
162
 
170
163
  private
171
164
 
165
+ def fetch_items(endpoint, params = {})
166
+ endpoint = ['/', endpoint.to_s].join
167
+ params.merge!({ 'PageSize' => GunBroker::API::PAGE_SIZE })
168
+ response = GunBroker::API.get(endpoint, params, token_header(@user.token))
169
+ pages = (response['count'] / GunBroker::API::PAGE_SIZE.to_f).ceil
170
+
171
+ if pages > 1
172
+ _items_from_results = items_from_results(response['results'])
173
+
174
+ pages.times do |page|
175
+ page += 1
176
+ next if page == 1
177
+
178
+ params.merge!({ 'PageIndex' => page })
179
+ response = GunBroker::API.get(endpoint, params, token_header(@user.token))
180
+ _items_from_results.concat(items_from_results(response['results']))
181
+ end
182
+
183
+ _items_from_results
184
+ else
185
+ items_from_results(response['results'])
186
+ end
187
+ end
188
+
172
189
  def items_from_results(results)
173
190
  results.map { |result| GunBroker::Item.new(result) }
174
191
  end
@@ -1,3 +1,3 @@
1
1
  module GunBroker
2
- VERSION = "1.1.3.1"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gun_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler