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 +4 -4
- data/lib/gun_broker/user/items_delegate.rb +48 -31
- data/lib/gun_broker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35088d1521500d853c13b13d7e54afde855e103d
|
4
|
+
data.tar.gz: fc53414ee8fd9799d8f28e51e0fcc5cb63c45948
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
117
|
-
|
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
|
-
|
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
|
-
|
131
|
-
|
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
|
-
|
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
|
-
|
165
|
-
|
166
|
-
|
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
|
data/lib/gun_broker/version.rb
CHANGED
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.
|
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
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|