gun_broker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/gun_broker/user.rb +3 -2
- data/lib/gun_broker/version.rb +1 -1
- data/spec/gun_broker/user_spec.rb +19 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 263f58913c30a8bc6cd92e93f7639764e36d5419
|
4
|
+
data.tar.gz: b81f8988a611e475e3d0c2c5dba5ab27f2d77493
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75d66025a4a1678065a866fd879edb113b5662a4fe02f99dbfa7cc13d41b4149397ca8f0e56721497a4b7e2625a72c9b7f776e59e33d64e0d77b03c60d888ce6
|
7
|
+
data.tar.gz: 7e3283d6755afd90d704bdbd502e495e9b00458875c4d4b2b6517de0197b43de23bcf02c62057a6ea243524452d11374bfa4591d8c78c94062cf421e0e8cecf1
|
data/README.md
CHANGED
@@ -50,8 +50,16 @@ return an array of `GunBroker::Item` instances.
|
|
50
50
|
|
51
51
|
```ruby
|
52
52
|
user.items # => [GunBroker::Item, ...]
|
53
|
-
user.
|
54
|
-
user.
|
53
|
+
user.items_unsold # => [GunBroker::Item, ...]
|
54
|
+
user.items_sold # => [GunBroker::Item, ...]
|
55
|
+
```
|
56
|
+
|
57
|
+
To revoke the access token, call `User#deauthenticate!`. This method is also aliased as `#revoke_access_token!`.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
user.token # => 'user-access-token'
|
61
|
+
user.deauthenticate!
|
62
|
+
user.token # => nil
|
55
63
|
```
|
56
64
|
|
57
65
|
### GunBroker::Item
|
data/lib/gun_broker/user.rb
CHANGED
@@ -21,18 +21,19 @@ module GunBroker
|
|
21
21
|
@token = nil
|
22
22
|
true # Explicit `true` so this method won't return the `nil` set above.
|
23
23
|
end
|
24
|
+
alias_method :revoke_access_token!, :deauthenticate!
|
24
25
|
|
25
26
|
def items
|
26
27
|
response = GunBroker::API.get('/Items', { 'SellerName' => @username }, { 'X-AccessToken' => @token })
|
27
28
|
response['results'].map { |result| GunBroker::Item.new(result) }
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
+
def items_unsold
|
31
32
|
response = GunBroker::API.get('/ItemsUnsold', {}, { 'X-AccessToken' => @token })
|
32
33
|
response['results'].map { |result| GunBroker::Item.new(result) }
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
+
def items_sold
|
36
37
|
response = GunBroker::API.get('/ItemsSold', {}, { 'X-AccessToken' => @token })
|
37
38
|
response['results'].map { |result| GunBroker::Item.new(result) }
|
38
39
|
end
|
data/lib/gun_broker/version.rb
CHANGED
@@ -83,6 +83,17 @@ describe GunBroker::User do
|
|
83
83
|
expect { user.deauthenticate! }.to raise_error(GunBroker::Error::NotAuthorized)
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
it 'should have a #revoke_access_token! alias' do
|
88
|
+
user = GunBroker::User.new(username, token: token)
|
89
|
+
|
90
|
+
stub_request(:delete, endpoint)
|
91
|
+
.with(headers: headers)
|
92
|
+
.to_return(body: response_fixture('deauthenticate'))
|
93
|
+
|
94
|
+
expect(user.revoke_access_token!).to eq(true)
|
95
|
+
expect(user.token).to be_nil
|
96
|
+
end
|
86
97
|
end
|
87
98
|
|
88
99
|
context '#items' do
|
@@ -118,7 +129,7 @@ describe GunBroker::User do
|
|
118
129
|
end
|
119
130
|
end
|
120
131
|
|
121
|
-
context '#
|
132
|
+
context '#items_unsold' do
|
122
133
|
let(:endpoint) { [GunBroker::API::GUNBROKER_API, '/ItemsUnsold'].join }
|
123
134
|
|
124
135
|
context 'on success' do
|
@@ -128,8 +139,8 @@ describe GunBroker::User do
|
|
128
139
|
.to_return(body: response_fixture('items'))
|
129
140
|
|
130
141
|
user = GunBroker::User.new(username, token: token)
|
131
|
-
expect(user.
|
132
|
-
expect(user.
|
142
|
+
expect(user.items_unsold).not_to be_empty
|
143
|
+
expect(user.items_unsold.first).to be_a(GunBroker::Item)
|
133
144
|
end
|
134
145
|
end
|
135
146
|
|
@@ -140,12 +151,12 @@ describe GunBroker::User do
|
|
140
151
|
.to_return(body: response_fixture('not_authorized'), status: 401)
|
141
152
|
|
142
153
|
user = GunBroker::User.new(username, token: token)
|
143
|
-
expect { user.
|
154
|
+
expect { user.items_unsold }.to raise_error(GunBroker::Error::NotAuthorized)
|
144
155
|
end
|
145
156
|
end
|
146
157
|
end
|
147
158
|
|
148
|
-
context '#
|
159
|
+
context '#items_sold' do
|
149
160
|
let(:endpoint) { [GunBroker::API::GUNBROKER_API, '/ItemsSold'].join }
|
150
161
|
|
151
162
|
context 'on success' do
|
@@ -155,8 +166,8 @@ describe GunBroker::User do
|
|
155
166
|
.to_return(body: response_fixture('items'))
|
156
167
|
|
157
168
|
user = GunBroker::User.new(username, token: token)
|
158
|
-
expect(user.
|
159
|
-
expect(user.
|
169
|
+
expect(user.items_sold).not_to be_empty
|
170
|
+
expect(user.items_sold.first).to be_a(GunBroker::Item)
|
160
171
|
end
|
161
172
|
end
|
162
173
|
|
@@ -167,7 +178,7 @@ describe GunBroker::User do
|
|
167
178
|
.to_return(body: response_fixture('not_authorized'), status: 401)
|
168
179
|
|
169
180
|
user = GunBroker::User.new(username, token: token)
|
170
|
-
expect { user.
|
181
|
+
expect { user.items_sold }.to raise_error(GunBroker::Error::NotAuthorized)
|
171
182
|
end
|
172
183
|
end
|
173
184
|
end
|