patient_zero 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/patient_zero/analytics/base.rb +3 -1
- data/lib/patient_zero/authorization.rb +3 -1
- data/lib/patient_zero/client.rb +11 -21
- data/lib/patient_zero/configurable.rb +1 -1
- data/lib/patient_zero/organization.rb +2 -1
- data/lib/patient_zero/profile.rb +3 -1
- data/lib/patient_zero/source.rb +3 -1
- data/lib/patient_zero/version.rb +1 -1
- data/spec/patient_zero/analytics/base_spec.rb +4 -4
- data/spec/patient_zero/authorization_spec.rb +2 -2
- data/spec/patient_zero/client_spec.rb +71 -5
- data/spec/patient_zero/organization_spec.rb +4 -4
- data/spec/patient_zero/profile_spec.rb +11 -11
- data/spec/patient_zero/source_spec.rb +6 -6
- 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: a037356146290a626fa56f41f3ea9ac05ef1ba8e
|
4
|
+
data.tar.gz: 140f175a8f2f333105e5ac50b8b4263419ca8bac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e70002f5430e5b3453802ada0c013e9c8154087df702d50b8c21e2c0c310d344a70f32ea89b9822a9a6d2d0de9d3adfdad10115ba7e8eba513cf9acfab3209
|
7
|
+
data.tar.gz: af84b55608d2edfd6f415c883d80eba65f07ffe7f201ad9dd537553f9b131dd1c2abab310d80a9bd6ba10d8c6fd98548d801d33ae59b72b49fe61a84dbecb5e0
|
data/lib/patient_zero/client.rb
CHANGED
@@ -1,43 +1,33 @@
|
|
1
1
|
module PatientZero
|
2
|
-
|
3
|
-
def self.
|
4
|
-
|
2
|
+
module Client
|
3
|
+
def self.included base
|
4
|
+
base.extend self
|
5
|
+
end
|
6
|
+
|
7
|
+
def connection
|
8
|
+
PatientZero.connection ||= Faraday.new(PatientZero.url) do |faraday|
|
5
9
|
faraday.request :url_encoded
|
6
10
|
faraday.response :logger
|
7
11
|
faraday.adapter Faraday.default_adapter
|
8
12
|
end
|
9
13
|
end
|
10
14
|
|
11
|
-
def
|
15
|
+
def parse request
|
12
16
|
response = JSON.parse request.body
|
13
17
|
raise Error, response['error'] unless response['error'].nil?
|
14
18
|
response
|
15
19
|
end
|
16
20
|
|
17
|
-
def self.get *args
|
18
|
-
parse connection.get *args
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.post *args
|
22
|
-
parse connection.post *args
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.put *args
|
26
|
-
parse connection.put *args
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
21
|
def get *args
|
32
|
-
|
22
|
+
parse connection.get *args
|
33
23
|
end
|
34
24
|
|
35
25
|
def post *args
|
36
|
-
|
26
|
+
parse connection.post *args
|
37
27
|
end
|
38
28
|
|
39
29
|
def put *args
|
40
|
-
|
30
|
+
parse connection.put *args
|
41
31
|
end
|
42
32
|
end
|
43
33
|
end
|
data/lib/patient_zero/profile.rb
CHANGED
data/lib/patient_zero/source.rb
CHANGED
data/lib/patient_zero/version.rb
CHANGED
@@ -10,11 +10,11 @@ module PatientZero
|
|
10
10
|
let(:token) { 'token-shmoken' }
|
11
11
|
let(:analytical_data) { { 'stats' => [ { 'id' => source_id, 'platform' => platform, 'name' => name, 'messages' => messages } ] } }
|
12
12
|
subject(:analytics_base) { Base.new token: token, source_id: source_id }
|
13
|
-
before { allow(
|
13
|
+
before { allow(analytics_base).to receive(:get).with('/mobile/api/v1/analytics', anything).and_return analytical_data }
|
14
14
|
|
15
15
|
describe '#name' do
|
16
16
|
it 'calls the analytics API endpoint' do
|
17
|
-
expect(
|
17
|
+
expect(analytics_base).to receive(:get).with('/mobile/api/v1/analytics', anything)
|
18
18
|
analytics_base.name
|
19
19
|
end
|
20
20
|
it 'pulls the name from the analytical_data hash' do
|
@@ -24,7 +24,7 @@ module PatientZero
|
|
24
24
|
|
25
25
|
describe '#platform' do
|
26
26
|
it 'calls the analytics API endpoint' do
|
27
|
-
expect(
|
27
|
+
expect(analytics_base).to receive(:get).with('/mobile/api/v1/analytics', anything)
|
28
28
|
analytics_base.name
|
29
29
|
end
|
30
30
|
it 'pulls the platform from the analytical_data hash' do
|
@@ -34,7 +34,7 @@ module PatientZero
|
|
34
34
|
|
35
35
|
describe '#messages' do
|
36
36
|
it 'calls the analytics API endpoint' do
|
37
|
-
expect(
|
37
|
+
expect(analytics_base).to receive(:get).with('/mobile/api/v1/analytics', anything)
|
38
38
|
analytics_base.name
|
39
39
|
end
|
40
40
|
context 'when there are messages' do
|
@@ -5,9 +5,9 @@ module PatientZero
|
|
5
5
|
describe '.token' do
|
6
6
|
let(:token) { 'token-shmoken' }
|
7
7
|
let(:authorization_response) { response_with_body user_token: token }
|
8
|
-
before{ allow(
|
8
|
+
before{ allow(Authorization.connection).to receive(:post).with('/mobile/api/v1/user/login', anything).and_return authorization_response }
|
9
9
|
it 'calls the login api endpoint' do
|
10
|
-
expect(
|
10
|
+
expect(Authorization.connection).to receive(:post).with('/mobile/api/v1/user/login', anything)
|
11
11
|
Authorization.token
|
12
12
|
end
|
13
13
|
context 'when email and password are correct' do
|
@@ -1,31 +1,97 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module PatientZero
|
4
|
+
class FakeClient
|
5
|
+
include Client
|
6
|
+
end
|
7
|
+
|
4
8
|
describe Client do
|
5
9
|
let(:token) { 'token-shmoken' }
|
6
10
|
let(:body) { "{}" }
|
7
|
-
let(:response) { double body: body }
|
11
|
+
let(:response) { double :response, body: body }
|
12
|
+
let(:connection) { double :conn, get: response, post: response, put: response }
|
8
13
|
|
9
14
|
describe '.connection' do
|
10
15
|
it 'news up a connection to the Viral Heat API' do
|
11
|
-
expect(
|
16
|
+
expect(FakeClient.connection).to be_a Faraday::Connection
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'exists on the instance' do
|
20
|
+
expect { FakeClient.new.connection }.to_not raise_error
|
12
21
|
end
|
13
22
|
end
|
14
23
|
|
15
24
|
describe '.parse' do
|
16
|
-
|
25
|
+
it 'exists on the instance' do
|
26
|
+
expect { FakeClient.new.parse response }.to_not raise_error
|
27
|
+
end
|
17
28
|
context 'when the response contains an error key with nil' do
|
18
29
|
let(:body) { "{\"status\":200,\"error\":null,\"user_token\":\"#{token}\"}" }
|
19
30
|
it 'returns a hash of data' do
|
20
|
-
expect(parse).to be_a Hash
|
31
|
+
expect(FakeClient.parse response).to be_a Hash
|
21
32
|
end
|
22
33
|
end
|
23
34
|
context 'when the response contains an error key that is not nil' do
|
24
35
|
let(:body) { "{\"status\":403,\"error\":\"Invalid login/password\",\"user_token\":null}" }
|
25
36
|
it 'raises an error' do
|
26
|
-
expect { parse }.to raise_error Error
|
37
|
+
expect { FakeClient.parse response }.to raise_error Error
|
27
38
|
end
|
28
39
|
end
|
29
40
|
end
|
41
|
+
|
42
|
+
describe '.get' do
|
43
|
+
before { allow(PatientZero).to receive(:connection).and_return connection }
|
44
|
+
|
45
|
+
it 'delegates to the connection' do
|
46
|
+
expect(PatientZero.connection).to receive(:get).with('an arg') { response }
|
47
|
+
FakeClient.get 'an arg'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'calls parse' do
|
51
|
+
expect(FakeClient).to receive(:parse).with response
|
52
|
+
FakeClient.get 'an arg'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'exists on the instance' do
|
56
|
+
expect { FakeClient.new.get 'an arg' }.to_not raise_error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.post' do
|
61
|
+
before { allow(PatientZero).to receive(:connection).and_return connection }
|
62
|
+
|
63
|
+
it 'delegates to the connection' do
|
64
|
+
expect(PatientZero.connection).to receive(:post).with('an arg') { response }
|
65
|
+
FakeClient.post 'an arg'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'calls parse' do
|
69
|
+
expect(FakeClient).to receive(:parse).with response
|
70
|
+
FakeClient.post 'an arg'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'exists on the instance' do
|
74
|
+
expect { FakeClient.new.post 'an arg' }.to_not raise_error
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '.put' do
|
79
|
+
before { allow(PatientZero).to receive(:connection).and_return connection }
|
80
|
+
|
81
|
+
it 'delegates to the connection' do
|
82
|
+
expect(PatientZero.connection).to receive(:put).with('an arg') { response }
|
83
|
+
FakeClient.put 'an arg'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'calls parse' do
|
87
|
+
expect(FakeClient).to receive(:parse).with response
|
88
|
+
FakeClient.put 'an arg'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'exists on the instance' do
|
92
|
+
expect { FakeClient.new.put 'an arg' }.to_not raise_error
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
30
96
|
end
|
31
97
|
end
|
@@ -20,10 +20,10 @@ module PatientZero
|
|
20
20
|
describe '.all' do
|
21
21
|
let(:organizations) { [organization] }
|
22
22
|
let(:organizations_response) { response_with_body organizations: organizations_response_data }
|
23
|
-
before { allow(
|
23
|
+
before { allow(Organization.connection).to receive(:get).with('/mobile/api/v1/organizations', anything) { organizations_response } }
|
24
24
|
|
25
25
|
it 'calls the organizations api endpoint' do
|
26
|
-
expect(
|
26
|
+
expect(Organization.connection).to receive(:get).with('/mobile/api/v1/organizations', anything)
|
27
27
|
Organization.all
|
28
28
|
end
|
29
29
|
|
@@ -52,10 +52,10 @@ module PatientZero
|
|
52
52
|
describe '#token' do
|
53
53
|
let(:organization_specific_token) { 'organization-token' }
|
54
54
|
let(:switch_response) { response_with_body user_token: organization_specific_token }
|
55
|
-
before { allow(
|
55
|
+
before { allow(Organization.connection).to receive(:get).with("/mobile/api/v1/organizations/#{id}/switch", anything).and_return switch_response }
|
56
56
|
|
57
57
|
it 'calls the organization switch api endpoint' do
|
58
|
-
expect(
|
58
|
+
expect(Organization.connection).to receive(:get).with("/mobile/api/v1/organizations/#{id}/switch", anything)
|
59
59
|
organization.token
|
60
60
|
end
|
61
61
|
|
@@ -21,10 +21,10 @@ module PatientZero
|
|
21
21
|
|
22
22
|
describe '.all' do
|
23
23
|
let(:profile_response) { response_with_body profiles: profiles }
|
24
|
-
before { allow(
|
24
|
+
before { allow(Profile.connection).to receive(:get).with('/social/api/v2/monitoring/profiles', anything) { profile_response } }
|
25
25
|
|
26
26
|
it 'calls the profiles api endpoint' do
|
27
|
-
expect(
|
27
|
+
expect(Profile.connection).to receive(:get).with('/social/api/v2/monitoring/profiles', anything)
|
28
28
|
Profile.all
|
29
29
|
end
|
30
30
|
|
@@ -35,10 +35,10 @@ module PatientZero
|
|
35
35
|
|
36
36
|
describe '.find' do
|
37
37
|
let(:profile_response) { response_with_body profiles: [profile_data] }
|
38
|
-
before { allow(
|
38
|
+
before { allow(Profile.connection).to receive(:get).with('/social/api/v2/monitoring/profiles', anything) { profile_response } }
|
39
39
|
|
40
40
|
it 'calls the profiles api endpoint' do
|
41
|
-
expect(
|
41
|
+
expect(Profile.connection).to receive(:get).with('/social/api/v2/monitoring/profiles', anything)
|
42
42
|
Profile.find id
|
43
43
|
end
|
44
44
|
|
@@ -49,10 +49,10 @@ module PatientZero
|
|
49
49
|
|
50
50
|
describe '.create' do
|
51
51
|
let(:profile_response) { response_with_body profile: profile_data }
|
52
|
-
before { allow(
|
52
|
+
before { allow(Profile.connection).to receive(:post).with('/social/api/v2/monitoring/profiles', anything) { profile_response } }
|
53
53
|
|
54
54
|
it 'calls the profiles api endpoint' do
|
55
|
-
expect(
|
55
|
+
expect(Profile.connection).to receive(:post).with('/social/api/v2/monitoring/profiles', anything)
|
56
56
|
Profile.create profile_data
|
57
57
|
end
|
58
58
|
|
@@ -60,20 +60,20 @@ module PatientZero
|
|
60
60
|
expect(Profile.create(profile_data)).to be_a Profile
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
describe '.update' do
|
65
|
-
let(:params) { {id: 1} }
|
65
|
+
let(:params) { {id: 1} }
|
66
66
|
let(:profile_response) { response_with_body profile: profile_data }
|
67
|
-
before { allow(
|
67
|
+
before { allow(Profile.connection).to receive(:put).with("/social/api/v2/monitoring/profiles/#{params[:id]}", anything) { profile_response } }
|
68
68
|
|
69
69
|
it 'calls the profiles api endpoint' do
|
70
|
-
expect(
|
70
|
+
expect(Profile.connection).to receive(:put).with("/social/api/v2/monitoring/profiles/#{params[:id]}", anything)
|
71
71
|
Profile.update params
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'returns a Profile object' do
|
75
75
|
expect(Profile.update(params)).to be_a Profile
|
76
76
|
end
|
77
|
-
end
|
77
|
+
end
|
78
78
|
end
|
79
79
|
end
|
@@ -18,10 +18,10 @@ module PatientZero
|
|
18
18
|
describe '.all' do
|
19
19
|
before do
|
20
20
|
allow(Authorization).to receive(:token).and_return token
|
21
|
-
allow(
|
21
|
+
allow(Source.connection).to receive(:get).with('/mobile/api/v1/sources/', anything).and_return response_with_body sources: sources_response_data
|
22
22
|
end
|
23
23
|
it 'calls the sources index api' do
|
24
|
-
expect(
|
24
|
+
expect(Source.connection).to receive(:get).with('/mobile/api/v1/sources/', anything)
|
25
25
|
Source.all
|
26
26
|
end
|
27
27
|
it 'calls Authorization.token if no token is passed in' do
|
@@ -35,7 +35,7 @@ module PatientZero
|
|
35
35
|
end
|
36
36
|
context 'when the associated organization token has no sources' do
|
37
37
|
it 'returns an empty array' do
|
38
|
-
allow(
|
38
|
+
allow(Source.connection).to receive(:get).with('/mobile/api/v1/sources/', anything).and_return response_with_body sources: []
|
39
39
|
expect(Source.all).to be_empty
|
40
40
|
end
|
41
41
|
end
|
@@ -44,10 +44,10 @@ module PatientZero
|
|
44
44
|
describe '.find' do
|
45
45
|
before do
|
46
46
|
allow(Authorization).to receive(:token).and_return token
|
47
|
-
allow(
|
47
|
+
allow(Source.connection).to receive(:get).with('/mobile/api/v1/sources/show/', anything).and_return response_with_body source: source_response_data
|
48
48
|
end
|
49
49
|
it 'calls the sources show api' do
|
50
|
-
expect(
|
50
|
+
expect(Source.connection).to receive(:get).with('/mobile/api/v1/sources/show/', anything)
|
51
51
|
Source.find id, token
|
52
52
|
end
|
53
53
|
context 'when the source exists' do
|
@@ -57,7 +57,7 @@ module PatientZero
|
|
57
57
|
end
|
58
58
|
context 'when no source exists' do
|
59
59
|
it 'throws an PatientZero::Error' do
|
60
|
-
allow(
|
60
|
+
allow(Source).to receive(:get).and_raise Error, 'The source could not be found. Please check your inputs.'
|
61
61
|
expect{ Source.find id, token }.to raise_error PatientZero::NotFoundError
|
62
62
|
end
|
63
63
|
end
|