gun_broker 0.4.10 → 0.4.11
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.rb +8 -0
- data/lib/gun_broker/version.rb +1 -1
- data/spec/gun_broker/user_spec.rb +35 -0
- 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: 9dd98bdbf4372b9b9dd1b9bd985c9ca25e4c8fb5
|
4
|
+
data.tar.gz: f9f75bb3681735ae157a23a40a7e179a5ed6f1c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 488c92d33bb197bb568e8a528fb9d6d65331d08e00d13623cd90a6a0437b389e505d4fc88a2832dbc23933535867ea744dcc09863d34d8529197a921910b87ef
|
7
|
+
data.tar.gz: c341c260e445d26c5a0036687c6329faba10996ef8f48b44f50d2717203c8f85680c9bfc9f991dfa0837f80378200055bf185020e4a02e3f8c81bdb6d792055b
|
data/lib/gun_broker/user.rb
CHANGED
@@ -23,6 +23,14 @@ module GunBroker
|
|
23
23
|
@token = auth_options[:token] || auth_options['token']
|
24
24
|
end
|
25
25
|
|
26
|
+
# Returns the GunBroker.com user ID. Uses {User#contact_info} to get the user details (therefore, the User must be authenticated).
|
27
|
+
# @raise [GunBroker::Error::NotAuthorized] If the User has not yet been authenticated.
|
28
|
+
# @raise [GunBroker::Error::RequestError] If there's an issue with the request (usually a `5xx` response).
|
29
|
+
# @return [String] The User's GunBroker.com user ID.
|
30
|
+
def id
|
31
|
+
contact_info['userID']
|
32
|
+
end
|
33
|
+
|
26
34
|
# Authenticates with the GunBroker API server and saves the returned access {#token}.
|
27
35
|
# @note {API#post! POST} /Users/AccessToken
|
28
36
|
# @raise [GunBroker::Error::NotAuthorized] If the username/password is invalid.
|
data/lib/gun_broker/version.rb
CHANGED
@@ -23,6 +23,41 @@ describe GunBroker::User do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
context '#id' do
|
27
|
+
let(:endpoint) { [GunBroker::API::GUNBROKER_API, '/Users/ContactInfo'].join }
|
28
|
+
|
29
|
+
context 'on success' do
|
30
|
+
it 'should return the user ID' do
|
31
|
+
user = GunBroker::User.new(username, token: token)
|
32
|
+
|
33
|
+
stub_request(:get, endpoint)
|
34
|
+
.with(
|
35
|
+
headers: headers('X-AccessToken' => token),
|
36
|
+
query: { 'UserName' => user.username }
|
37
|
+
)
|
38
|
+
.to_return(body: response_fixture('contact_info'))
|
39
|
+
|
40
|
+
contact_info = JSON.parse(response_fixture('contact_info'))
|
41
|
+
expect(user.id).to eq(contact_info['userID'])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'not authenticated' do
|
46
|
+
it 'should raise a GunBroker::Error::NotAuthorized exception' do
|
47
|
+
user = GunBroker::User.new(username, token: token)
|
48
|
+
|
49
|
+
stub_request(:get, endpoint)
|
50
|
+
.with(
|
51
|
+
headers: headers('X-AccessToken' => token),
|
52
|
+
query: { 'UserName' => user.username }
|
53
|
+
)
|
54
|
+
.to_raise(GunBroker::Error::NotAuthorized)
|
55
|
+
|
56
|
+
expect { user.id }.to raise_error(GunBroker::Error::NotAuthorized)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
26
61
|
context '#token_header' do
|
27
62
|
it 'raises an error if @token nil' do
|
28
63
|
user = GunBroker::User.new(username, token: nil)
|
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.
|
4
|
+
version: 0.4.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|