plangrade-ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.gitignore +2 -0
- data/.travis.yml +20 -0
- data/Gemfile +7 -0
- data/README.md +190 -53
- data/Rakefile +10 -1
- data/lib/plangrade/api/company.rb +4 -4
- data/lib/plangrade/api/participant.rb +6 -5
- data/lib/plangrade/api/user.rb +3 -3
- data/lib/plangrade/oauth2_client.rb +1 -0
- data/lib/plangrade/resources/company.rb +1 -1
- data/lib/plangrade/resources/participant.rb +2 -2
- data/lib/plangrade/resources/user.rb +3 -3
- data/lib/plangrade/ruby/version.rb +1 -1
- data/plangrade-ruby.gemspec +6 -10
- data/spec/api/company_spec.rb +72 -0
- data/spec/api/participant_spec.rb +79 -0
- data/spec/api/user_spec.rb +65 -0
- data/spec/client_spec.rb +332 -0
- data/spec/error_spec.rb +88 -0
- data/spec/fixtures/company.json +1 -0
- data/{test → spec}/fixtures/one_user.yml +0 -0
- data/spec/fixtures/participant.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/http_adapter_spec.rb +109 -0
- data/spec/oauth2_client_spec.rb +109 -0
- data/spec/resources/base_spec.rb +190 -0
- data/spec/resources/company_spec.rb +135 -0
- data/spec/resources/identity_map_spec.rb +127 -0
- data/spec/resources/participant_spec.rb +151 -0
- data/spec/resources/user_spec.rb +152 -0
- data/spec/spec_helper.rb +73 -0
- data/{test → spec}/user/user_test.rb +0 -0
- data.tar.gz.sig +0 -0
- metadata +101 -97
- metadata.gz.sig +0 -0
- data/test/test_helper.rb +0 -9
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
21
|
+
|
22
|
+
describe Plangrade::Resources::Participant do
|
23
|
+
|
24
|
+
before :all do
|
25
|
+
Plangrade.configure do |conf|
|
26
|
+
conf.access_token = 'TolNOFka9Uls2DxahNi78A'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
after :all do
|
31
|
+
Plangrade.reset!
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'class methods' do
|
35
|
+
|
36
|
+
subject { Plangrade::Resources::Participant }
|
37
|
+
|
38
|
+
describe '#create' do
|
39
|
+
it 'creates a new participant' do
|
40
|
+
stub_request(:post, "https://plangrade.com/api/v1/participants").with(
|
41
|
+
:body => { :first_name => "Johnny", :last_name => "Compliance", :email => 'compliance@plangrade.com', :phone => "123456789", :employee_id => "0", :company_id => "1", :street1 => "1234 Fake St.", :street2 => "", :city => "Fake", :state => "UT", :zip => "12345", :dob => "1985-12-31", :ssn => "1234" },
|
42
|
+
:headers => {
|
43
|
+
'Accept' => 'application/json',
|
44
|
+
'Authorization' => "Bearer #{Plangrade.access_token}",
|
45
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
46
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
47
|
+
}
|
48
|
+
).to_return(
|
49
|
+
:status => 201,
|
50
|
+
:body => '',
|
51
|
+
:headers => { 'Location' => 'https://plangrade.com/api/v1/participants/3'}
|
52
|
+
)
|
53
|
+
subject.create(1, "Johnny", "Compliance", "1234 Fake St.", "", "Fake", "UT", "12345", "1985-12-31", "1234", "compliance@plangrade.com", 123456789, 0)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'new participant object with id' do
|
59
|
+
|
60
|
+
before :each do
|
61
|
+
Plangrade::Resources::Participant.identity_map.purge!
|
62
|
+
end
|
63
|
+
|
64
|
+
subject { Plangrade::Resources::Participant.new(:id => 3) }
|
65
|
+
|
66
|
+
describe "#id" do
|
67
|
+
it 'returns id' do
|
68
|
+
expect(subject.id).to eq 3
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'hydrated participant object' do
|
74
|
+
subject { Plangrade::Resources::Participant.new(MultiJson.load(fixture('participant.json'), :symbolize_keys => true)) }
|
75
|
+
|
76
|
+
describe "#id" do
|
77
|
+
it 'returns id' do
|
78
|
+
expect(subject.id).to eq 3
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#email" do
|
83
|
+
it 'returns email address' do
|
84
|
+
stub_request(:get, "https://plangrade.com/api/v1/participants/3").
|
85
|
+
with(:headers => {
|
86
|
+
'Accept'=>'application/json',
|
87
|
+
'Authorization'=>"Bearer #{Plangrade.access_token}",
|
88
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
89
|
+
}).to_return(
|
90
|
+
:status => 200,
|
91
|
+
:body => fixture('participant.json'),
|
92
|
+
:headers => {}
|
93
|
+
)
|
94
|
+
expect(subject.email).to eq 'compliance@plangrade.com'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#delete" do
|
99
|
+
it 'deletes participant' do
|
100
|
+
stub_request(:delete, "https://plangrade.com/api/v1/participants/3").
|
101
|
+
with(:headers => {
|
102
|
+
'Accept'=>'application/json',
|
103
|
+
'Authorization'=>"Bearer #{Plangrade.access_token}",
|
104
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
105
|
+
}).to_return(
|
106
|
+
:status => 200,
|
107
|
+
:body => '',
|
108
|
+
:headers => {}
|
109
|
+
)
|
110
|
+
subject.delete!
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#archive" do
|
115
|
+
it 'archive participant' do
|
116
|
+
stub_request(:get, "https://plangrade.com/api/v1/participants/archive?participant_id=3").
|
117
|
+
with(:headers => {
|
118
|
+
'Accept'=>'application/json',
|
119
|
+
'Authorization'=>"Bearer #{Plangrade.access_token}",
|
120
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
121
|
+
}).to_return(
|
122
|
+
:status => 200,
|
123
|
+
:body => '',
|
124
|
+
:headers => {}
|
125
|
+
)
|
126
|
+
expect(subject.id).to eq 3
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#update' do
|
131
|
+
context 'with id as an integer' do
|
132
|
+
it 'updates participant' do
|
133
|
+
stub_request(:put, "https://plangrade.com/api/v1/participants/3").with(
|
134
|
+
:body => { :first_name => 'smithy' },
|
135
|
+
:headers => {
|
136
|
+
'Accept' => 'application/json',
|
137
|
+
'Authorization' => "Bearer #{Plangrade.access_token}",
|
138
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
139
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
140
|
+
}
|
141
|
+
).to_return(
|
142
|
+
:status => 200,
|
143
|
+
:body => '',
|
144
|
+
:headers => { 'Location' => 'https://plangrade.com/api/v1/participants/3'}
|
145
|
+
)
|
146
|
+
subject.update!(:first_name => 'smithy')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
21
|
+
|
22
|
+
describe Plangrade::Resources::User do
|
23
|
+
|
24
|
+
before :all do
|
25
|
+
Plangrade.configure do |conf|
|
26
|
+
conf.access_token = 'TolNOFka9Uls2DxahNi78A'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
after :all do
|
31
|
+
Plangrade.reset!
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'class methods' do
|
35
|
+
|
36
|
+
subject { Plangrade::Resources::User }
|
37
|
+
|
38
|
+
describe '#create' do
|
39
|
+
it 'creates a new user' do
|
40
|
+
stub_request(:post, "https://plangrade.com/api/v1/users").with(
|
41
|
+
:body => { :name => "Compliance Man", :email => 'compliance@plangrade.com' },
|
42
|
+
:headers => {
|
43
|
+
'Accept' => 'application/json',
|
44
|
+
'Authorization' => "Bearer #{Plangrade.access_token}",
|
45
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
46
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
47
|
+
}
|
48
|
+
).to_return(
|
49
|
+
:status => 201,
|
50
|
+
:body => '',
|
51
|
+
:headers => { 'Location' => 'https://plangrade.com/api/v1/users/364'}
|
52
|
+
)
|
53
|
+
subject.create("compliance@plangrade.com", "Compliance Man")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#current_user' do
|
58
|
+
it "should fetch authenticated user's data" do
|
59
|
+
stub_request(:get, "https://plangrade.com/api/v1/me").with(
|
60
|
+
:headers => {
|
61
|
+
'Accept' => 'application/json',
|
62
|
+
'Authorization' => "Bearer #{Plangrade.access_token}",
|
63
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
64
|
+
}
|
65
|
+
).to_return(
|
66
|
+
:status => 200,
|
67
|
+
:body => fixture('user.json'),
|
68
|
+
:headers => {}
|
69
|
+
)
|
70
|
+
subject.current_user
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'new user object with id' do
|
76
|
+
|
77
|
+
before :each do
|
78
|
+
Plangrade::Resources::User.identity_map.purge!
|
79
|
+
end
|
80
|
+
|
81
|
+
subject { Plangrade::Resources::User.new(:id => 1) }
|
82
|
+
|
83
|
+
describe "#id" do
|
84
|
+
it 'returns id' do
|
85
|
+
expect(subject.id).to eq 1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'hydrated user object' do
|
91
|
+
subject { Plangrade::Resources::User.new(MultiJson.load(fixture('user.json'), :symbolize_keys => true)) }
|
92
|
+
|
93
|
+
describe "#id" do
|
94
|
+
it 'returns id' do
|
95
|
+
expect(subject.id).to eq 2
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#email" do
|
100
|
+
it 'returns email address' do
|
101
|
+
stub_request(:get, "https://plangrade.com/api/v1/users/2").
|
102
|
+
with(:headers => {
|
103
|
+
'Accept'=>'application/json',
|
104
|
+
'Authorization'=>"Bearer #{Plangrade.access_token}",
|
105
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
106
|
+
}).to_return(
|
107
|
+
:status => 200,
|
108
|
+
:body => fixture('user.json'),
|
109
|
+
:headers => {}
|
110
|
+
)
|
111
|
+
expect(subject.email).to eq 'compliance@plangrade.com'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#delete" do
|
116
|
+
it 'deletes user' do
|
117
|
+
stub_request(:delete, "https://plangrade.com/api/v1/users/2").
|
118
|
+
with(:headers => {
|
119
|
+
'Accept'=>'application/json',
|
120
|
+
'Authorization'=>"Bearer #{Plangrade.access_token}",
|
121
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
122
|
+
}).to_return(
|
123
|
+
:status => 200,
|
124
|
+
:body => '',
|
125
|
+
:headers => {}
|
126
|
+
)
|
127
|
+
subject.delete!
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#update' do
|
132
|
+
context 'with id as an integer' do
|
133
|
+
it 'updates user' do
|
134
|
+
stub_request(:put, "https://plangrade.com/api/v1/users/2").with(
|
135
|
+
:body => { :name => 'smithy' },
|
136
|
+
:headers => {
|
137
|
+
'Accept' => 'application/json',
|
138
|
+
'Authorization' => "Bearer #{Plangrade.access_token}",
|
139
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
140
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
141
|
+
}
|
142
|
+
).to_return(
|
143
|
+
:status => 200,
|
144
|
+
:body => '',
|
145
|
+
:headers => { 'Location' => 'https://plangrade.com/api/v1/users/2'}
|
146
|
+
)
|
147
|
+
subject.update!(:name => 'smithy')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require 'simplecov'
|
21
|
+
require 'coveralls'
|
22
|
+
|
23
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
24
|
+
SimpleCov::Formatter::HTMLFormatter,
|
25
|
+
Coveralls::SimpleCov::Formatter
|
26
|
+
]
|
27
|
+
SimpleCov.start
|
28
|
+
|
29
|
+
require 'plangrade'
|
30
|
+
require 'rspec'
|
31
|
+
require 'rspec/autorun'
|
32
|
+
require 'webmock/rspec'
|
33
|
+
|
34
|
+
WebMock.disable_net_connect!(:allow => 'coveralls.io')
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
config.mock_with :rspec
|
38
|
+
config.expect_with :rspec do |c|
|
39
|
+
c.syntax = :expect
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def stub_delete(path='')
|
44
|
+
stub_request(:delete, "https://plangrade.com#{path}")
|
45
|
+
end
|
46
|
+
|
47
|
+
def stub_get(path='')
|
48
|
+
stub_request(:get, "https://plangrade.com#{path}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def stub_post(path='')
|
52
|
+
stub_request(:post, "https://plangrade.com#{path}")
|
53
|
+
end
|
54
|
+
|
55
|
+
def stub_put(path='')
|
56
|
+
stub_request(:put, "https://plangrade.com#{path}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def fixture_path
|
60
|
+
File.expand_path("../fixtures", __FILE__)
|
61
|
+
end
|
62
|
+
|
63
|
+
def mock_path
|
64
|
+
File.expand_path("../mocks", __FILE__)
|
65
|
+
end
|
66
|
+
|
67
|
+
def fixture(file)
|
68
|
+
File.new("#{fixture_path}/#{file}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def upload(file)
|
72
|
+
File.new("#{mock_path}/#{file}")
|
73
|
+
end
|
File without changes
|
data.tar.gz.sig
CHANGED
Binary file
|