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,79 @@
|
|
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
|
+
require 'ostruct'
|
22
|
+
|
23
|
+
describe Plangrade::Api::Participant do
|
24
|
+
|
25
|
+
before :all do
|
26
|
+
@client = Plangrade::Client.new(
|
27
|
+
:site_url => 'https://plangrade.com',
|
28
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
29
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
30
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { @client }
|
35
|
+
|
36
|
+
describe 'create_participant' do
|
37
|
+
it 'makes an http request' do
|
38
|
+
params = {:company_id => 1, :employee_id => 0, :ssn => '1234', :first_name => 'Joe', :last_name => 'Compliance', :street1 => '1234 Fake St.', :city => 'Fake', :state => 'UT', :zip => '84606', :dob => '1983-12-31', :email => 'compliance@plangrade.com', :phone => 1234567890}
|
39
|
+
@client.should_receive(:post).with('/api/v1/participants', params)
|
40
|
+
@client.create_participant(params)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'update_participant' do
|
45
|
+
it 'makes an http request' do
|
46
|
+
params = {:employee_id => 0, :first_name => 'John'}
|
47
|
+
@client.should_receive(:put).with('/api/v1/participants/1', params)
|
48
|
+
@client.update_participant(1, params)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'archive_participant' do
|
53
|
+
it 'makes an http request' do
|
54
|
+
@client.should_receive(:get).with('/api/v1/participants/archive?participant_id=1')
|
55
|
+
@client.archive_participant(1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'delete_participant' do
|
60
|
+
it 'makes an http request' do
|
61
|
+
@client.should_receive(:delete).with('/api/v1/participants/1')
|
62
|
+
@client.delete_participant(1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'get_participant' do
|
67
|
+
it 'makes an http request' do
|
68
|
+
@client.should_receive(:get).with('/api/v1/participants/1')
|
69
|
+
@client.get_participant(1)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'all_participants' do
|
74
|
+
it 'makes an http request' do
|
75
|
+
@client.should_receive(:get).with('/api/v1/participants?company_id=1')
|
76
|
+
@client.all_participants(:company_id => 1)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
require 'ostruct'
|
22
|
+
|
23
|
+
describe Plangrade::Api::User do
|
24
|
+
|
25
|
+
before :all do
|
26
|
+
@client = Plangrade::Client.new(
|
27
|
+
:site_url => 'https://plangrade.com',
|
28
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
29
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
30
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { @client }
|
35
|
+
|
36
|
+
describe 'create_user' do
|
37
|
+
it 'makes an http request' do
|
38
|
+
params = {:name => 'topher', :email => 'compliance@plangrade.com'}
|
39
|
+
@client.should_receive(:post).with('/api/v1/users', params)
|
40
|
+
@client.create_user(params)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'update_user' do
|
45
|
+
it 'makes an http request' do
|
46
|
+
params = {:name => 'christopher'}
|
47
|
+
@client.should_receive(:put).with('/api/v1/users/1', params)
|
48
|
+
@client.update_user(1, params)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'delete_user' do
|
53
|
+
it 'makes an http request' do
|
54
|
+
@client.should_receive(:delete).with('/api/v1/users/1')
|
55
|
+
@client.delete_user(1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'current_user' do
|
60
|
+
it 'makes an http request' do
|
61
|
+
@client.should_receive(:get).with('/api/v1/me')
|
62
|
+
@client.current_user
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,332 @@
|
|
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::Client do
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
@configuration = {
|
26
|
+
:site_url => 'https://plangrade.com',
|
27
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
28
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
29
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A',
|
30
|
+
:connection_options => { :max_redirects => 5, :use_ssl => true },
|
31
|
+
:default_headers => {"Accept"=>"application/json", "User-Agent"=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"}
|
32
|
+
}
|
33
|
+
|
34
|
+
Plangrade.configure do |config|
|
35
|
+
@configuration.each do |key, val|
|
36
|
+
config.send("#{key}=", val)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
after :each do
|
42
|
+
Plangrade.reset!
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { Plangrade::Client.new(@configuration) }
|
46
|
+
|
47
|
+
context "with module configuration" do
|
48
|
+
|
49
|
+
before :each do
|
50
|
+
@default_conf = {
|
51
|
+
:site_url => nil,
|
52
|
+
:client_id => nil,
|
53
|
+
:client_secret => nil,
|
54
|
+
:access_token => nil,
|
55
|
+
:default_headers => {"Accept"=>"application/json", "User-Agent"=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"},
|
56
|
+
:connection_options => {}
|
57
|
+
}
|
58
|
+
Plangrade.configure do |config|
|
59
|
+
Plangrade::Configurable.keys.each do |key|
|
60
|
+
config.send("#{key}=", @default_conf[key])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
after do
|
66
|
+
Plangrade.reset!
|
67
|
+
end
|
68
|
+
|
69
|
+
it "inherits the module configuration" do
|
70
|
+
client = Plangrade::Client.new
|
71
|
+
@default_conf.each do |key, value|
|
72
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with initialization options" do
|
77
|
+
before(:all) do
|
78
|
+
@conf = {
|
79
|
+
:site_url => 'https://plangrade.com',
|
80
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
81
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
82
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A',
|
83
|
+
:default_headers => {"Accept"=>"application/json", "User-Agent"=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"},
|
84
|
+
:connection_options => { :max_redirects => 5, :use_ssl => true }
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
context "during initialization" do
|
89
|
+
it "overrides the module configuration" do
|
90
|
+
client = Plangrade::Client.new(@conf)
|
91
|
+
Plangrade::Configurable.keys.each do |key|
|
92
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq @conf[key]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "after initialization" do
|
98
|
+
it "overrides the module configuration" do
|
99
|
+
Plangrade.configure {|c| c.connection_options = {}}
|
100
|
+
client = Plangrade::Client.new
|
101
|
+
client.configure do |config|
|
102
|
+
@conf.each do |key, value|
|
103
|
+
config.send("#{key}=", value)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
Plangrade::Configurable.keys.each do |key|
|
107
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq @conf[key]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
describe "#connection_options" do
|
117
|
+
context "with default connection options" do
|
118
|
+
it "returns empty hash" do
|
119
|
+
expect(subject.connection_options).to eq({ :max_redirects => 5, :use_ssl => true })
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "with custom connection options" do
|
124
|
+
it "returns default options" do
|
125
|
+
subject.connection_options = { :max_redirects => 5, :use_ssl => true }
|
126
|
+
expect(subject.connection_options).to eq({:max_redirects => 5, :use_ssl => true})
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#request" do
|
132
|
+
context "when method is not supported" do
|
133
|
+
it "raises an error" do
|
134
|
+
expect {subject.send(:request, :patch, '/')}.to raise_error
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when method is get" do
|
139
|
+
it "returns an http response" do
|
140
|
+
path = '/oauth/authorize'
|
141
|
+
params = {:client_id => '001337', :client_secret => 'abcxyz'}
|
142
|
+
method = :get
|
143
|
+
|
144
|
+
normalized_path = '/oauth/authorize?client_id=001337&client_secret=abcxyz'
|
145
|
+
|
146
|
+
stub_request(:get, "https://plangrade.com/oauth/authorize?client_id=001337&client_secret=abcxyz").with(
|
147
|
+
:headers => {
|
148
|
+
'Accept'=>'application/json',
|
149
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
150
|
+
})
|
151
|
+
response = subject.send(:request, method, path, params)
|
152
|
+
|
153
|
+
expect(response.code).to eq 200
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when method is delete" do
|
158
|
+
it "returns an http response" do
|
159
|
+
path = '/users/1'
|
160
|
+
|
161
|
+
stub_request(:delete, "https://plangrade.com/users/1").with(
|
162
|
+
:headers => {
|
163
|
+
'Accept'=>'application/json',
|
164
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
165
|
+
}).to_return(:status => 200, :body => "", :headers => {})
|
166
|
+
|
167
|
+
response = subject.send(:request, :delete, path)
|
168
|
+
expect(response.code).to eq 200
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "when method is post" do
|
173
|
+
it "returns an http response" do
|
174
|
+
path = '/participants'
|
175
|
+
params = {:company_id =>1, :first_name => 'Christopher'}
|
176
|
+
query = Addressable::URI.form_encode(params)
|
177
|
+
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
178
|
+
|
179
|
+
stub_request(:post, "https://plangrade.com/participants").with(
|
180
|
+
:body => {
|
181
|
+
"company_id"=>"1",
|
182
|
+
"first_name"=>"Christopher"
|
183
|
+
},
|
184
|
+
:headers => {
|
185
|
+
'Accept'=>'application/json',
|
186
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
187
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
188
|
+
}).to_return(:status => 200, :body => "", :headers => {})
|
189
|
+
|
190
|
+
response =subject.send(:request, :post, path, params)
|
191
|
+
expect(response.code).to eq 200
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "when method is put" do
|
196
|
+
it "returns an http response" do
|
197
|
+
path = '/users/1'
|
198
|
+
params = {:name => 'christopher reynoso'}
|
199
|
+
query = Addressable::URI.form_encode(params)
|
200
|
+
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
201
|
+
|
202
|
+
stub_request(:put, "https://plangrade.com/users/1").with(
|
203
|
+
:body => {
|
204
|
+
"name" => "christopher reynoso"
|
205
|
+
},
|
206
|
+
:headers => {
|
207
|
+
'Accept'=>'application/json',
|
208
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
209
|
+
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
|
210
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
211
|
+
}).
|
212
|
+
to_return(:status => 200, :body => "", :headers => {})
|
213
|
+
|
214
|
+
response = subject.send(:request, :put, path, params)
|
215
|
+
expect(response.code).to eq 200
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it "follows redirect" do
|
220
|
+
params = {:company_id => "1", :first_name => 'Christopher'}
|
221
|
+
stub_request(:post, "https://plangrade.com/participants").with(
|
222
|
+
:body => params,
|
223
|
+
:headers => {
|
224
|
+
'Accept' =>'application/json',
|
225
|
+
'Accept-Encoding' => 'gzip, deflate',
|
226
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
227
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
228
|
+
}
|
229
|
+
).to_return(:status => 303, :body => "", :headers => { 'Location' => 'https://plangrade.com/users'})
|
230
|
+
|
231
|
+
stub_request(:get, "https://plangrade.com/users").
|
232
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"}).
|
233
|
+
to_return(:status => 200, :body => "", :headers => {})
|
234
|
+
params = {:company_id => 1, :first_name => 'Christopher'}
|
235
|
+
response = subject.send(:request, :post, '/participants', params)
|
236
|
+
|
237
|
+
expect(response.code).to eq 200
|
238
|
+
end
|
239
|
+
|
240
|
+
it "respects the redirect limit " do
|
241
|
+
subject.connection_options = { :max_redirects => 1 }
|
242
|
+
|
243
|
+
stub_request(:get, "https://plangrade.com/participants").
|
244
|
+
with(
|
245
|
+
:headers => {
|
246
|
+
'Accept' => 'application/json',
|
247
|
+
'Accept-Encoding'=> 'gzip, deflate',
|
248
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
249
|
+
}
|
250
|
+
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://plangrade.com/users'})
|
251
|
+
|
252
|
+
stub_request(:get, "https://plangrade.com/users").
|
253
|
+
with(
|
254
|
+
:headers => {
|
255
|
+
'Accept' => 'application/json',
|
256
|
+
'Accept-Encoding'=> 'gzip, deflate',
|
257
|
+
'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
258
|
+
}
|
259
|
+
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://plangrade.com/companies'})
|
260
|
+
|
261
|
+
expect { subject.send(:request, :get, '/participants') }.to raise_error(RestClient::MaxRedirectsReached)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'http request' do
|
266
|
+
describe "#post" do
|
267
|
+
it "makes an http POST request" do
|
268
|
+
stub_post('/users').with(
|
269
|
+
:headers => {
|
270
|
+
'Accept'=>'application/json',
|
271
|
+
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
|
272
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
273
|
+
'User-Agent'=>"Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
274
|
+
},
|
275
|
+
:body => { :name => 'christopher reynoso' }).to_return({
|
276
|
+
:status => 200, :body => "", :headers => {}
|
277
|
+
})
|
278
|
+
subject.post('/users', { :name => 'christopher reynoso'})
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe "#put" do
|
283
|
+
it "makes an http PUT request" do
|
284
|
+
stub_put('/users/1').with(
|
285
|
+
:headers => {
|
286
|
+
'Accept'=>'application/json',
|
287
|
+
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
|
288
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
289
|
+
'User-Agent'=> "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
|
290
|
+
},
|
291
|
+
:body => { :name => 'topher reynoso' }).to_return(
|
292
|
+
:status => 200, :body => "", :headers => {})
|
293
|
+
|
294
|
+
subject.put('/users/1', { :name => 'topher reynoso'})
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe "#get" do
|
299
|
+
it "makes an http GET request" do
|
300
|
+
stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' })
|
301
|
+
subject.get('/users/1')
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe "#delete" do
|
306
|
+
it "makes an http DELETE request" do
|
307
|
+
stub_delete('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' })
|
308
|
+
subject.delete('/users/1')
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe 'with invalid token' do
|
313
|
+
it 'raises exception' do
|
314
|
+
stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' }).to_return(
|
315
|
+
:body => '{ "response": { "message": "Token not found.", "code": 16, "stat": "fail" } }',
|
316
|
+
:status => 401)
|
317
|
+
|
318
|
+
expect(subject.get('/users/1')).to eq('{ "response": { "message": "Token not found.", "code": 16, "stat": "fail" } }')
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe 'with too many requests' do
|
323
|
+
it 'raises exception' do
|
324
|
+
stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' }).to_return(
|
325
|
+
:body => '{ "response": { "message": "Rate limited due to excessive requests.", "code": 33, "stat": "fail" } }',
|
326
|
+
:status => 429
|
327
|
+
)
|
328
|
+
expect(subject.get('/users/1')).to eq('{ "response": { "message": "Rate limited due to excessive requests.", "code": 33, "stat": "fail" } }')
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
data/spec/error_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
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::Error do
|
23
|
+
|
24
|
+
subject { Plangrade::Error }
|
25
|
+
|
26
|
+
describe 'from status' do
|
27
|
+
|
28
|
+
context 'status unknown' do
|
29
|
+
it 'returns ApiError' do
|
30
|
+
expect(subject.from_status).to eq Plangrade::Error::ApiError
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'status 400' do
|
35
|
+
it 'returns BadRequest' do
|
36
|
+
expect(subject.from_status(400)).to eq Plangrade::Error::BadRequest
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'status 401' do
|
41
|
+
it 'returns Unauthorized' do
|
42
|
+
expect(subject.from_status(401)).to eq Plangrade::Error::Unauthorized
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'status 403' do
|
47
|
+
it 'returns Forbidden' do
|
48
|
+
expect(subject.from_status(403)).to eq Plangrade::Error::Forbidden
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'status 404' do
|
53
|
+
it 'returns NotFound' do
|
54
|
+
expect(subject.from_status(404)).to eq Plangrade::Error::NotFound
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'status 406' do
|
59
|
+
it 'returns NotAcceptable' do
|
60
|
+
expect(subject.from_status(406)).to eq Plangrade::Error::NotAcceptable
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'status 429' do
|
65
|
+
it 'returns RateLimitExceeded' do
|
66
|
+
expect(subject.from_status(429)).to eq Plangrade::Error::RateLimitExceeded
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'status 500' do
|
71
|
+
it 'returns InternalServerError' do
|
72
|
+
expect(subject.from_status(500)).to eq Plangrade::Error::InternalServerError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'status 502' do
|
77
|
+
it 'returns BadGateway' do
|
78
|
+
expect(subject.from_status(502)).to eq Plangrade::Error::BadGateway
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'status 503' do
|
83
|
+
it 'returns ServiceUnavailable' do
|
84
|
+
expect(subject.from_status(503)).to eq Plangrade::Error::ServiceUnavailable
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"name":"plangrade, llc","id":4,"ein":"123456789"}
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{"first_name":"Johnny","last_name":"Compliance","id":3,"employee_id":0,"company_id":1,"email":"compliance@plangrade.com","phone":123456789,"street1":"1234 Fake St.","street2":"","city":"Fake","state":"UT","zip":"12345","dob":"1985-12-31","ssn":"1234"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"name":"Smith","id":2,"email":"compliance@plangrade.com"}
|
@@ -0,0 +1,109 @@
|
|
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
|
+
require 'plangrade/http_adapter'
|
22
|
+
|
23
|
+
describe Plangrade::HttpAdapter do
|
24
|
+
|
25
|
+
before :all do
|
26
|
+
Plangrade.configure do |conf|
|
27
|
+
conf.access_token = 'TolNOFka9Uls2DxahNi78A'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "initialization" do
|
32
|
+
context "with user options" do
|
33
|
+
|
34
|
+
before do
|
35
|
+
@options = {
|
36
|
+
:verify_ssl => false,
|
37
|
+
:max_redirects => 2
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
subject { @conn = Plangrade::HttpAdapter.new('https://www.example.com', @options) }
|
42
|
+
|
43
|
+
it "overrides default options" do
|
44
|
+
expect(subject.instance_variable_get(:"@connection_options")).to eq @options
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with invalid url" do
|
49
|
+
it "should raise argument error" do
|
50
|
+
expect { Plangrade::HttpAdapter.new('www.example.com') }.to raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with no options" do
|
56
|
+
|
57
|
+
subject { @conn = Plangrade::HttpAdapter.new('https://plangrade.com') }
|
58
|
+
|
59
|
+
describe "#scheme" do
|
60
|
+
it "returns the http scheme" do
|
61
|
+
expect(subject.scheme).to eq 'https'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#host" do
|
66
|
+
it "returns the host server" do
|
67
|
+
expect(subject.host).to eq 'plangrade.com'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "site_url" do
|
72
|
+
it "returns site_url" do
|
73
|
+
expect(subject.site_url).to eq 'https://plangrade.com'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "site_url=" do
|
78
|
+
it "sets new site_url on client" do
|
79
|
+
subject.site_url = 'https://github.com/topherreynoso'
|
80
|
+
expect(subject.site_url).to eq 'https://github.com/topherreynoso'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "connection_options=" do
|
85
|
+
it "sets new connection_options" do
|
86
|
+
subject.connection_options = { :max_redirects => 6 }
|
87
|
+
expect(subject.connection_options).to eq({ :max_redirects => 6 })
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should raise error" do
|
91
|
+
expect { subject.connection_options = '' }.to raise_error(ArgumentError)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#absolute_url" do
|
96
|
+
context "with no parameters" do
|
97
|
+
it "returns a uri without path" do
|
98
|
+
expect(subject.send(:absolute_url)).to eq "https://plangrade.com"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with parameters" do
|
103
|
+
it "returns a uri with path" do
|
104
|
+
expect(subject.send(:absolute_url, '/oauth/authorize')).to eq "https://plangrade.com/oauth/authorize"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|