gun_broker 0.7.2 → 0.8.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.rb +20 -0
- data/lib/gun_broker/user/items_delegate.rb +24 -13
- data/lib/gun_broker/version.rb +1 -1
- data/spec/fixtures/item_id.json +1 -0
- data/spec/gun_broker/user/items_delegate_spec.rb +16 -0
- data/spec/gun_broker_spec.rb +19 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d2b22b6ae3a52a176f7191944c75b34f1d1fe11
|
4
|
+
data.tar.gz: bd1e881cd614343cb8a441420b751ce7e8ce9314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46ec9c38357f0a3e1daccfd5d16049b4b9aa610a253c6bd4a65672649b1f1b013593cff4b97c96e0920807d161a0be84c320a6b3ecf961bc4cd870c19693328c
|
7
|
+
data.tar.gz: b9d604c7aca3055a5e2a1347c7657dcebd685fa6df3135810a931fe542ff097780edf13d28c35fa4a92dc48dabc4421c7d572328829a451e8a76a93a6f7263d8
|
data/lib/gun_broker.rb
CHANGED
@@ -10,6 +10,21 @@ require 'gun_broker/user'
|
|
10
10
|
|
11
11
|
module GunBroker
|
12
12
|
|
13
|
+
WEB_URL = "https://www.gunbroker.com"
|
14
|
+
WEB_URL_SANDBOX = "https://www.sandbox.gunbroker.com"
|
15
|
+
|
16
|
+
# Sets the developer key obtained from GunBroker.com.
|
17
|
+
# @param api [Boolean] whether to use api endpoint or public website endpoint
|
18
|
+
def self.base_url(api: true)
|
19
|
+
if sandbox?
|
20
|
+
return API::ROOT_URL_SANDBOX if api
|
21
|
+
WEB_URL_SANDBOX
|
22
|
+
else
|
23
|
+
return API::ROOT_URL if api
|
24
|
+
WEB_URL
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
13
28
|
# Sets the developer key obtained from GunBroker.com.
|
14
29
|
# @param dev_key [String]
|
15
30
|
def self.dev_key=(dev_key)
|
@@ -36,6 +51,11 @@ module GunBroker
|
|
36
51
|
defined?(@@sandbox) ? @@sandbox : false
|
37
52
|
end
|
38
53
|
|
54
|
+
# An alias to {.sandbox} method
|
55
|
+
def self.sandbox?
|
56
|
+
sandbox
|
57
|
+
end
|
58
|
+
|
39
59
|
# Returns a hash containing the time on GunBroker's servers in UTC
|
40
60
|
# and the current version of the GunBroker API.
|
41
61
|
#
|
@@ -96,27 +96,35 @@ module GunBroker
|
|
96
96
|
end
|
97
97
|
|
98
98
|
# Returns Items that are currently selling.
|
99
|
+
# @param options [Hash] {ItemID=>ItemID}.
|
99
100
|
# @note {API#get! GET} /Items
|
100
101
|
# @raise [GunBroker::Error::NotAuthorized] If the {User#token} isn't valid.
|
101
102
|
# @raise [GunBroker::Error::RequestError] If there's an issue with the request (usually a `5xx` response).
|
102
103
|
# @return [Array<Item>]
|
103
|
-
def selling
|
104
|
-
|
105
|
-
'
|
104
|
+
def selling(options = {})
|
105
|
+
parameters = {
|
106
|
+
'ItemID' => (options[:item_id] || options["ItemID"]),
|
107
|
+
'PageSize' => GunBroker::API::PAGE_SIZE,
|
108
|
+
'SellerName' => @user.username,
|
106
109
|
'SellingStatus' => SELLING_STATUS[:selling],
|
107
|
-
|
108
|
-
|
110
|
+
}.delete_if { |k, v| v.nil? }
|
111
|
+
|
112
|
+
response = GunBroker::API.get('/Items', parameters, token_header(@user.token))
|
109
113
|
items_from_results(response['results'])
|
110
114
|
end
|
111
115
|
|
112
116
|
# Items the User has sold.
|
117
|
+
# @param options [Hash] {ItemID=>ItemID}.
|
113
118
|
# @note {API#get! GET} /ItemsSold
|
114
119
|
# @raise (see #all)
|
115
120
|
# @return [Array<Item>]
|
116
|
-
def sold
|
117
|
-
|
118
|
-
'PageSize' => GunBroker::API::PAGE_SIZE
|
119
|
-
|
121
|
+
def sold(options = {})
|
122
|
+
parameters = {
|
123
|
+
'PageSize' => GunBroker::API::PAGE_SIZE,
|
124
|
+
'ItemID' => (options[:item_id] || options["ItemID"]),
|
125
|
+
}.delete_if { |k, v| v.nil? }
|
126
|
+
|
127
|
+
response = GunBroker::API.get('/ItemsSold', parameters, token_header(@user.token))
|
120
128
|
items_from_results(response['results'])
|
121
129
|
end
|
122
130
|
|
@@ -124,10 +132,13 @@ module GunBroker
|
|
124
132
|
# @note {API#get! GET} /ItemsUnsold
|
125
133
|
# @raise (see #all)
|
126
134
|
# @return [Array<Item>]
|
127
|
-
def unsold
|
128
|
-
|
129
|
-
'PageSize' => GunBroker::API::PAGE_SIZE
|
130
|
-
|
135
|
+
def unsold(options = {})
|
136
|
+
parameters = {
|
137
|
+
'PageSize' => GunBroker::API::PAGE_SIZE,
|
138
|
+
'ItemID' => (options[:item_id] || options["ItemID"]),
|
139
|
+
}.delete_if { |k, v| v.nil? }
|
140
|
+
|
141
|
+
response = GunBroker::API.get('/ItemsUnsold', parameters, token_header(@user.token))
|
131
142
|
items_from_results(response['results'])
|
132
143
|
end
|
133
144
|
|
data/lib/gun_broker/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"count":1,"pageIndex":1,"pageSize":25,"results":[{"itemID":465370483,"bids":0,"eligibleForImmediateCheckout":false,"endingDate":"2015-02-25T15:37:19Z","isFeaturedItem":false,"isFixedPrice":true,"isHighlighted":false,"isShowCaseItem":false,"isTitleBoldface":false,"hasBuyNow":false,"hasColor":false,"hasQuickLook":false,"hasPictures":true,"hasReserve":false,"hasReserveBeenMet":false,"highBidderID":0,"quantity":3,"price":49.9900,"serialNumber":"","sku":"","subTitle":"","thumbnailURL":"http://pics.gunbroker.com/GB/465370000/465370483/thumb.jpg","timeLeft":"P26DT18H52M28S","title":"Magpul STR Carbine Stock Mil Spec Black","titleColor":"#000000","links":[{"rel":"self","href":"https://api.gunbroker.com/v1/items/465370483","verb":"GET","title":"465370483"}]}],"categoryCounts":[{"id":3032,"name":"Rifle Stocks","count":1}],"links":[{"rel":"share","href":"http://www.gunbroker.com/All/BI.aspx?IncludeSellers=2266088&PageSize=25","verb":"GET","title":"Check out what I found on GunBroker.com!"}]}
|
@@ -200,6 +200,22 @@ describe GunBroker::User::ItemsDelegate do
|
|
200
200
|
expect(delegate.sold).not_to be_empty
|
201
201
|
expect(delegate.sold.first).to be_a(GunBroker::Item)
|
202
202
|
end
|
203
|
+
|
204
|
+
it 'returns one sold item when passed an `ItemID` option' do
|
205
|
+
stub_request(:get, endpoint)
|
206
|
+
.with(
|
207
|
+
headers: headers('X-AccessToken' => token),
|
208
|
+
query: {
|
209
|
+
'PageSize' => GunBroker::API::PAGE_SIZE,
|
210
|
+
'ItemID' => '123'
|
211
|
+
}
|
212
|
+
)
|
213
|
+
.to_return(body: response_fixture('item_id'))
|
214
|
+
|
215
|
+
user = GunBroker::User.new(username, token: token)
|
216
|
+
expect(delegate.sold(item_id: 123)).not_to be_empty
|
217
|
+
expect(delegate.sold(item_id: 123).first).to be_a(GunBroker::Item)
|
218
|
+
end
|
203
219
|
end
|
204
220
|
|
205
221
|
context 'on failure' do
|
data/spec/gun_broker_spec.rb
CHANGED
@@ -6,6 +6,24 @@ describe GunBroker do
|
|
6
6
|
expect(GunBroker::VERSION).to be_a(String)
|
7
7
|
end
|
8
8
|
|
9
|
+
context '.base_url' do
|
10
|
+
context 'in sandbox mode' do
|
11
|
+
it 'should return the proper sandbox api url' do
|
12
|
+
GunBroker.sandbox = false
|
13
|
+
expect(GunBroker.base_url).to eq("https://api.gunbroker.com/v1")
|
14
|
+
expect(GunBroker.base_url(api: false)).to eq("https://www.gunbroker.com")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'in live mode' do
|
19
|
+
it 'should return the proper api url' do
|
20
|
+
GunBroker.sandbox = true
|
21
|
+
expect(GunBroker.base_url).to eq("https://api.sandbox.gunbroker.com/v1")
|
22
|
+
expect(GunBroker.base_url(api: false)).to eq("https://www.sandbox.gunbroker.com")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
9
27
|
context '.dev_key' do
|
10
28
|
let(:key) { 'foo' }
|
11
29
|
|
@@ -26,13 +44,10 @@ describe GunBroker do
|
|
26
44
|
end
|
27
45
|
|
28
46
|
context '.sandbox' do
|
29
|
-
it 'defaults to false' do
|
30
|
-
expect(GunBroker.sandbox).to eq(false)
|
31
|
-
end
|
32
|
-
|
33
47
|
it 'sets @@sandbox to true' do
|
34
48
|
GunBroker.sandbox = true
|
35
49
|
expect(GunBroker.sandbox).to eq(true)
|
50
|
+
expect(GunBroker.sandbox?).to eq(true)
|
36
51
|
end
|
37
52
|
end
|
38
53
|
|
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: 0.
|
4
|
+
version: 0.8.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: 2016-
|
11
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- spec/fixtures/feedback-summary.json
|
133
133
|
- spec/fixtures/feedback.json
|
134
134
|
- spec/fixtures/item.json
|
135
|
+
- spec/fixtures/item_id.json
|
135
136
|
- spec/fixtures/items.json
|
136
137
|
- spec/fixtures/not_authorized.json
|
137
138
|
- spec/fixtures/test.json
|
@@ -183,6 +184,7 @@ test_files:
|
|
183
184
|
- spec/fixtures/feedback-summary.json
|
184
185
|
- spec/fixtures/feedback.json
|
185
186
|
- spec/fixtures/item.json
|
187
|
+
- spec/fixtures/item_id.json
|
186
188
|
- spec/fixtures/items.json
|
187
189
|
- spec/fixtures/not_authorized.json
|
188
190
|
- spec/fixtures/test.json
|