authenticator-client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +22 -0
- data/README.md +71 -2
- data/authenticator-client.gemspec +4 -1
- data/lib/authenticator/client/account.rb +1 -0
- data/lib/authenticator/client/authenticate_response.rb +15 -0
- data/lib/authenticator/client/base.rb +10 -69
- data/lib/authenticator/client/version.rb +1 -1
- data/spec/authenticator/client/base_spec.rb +13 -13
- data/spec/authenticator/client_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +35 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd9129412c0abea844885d8fe90ace9b3d54a979
|
4
|
+
data.tar.gz: 032fc0192b99e8c46778bff82b2463545dc7bccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29cf3f15a440e926218eb9a5be081250237ba7049149267780498c2b17651fb0c1c7053ad0207d94abc0912c0cae9d1f9476d20f267cb3ccf2b93ab8fcc3675b
|
7
|
+
data.tar.gz: e30fc2bb3983fc6be64aabf729535e38eb72209ed0529fa8c0e9aac581d46541c8b84c90a49e1f8c68ecade932a789beea74e2758d49e21467eaa80a122666ca
|
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.1.0
|
5
|
+
|
6
|
+
gemfile:
|
7
|
+
- Gemfile
|
8
|
+
|
9
|
+
cache: bundler
|
10
|
+
|
11
|
+
env:
|
12
|
+
matrix:
|
13
|
+
- TEST_SUITE="spec"
|
14
|
+
|
15
|
+
|
16
|
+
before_script: "bundle update"
|
17
|
+
|
18
|
+
script:
|
19
|
+
- bundle exec rake $TEST_SUITE
|
20
|
+
|
21
|
+
notifications:
|
22
|
+
email: false
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Authenticator::Client
|
2
|
+
[![Build Status](https://travis-ci.org/johnmcconnell/authenticator-client.svg?branch=master)]
|
3
|
+
(https://travis-ci.org/johnmcconnell/authenticator-client)
|
4
|
+
[![Coverage
|
5
|
+
Status](https://coveralls.io/repos/johnmcconnell/authenticator-client/badge.png?branch=master)](https://coveralls.io/r/johnmcconnell/authenticator-client?branch=master)
|
2
6
|
|
3
|
-
|
7
|
+
## Description
|
8
|
+
This gem is designed to be used with
|
9
|
+
[Account Authenticator](https://account-authenticator.herokuapp.com/)
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -20,7 +26,70 @@ Or install it yourself as:
|
|
20
26
|
|
21
27
|
## Usage
|
22
28
|
|
23
|
-
|
29
|
+
### Creating a client:
|
30
|
+
|
31
|
+
```
|
32
|
+
config = {
|
33
|
+
api_key: 'api_key',
|
34
|
+
api_password: 'api_password',
|
35
|
+
host: 'http://account-authenticator.herokuapp.com'
|
36
|
+
}
|
37
|
+
|
38
|
+
Authenticator::Client.register_config(:config_key, config)
|
39
|
+
Authenticator::Client.new(:config_key)
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
### Creating an account:
|
44
|
+
|
45
|
+
```
|
46
|
+
client.create(Account.new(username, password))
|
47
|
+
#=> '{
|
48
|
+
"id":6,
|
49
|
+
"username":"new_username",
|
50
|
+
"created_at":"2015-01-04T20:36:28.339Z",
|
51
|
+
"updated_at":"2015-01-04T20:36:28.339Z"
|
52
|
+
}'
|
53
|
+
```
|
54
|
+
|
55
|
+
### Authenticating an account:
|
56
|
+
|
57
|
+
```
|
58
|
+
client.authenticate(account)
|
59
|
+
#=> '{"authenticated":true}'
|
60
|
+
```
|
61
|
+
|
62
|
+
### Reading accounts:
|
63
|
+
|
64
|
+
```
|
65
|
+
client.all
|
66
|
+
#=> '{"accounts":[
|
67
|
+
{ "id":6,
|
68
|
+
"username":"new_username",
|
69
|
+
"created_at":"2015-01-04T20:36:28.339Z",
|
70
|
+
"updated_at":"2015-01-04T20:36:28.339Z" }
|
71
|
+
]}'
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
### Updating an account:
|
76
|
+
|
77
|
+
```
|
78
|
+
client.update(id, account)
|
79
|
+
#=> '{
|
80
|
+
"id":7,
|
81
|
+
"username":"new_username_1",
|
82
|
+
"created_at":"2015-01-04T20:36:28.949Z",
|
83
|
+
"updated_at":"2015-01-04T20:36:28.949Z"
|
84
|
+
}'
|
85
|
+
```
|
86
|
+
|
87
|
+
### Deleting an account:
|
88
|
+
|
89
|
+
```
|
90
|
+
client.destroy(id)
|
91
|
+
#=> '{"id":10}'
|
92
|
+
```
|
24
93
|
|
25
94
|
## Contributing
|
26
95
|
|
@@ -19,8 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency 'rest-client', '~> 1.7.2'
|
22
|
+
spec.add_dependency 'json_client', '~> 0.0.1'
|
23
|
+
|
24
|
+
spec.add_development_dependency "simplecov", "~> 0.8.0"
|
25
|
+
spec.add_development_dependency "coveralls", "~> 0.7.0"
|
22
26
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
24
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
28
|
spec.add_development_dependency "rspec"
|
26
29
|
spec.add_development_dependency "rspec-collection_matchers"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json_client'
|
2
|
+
|
3
|
+
module Authenticator
|
4
|
+
module Client
|
5
|
+
class AuthenticateResponse < JsonClient::BaseResponses::Response
|
6
|
+
def initialize(body, code)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def auth_success?
|
11
|
+
json['authenticated'] == true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,91 +1,32 @@
|
|
1
1
|
require 'rest_client'
|
2
|
+
require 'json_client'
|
3
|
+
require_relative 'authenticate_response'
|
2
4
|
|
3
5
|
module Authenticator
|
4
6
|
module Client
|
5
|
-
class Base
|
6
|
-
attr_reader :api_key, :api_password, :host
|
7
|
-
|
7
|
+
class Base < JsonClient::Base
|
8
8
|
def initialize(config)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
validate_variables
|
13
|
-
end
|
14
|
-
|
15
|
-
def all
|
16
|
-
uri = account_path
|
17
|
-
RestClient.get uri, params: auth_params
|
18
|
-
end
|
19
|
-
|
20
|
-
def show(id)
|
21
|
-
uri = account_path(id)
|
22
|
-
RestClient.get uri, params: auth_params
|
23
|
-
end
|
24
|
-
|
25
|
-
def create(account)
|
26
|
-
uri = account_path
|
27
|
-
RestClient.post(
|
28
|
-
uri,
|
29
|
-
auth_params.merge(account.to_params).to_json,
|
30
|
-
content_type: :json,
|
31
|
-
accept: :json
|
9
|
+
super(
|
10
|
+
JsonClient::Pather.new(config[:host], 'api/v1', 'accounts'),
|
11
|
+
config
|
32
12
|
)
|
33
13
|
end
|
34
14
|
|
35
15
|
def authenticate(account)
|
36
16
|
uri = authenticate_path
|
37
|
-
RestClient.post(
|
38
|
-
uri,
|
39
|
-
auth_params.merge(account.to_params).to_json,
|
40
|
-
content_type: :json,
|
41
|
-
accept: :json
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
def update(id, account)
|
46
|
-
uri = account_path(id)
|
47
|
-
RestClient.put(
|
17
|
+
response = RestClient.post(
|
48
18
|
uri,
|
49
|
-
auth_params.merge(account.
|
19
|
+
auth_params.merge(account.to_h).to_json,
|
50
20
|
content_type: :json,
|
51
21
|
accept: :json
|
52
22
|
)
|
53
|
-
|
54
|
-
|
55
|
-
def destroy(id)
|
56
|
-
uri = account_path(id)
|
57
|
-
RestClient.delete(
|
58
|
-
uri, params: auth_params
|
59
|
-
)
|
23
|
+
AuthenticateResponse.new(response.body, response.code)
|
60
24
|
end
|
61
25
|
|
62
26
|
protected
|
63
27
|
|
64
28
|
def authenticate_path
|
65
|
-
"#{host}/api/v1/authentications/authenticate"
|
66
|
-
end
|
67
|
-
|
68
|
-
def account_path(id = nil)
|
69
|
-
if id.nil?
|
70
|
-
"#{host}/api/v1/accounts"
|
71
|
-
else
|
72
|
-
"#{host}/api/v1/accounts/#{id}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def auth_params
|
77
|
-
{
|
78
|
-
api_key: api_key,
|
79
|
-
api_password: api_password
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def validate_variables
|
86
|
-
fail 'host must be set' if host.nil?
|
87
|
-
fail 'api_key must be set' if api_key.nil?
|
88
|
-
fail 'api_password must be set' if api_key.nil?
|
29
|
+
"#{pather.host}/api/v1/authentications/authenticate"
|
89
30
|
end
|
90
31
|
end
|
91
32
|
end
|
@@ -41,7 +41,7 @@ describe Authenticator::Client::Base do
|
|
41
41
|
describe '#all' do
|
42
42
|
it 'fetches all the accounts' do
|
43
43
|
VCR.use_cassette('all_success') do
|
44
|
-
response =
|
44
|
+
response = subject.index.json
|
45
45
|
|
46
46
|
expect(response['accounts']).not_to be nil
|
47
47
|
end
|
@@ -51,11 +51,10 @@ describe Authenticator::Client::Base do
|
|
51
51
|
describe '#authenticate' do
|
52
52
|
it 'creates an account' do
|
53
53
|
VCR.use_cassette('authenticate_success') do
|
54
|
-
response =
|
55
|
-
subject.authenticate(account)
|
56
|
-
)
|
54
|
+
response = subject.authenticate(account)
|
57
55
|
|
58
|
-
expect(response['authenticated']).to eq true
|
56
|
+
expect(response.json['authenticated']).to eq true
|
57
|
+
expect(response.auth_success?).to eq true
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
@@ -63,9 +62,7 @@ describe Authenticator::Client::Base do
|
|
63
62
|
describe '#create' do
|
64
63
|
it 'creates an account' do
|
65
64
|
VCR.use_cassette('create_success') do
|
66
|
-
response =
|
67
|
-
subject.create(account)
|
68
|
-
)
|
65
|
+
response = subject.create(account).json
|
69
66
|
|
70
67
|
expect(response['username']).to eq 'new_username'
|
71
68
|
expect(response['id']).not_to be nil
|
@@ -78,9 +75,12 @@ describe Authenticator::Client::Base do
|
|
78
75
|
describe '#show' do
|
79
76
|
it 'fetches the account' do
|
80
77
|
VCR.use_cassette('show_success') do
|
81
|
-
response =
|
78
|
+
response = subject.show(6).json
|
82
79
|
|
83
80
|
expect(response['username']).to eq 'new_username'
|
81
|
+
expect(response['id']).to be 6
|
82
|
+
expect(response['created_at']).to eq '2015-01-04T20:36:28.339Z'
|
83
|
+
expect(response['updated_at']).to eq '2015-01-04T20:36:28.339Z'
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -88,8 +88,8 @@ describe Authenticator::Client::Base do
|
|
88
88
|
describe '#update' do
|
89
89
|
it 'updates the account' do
|
90
90
|
VCR.use_cassette('update_success') do
|
91
|
-
id =
|
92
|
-
response =
|
91
|
+
id = subject.create(new_account).json['id']
|
92
|
+
response = subject.update(id, updated_account).json
|
93
93
|
|
94
94
|
expect(response['username']).to eq updated_account.username
|
95
95
|
expect(response['id']).to eq id
|
@@ -100,8 +100,8 @@ describe Authenticator::Client::Base do
|
|
100
100
|
describe '#destroy' do
|
101
101
|
it 'destroys the account' do
|
102
102
|
VCR.use_cassette('destroy_success') do
|
103
|
-
id =
|
104
|
-
response =
|
103
|
+
id = subject.create(destroy_account).json['id']
|
104
|
+
response = subject.destroy(id).json
|
105
105
|
|
106
106
|
expect(response['id']).to eq id
|
107
107
|
end
|
@@ -21,7 +21,7 @@ describe Authenticator::Client do
|
|
21
21
|
it 'registers a configuration to be used when invoked with ::new' do
|
22
22
|
described_class.register_config(:test, config)
|
23
23
|
client = described_class.new(:test)
|
24
|
-
expect(client.host).to eq config[:host]
|
24
|
+
expect(client.pather.host).to eq config[:host]
|
25
25
|
expect(client.api_key).to eq config[:api_key]
|
26
26
|
expect(client.api_password).to eq config[:api_password]
|
27
27
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authenticator-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johnmcconnell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -25,19 +25,47 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.7.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: json_client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.0
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
68
|
+
version: 0.7.0
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +144,7 @@ extensions: []
|
|
116
144
|
extra_rdoc_files: []
|
117
145
|
files:
|
118
146
|
- ".gitignore"
|
147
|
+
- ".travis.yml"
|
119
148
|
- Gemfile
|
120
149
|
- LICENSE.txt
|
121
150
|
- README.md
|
@@ -123,6 +152,7 @@ files:
|
|
123
152
|
- authenticator-client.gemspec
|
124
153
|
- lib/authenticator/client.rb
|
125
154
|
- lib/authenticator/client/account.rb
|
155
|
+
- lib/authenticator/client/authenticate_response.rb
|
126
156
|
- lib/authenticator/client/base.rb
|
127
157
|
- lib/authenticator/client/version.rb
|
128
158
|
- spec/authenticator/client/base_spec.rb
|