lifen 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +11 -11
- data/lib/lifen.rb +7 -4
- data/lib/lifen/app_authenticated_client.rb +15 -27
- data/lib/lifen/client.rb +44 -0
- data/lib/lifen/configuration.rb +1 -1
- data/lib/lifen/error.rb +1 -0
- data/lib/lifen/flow.rb +41 -44
- data/lib/lifen/flows.rb +4 -8
- data/lib/lifen/status.rb +5 -3
- data/lib/lifen/token.rb +44 -0
- data/lib/lifen/user.rb +34 -23
- data/lib/lifen/user_authenticated_client.rb +17 -27
- data/lib/lifen/version.rb +1 -1
- data/lifen.gemspec +1 -0
- data/spec/cassettes/flows/attach_users/invalid_flow_uuid.yml +11 -13
- data/spec/cassettes/flows/attach_users/invalid_user_uuid.yml +12 -14
- data/spec/cassettes/flows/attach_users/valid.yml +14 -16
- data/spec/cassettes/flows/create.yml +13 -15
- data/spec/cassettes/flows/create_with_users.yml +12 -13
- data/spec/cassettes/flows/detach_users/valid.yml +14 -16
- data/spec/cassettes/flows/internal_error.yml +4 -2
- data/spec/cassettes/flows/internal_error_without_trace_id.yml +4 -2
- data/spec/cassettes/flows/invalid_token.yml +18 -14
- data/spec/cassettes/flows/valid_token.yml +14 -17
- data/spec/cassettes/messages/valid_message.yml +13 -15
- data/spec/cassettes/users/create/existing_user.yml +11 -11
- data/spec/cassettes/users/create/invalid_token.yml +16 -10
- data/spec/cassettes/users/create/missing_fields.yml +19 -14
- data/spec/cassettes/users/create/valid_attributes.yml +12 -12
- data/spec/cassettes/users/{refresh_unread_messages → status/refresh}/invalid_token.yml +16 -12
- data/spec/cassettes/users/{refresh_unread_messages → status/refresh}/valid_token.yml +10 -12
- data/spec/cassettes/users/token/refresh/invalid_user_uuid.yml +40 -0
- data/spec/cassettes/users/{refresh/invalid_user_uuid.yml → token/refresh/valid_user_uuid.yml} +16 -15
- data/spec/flows_spec.rb +43 -25
- data/spec/messages_spec.rb +10 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/users_spec.rb +46 -26
- metadata +25 -13
- data/lib/lifen/authentication.rb +0 -29
- data/spec/cassettes/flows/detach_users/valid_again.yml +0 -57
- data/spec/cassettes/users/refresh/valid_user_uuid.yml +0 -54
@@ -8,15 +8,15 @@ http_interactions:
|
|
8
8
|
string: "{}"
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- Faraday v0.
|
12
|
-
|
13
|
-
- invalid_token
|
11
|
+
- Faraday v0.10.0
|
12
|
+
Authorization:
|
13
|
+
- Bearer invalid_token
|
14
14
|
Content-Type:
|
15
15
|
- application/json
|
16
|
+
Accept:
|
17
|
+
- application/json
|
16
18
|
Accept-Encoding:
|
17
19
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
-
Accept:
|
19
|
-
- "*/*"
|
20
20
|
response:
|
21
21
|
status:
|
22
22
|
code: 401
|
@@ -27,30 +27,34 @@ http_interactions:
|
|
27
27
|
X-B3-Sampled:
|
28
28
|
- '1'
|
29
29
|
X-B3-Spanid:
|
30
|
-
-
|
30
|
+
- 62fa861f3ed63e22
|
31
31
|
X-B3-Traceid:
|
32
|
-
-
|
32
|
+
- 62fa861f3ed63e22
|
33
33
|
X-Content-Type-Options:
|
34
34
|
- nosniff
|
35
35
|
X-Xss-Protection:
|
36
36
|
- 1; mode=block
|
37
37
|
Cache-Control:
|
38
38
|
- no-cache, no-store, max-age=0, must-revalidate
|
39
|
+
- no-store
|
39
40
|
Pragma:
|
40
41
|
- no-cache
|
42
|
+
- no-cache
|
41
43
|
Expires:
|
42
44
|
- '0'
|
45
|
+
Www-Authenticate:
|
46
|
+
- 'Bearer realm="oauth", error="invalid_token", error_description="Invalid access
|
47
|
+
token: invalid_token"'
|
43
48
|
Content-Type:
|
44
49
|
- application/json;charset=UTF-8
|
45
50
|
Transfer-Encoding:
|
46
51
|
- chunked
|
47
52
|
Date:
|
48
|
-
-
|
49
|
-
Connection:
|
50
|
-
- close
|
53
|
+
- Fri, 09 Dec 2016 13:57:42 GMT
|
51
54
|
body:
|
52
55
|
encoding: UTF-8
|
53
|
-
string: '{"
|
56
|
+
string: '{"error":"invalid_token","error_description":"Invalid access token:
|
57
|
+
invalid_token"}'
|
54
58
|
http_version:
|
55
|
-
recorded_at:
|
59
|
+
recorded_at: Fri, 09 Dec 2016 13:55:51 GMT
|
56
60
|
recorded_with: VCR 3.0.3
|
@@ -8,15 +8,15 @@ http_interactions:
|
|
8
8
|
string: "{}"
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- Faraday v0.
|
12
|
-
|
13
|
-
- valid_token
|
11
|
+
- Faraday v0.10.0
|
12
|
+
Authorization:
|
13
|
+
- Bearer valid_token
|
14
14
|
Content-Type:
|
15
15
|
- application/json
|
16
|
+
Accept:
|
17
|
+
- application/json
|
16
18
|
Accept-Encoding:
|
17
19
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
-
Accept:
|
19
|
-
- "*/*"
|
20
20
|
response:
|
21
21
|
status:
|
22
22
|
code: 200
|
@@ -27,9 +27,9 @@ http_interactions:
|
|
27
27
|
X-B3-Sampled:
|
28
28
|
- '1'
|
29
29
|
X-B3-Spanid:
|
30
|
-
-
|
30
|
+
- e12babb877ed2906
|
31
31
|
X-B3-Traceid:
|
32
|
-
-
|
32
|
+
- e12babb877ed2906
|
33
33
|
X-Content-Type-Options:
|
34
34
|
- nosniff
|
35
35
|
X-Xss-Protection:
|
@@ -41,16 +41,14 @@ http_interactions:
|
|
41
41
|
Expires:
|
42
42
|
- '0'
|
43
43
|
Content-Type:
|
44
|
-
- application/
|
44
|
+
- application/json;charset=UTF-8
|
45
45
|
Transfer-Encoding:
|
46
46
|
- chunked
|
47
47
|
Date:
|
48
|
-
-
|
49
|
-
Connection:
|
50
|
-
- close
|
48
|
+
- Fri, 09 Dec 2016 13:58:05 GMT
|
51
49
|
body:
|
52
50
|
encoding: UTF-8
|
53
51
|
string: '{"unread":2}'
|
54
52
|
http_version:
|
55
|
-
recorded_at:
|
53
|
+
recorded_at: Fri, 09 Dec 2016 13:56:13 GMT
|
56
54
|
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://develop.lifen.fr/oauth/admin/third_party/access_token?accountUuid=invalid-user-uuid
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: "{}"
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.10.0
|
12
|
+
Authorization:
|
13
|
+
- Bearer valid_application_access_token
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
Accept:
|
17
|
+
- application/json
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 500
|
23
|
+
message: Internal Server Error
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- Apache-Coyote/1.1
|
27
|
+
Content-Type:
|
28
|
+
- application/json;charset=UTF-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Date:
|
32
|
+
- Fri, 09 Dec 2016 13:49:20 GMT
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: '{"timestamp":"2016-12-09T13:49:20.369+0000","status":500,"error":"Internal
|
36
|
+
Server Error","exception":"java.lang.IllegalArgumentException","message":"Invalid
|
37
|
+
UUID string: invalid-user-uuid","path":"/oauth2/oauth/admin/third_party/access_token"}'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Fri, 09 Dec 2016 13:47:29 GMT
|
40
|
+
recorded_with: VCR 3.0.3
|
data/spec/cassettes/users/{refresh/invalid_user_uuid.yml → token/refresh/valid_user_uuid.yml}
RENAMED
@@ -2,42 +2,44 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://develop.lifen.fr/
|
5
|
+
uri: https://develop.lifen.fr/oauth/admin/third_party/access_token?accountUuid=11e6be14-8267-25ee-a3bd-0242ac110002
|
6
6
|
body:
|
7
7
|
encoding: UTF-8
|
8
|
-
string:
|
8
|
+
string: "{}"
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- Faraday v0.
|
12
|
-
|
13
|
-
-
|
11
|
+
- Faraday v0.10.0
|
12
|
+
Authorization:
|
13
|
+
- Bearer valid_application_access_token
|
14
14
|
Content-Type:
|
15
15
|
- application/json
|
16
|
+
Accept:
|
17
|
+
- application/json
|
16
18
|
Accept-Encoding:
|
17
19
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
-
Accept:
|
19
|
-
- "*/*"
|
20
20
|
response:
|
21
21
|
status:
|
22
|
-
code:
|
23
|
-
message:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
24
|
headers:
|
25
25
|
Server:
|
26
26
|
- Apache-Coyote/1.1
|
27
27
|
X-B3-Sampled:
|
28
28
|
- '1'
|
29
29
|
X-B3-Spanid:
|
30
|
-
-
|
30
|
+
- 8a24ea0924af60c5
|
31
31
|
X-B3-Traceid:
|
32
|
-
-
|
32
|
+
- 8a24ea0924af60c5
|
33
33
|
X-Content-Type-Options:
|
34
34
|
- nosniff
|
35
35
|
X-Xss-Protection:
|
36
36
|
- 1; mode=block
|
37
37
|
Cache-Control:
|
38
38
|
- no-cache, no-store, max-age=0, must-revalidate
|
39
|
+
- no-store
|
39
40
|
Pragma:
|
40
41
|
- no-cache
|
42
|
+
- no-cache
|
41
43
|
Expires:
|
42
44
|
- '0'
|
43
45
|
Content-Type:
|
@@ -45,11 +47,10 @@ http_interactions:
|
|
45
47
|
Transfer-Encoding:
|
46
48
|
- chunked
|
47
49
|
Date:
|
48
|
-
-
|
50
|
+
- Fri, 09 Dec 2016 13:50:37 GMT
|
49
51
|
body:
|
50
52
|
encoding: UTF-8
|
51
|
-
string: '{"
|
52
|
-
Request","code":"error.badrequest","X-B3-TraceId":"7911bb796330c549","X-B3-SpanId":"7911bb796330c549"}'
|
53
|
+
string: '{"access_token":"762dd9a0-d0cc-45c9-b6e6-faf988167efb","token_type":"bearer","expires_in":86399,"scope":"public"}'
|
53
54
|
http_version:
|
54
|
-
recorded_at:
|
55
|
+
recorded_at: Fri, 09 Dec 2016 13:48:46 GMT
|
55
56
|
recorded_with: VCR 3.0.3
|
data/spec/flows_spec.rb
CHANGED
@@ -2,17 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Lifen::Flow do
|
4
4
|
|
5
|
-
|
5
|
+
let(:valid_token_value) { "valid_token" }
|
6
|
+
|
7
|
+
let(:invalid_token) { Lifen::Token.new(value: "invalid_token", expires_at: Time.now.to_i + 60) }
|
8
|
+
let(:valid_token) { Lifen::Token.new(value: valid_token_value, expires_at: Time.now.to_i + 60) }
|
9
|
+
|
10
|
+
let(:user) { Lifen::User.new(token: valid_token, uuid: "25588996-4ff1-2dbb-9643-eabb809fa654") }
|
6
11
|
|
7
12
|
describe "index" do
|
8
13
|
|
9
14
|
context "invalid token" do
|
10
15
|
it 'raises an error' do
|
11
|
-
user = Lifen::User.new(token:
|
16
|
+
user = Lifen::User.new(token: invalid_token)
|
12
17
|
|
13
18
|
expect{
|
14
19
|
VCR.use_cassette "flows/invalid_token" do
|
15
|
-
|
20
|
+
user.flows
|
16
21
|
end
|
17
22
|
}.to raise_error(Lifen::UnauthorizedError)
|
18
23
|
end
|
@@ -24,7 +29,7 @@ describe Lifen::Flow do
|
|
24
29
|
|
25
30
|
expect{
|
26
31
|
VCR.use_cassette "flows/internal_error" do
|
27
|
-
|
32
|
+
user.flows
|
28
33
|
end
|
29
34
|
}.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: 2e2eac3a7e3fa2)")
|
30
35
|
end
|
@@ -32,7 +37,7 @@ describe Lifen::Flow do
|
|
32
37
|
it 'raises an error (without trace ID)' do
|
33
38
|
expect{
|
34
39
|
VCR.use_cassette "flows/internal_error_without_trace_id" do
|
35
|
-
|
40
|
+
user.flows
|
36
41
|
end
|
37
42
|
}.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: unknown)")
|
38
43
|
end
|
@@ -41,6 +46,8 @@ describe Lifen::Flow do
|
|
41
46
|
|
42
47
|
context "valid token" do
|
43
48
|
|
49
|
+
# let(:valid_token_value) { "REPLACE_ME" }
|
50
|
+
|
44
51
|
before(:each) do
|
45
52
|
VCR.use_cassette "flows/valid_token" do
|
46
53
|
@flows = user.flows
|
@@ -49,12 +56,12 @@ describe Lifen::Flow do
|
|
49
56
|
@flow = @flows.first
|
50
57
|
end
|
51
58
|
|
52
|
-
it { expect(@flows.size).to eq(
|
59
|
+
it { expect(@flows.size).to eq(1) }
|
53
60
|
|
54
61
|
it 'has valid attributes' do
|
55
62
|
expect(@flow.user).to eq(user)
|
56
|
-
expect(@flow.uuid).to eq("
|
57
|
-
expect(@flow.title).to
|
63
|
+
expect(@flow.uuid).to eq("11e6be18-7a35-d759-9177-0242ac110002")
|
64
|
+
expect(@flow.title).to eq("Rspec Flow")
|
58
65
|
end
|
59
66
|
|
60
67
|
end
|
@@ -62,6 +69,9 @@ describe Lifen::Flow do
|
|
62
69
|
end
|
63
70
|
|
64
71
|
describe 'create' do
|
72
|
+
|
73
|
+
# let(:valid_token_value) { "REPLACE_ME" }
|
74
|
+
|
65
75
|
let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow") }
|
66
76
|
|
67
77
|
it 'creates a flow' do
|
@@ -77,10 +87,10 @@ describe Lifen::Flow do
|
|
77
87
|
|
78
88
|
context 'attaching users at the same time' do
|
79
89
|
|
80
|
-
let(:user) { Lifen::User.new(token:
|
81
|
-
let(:other_user) { Lifen::User.new(uuid: "
|
90
|
+
let(:user) { Lifen::User.new(token: valid_token, uuid: "11e6be14-8267-25ee-a3bd-0242ac110002") }
|
91
|
+
let(:other_user) { Lifen::User.new(uuid: "11e6be15-0fb1-0a21-a3bd-0242ac110002") }
|
82
92
|
|
83
|
-
let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow",
|
93
|
+
let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow", users: [other_user]) }
|
84
94
|
|
85
95
|
it 'creates a flow with attached users' do
|
86
96
|
|
@@ -88,13 +98,13 @@ describe Lifen::Flow do
|
|
88
98
|
flow.create
|
89
99
|
end
|
90
100
|
|
91
|
-
expect(flow.
|
92
|
-
first_user = flow.
|
101
|
+
expect(flow.users.size).to eq(2)
|
102
|
+
first_user = flow.users.first
|
93
103
|
|
94
|
-
expect(first_user.uuid).to eq("
|
95
|
-
expect(first_user.first_name).to eq("
|
104
|
+
expect(first_user.uuid).to eq("11e6be14-8267-25ee-a3bd-0242ac110002")
|
105
|
+
expect(first_user.first_name).to eq("Existing")
|
96
106
|
|
97
|
-
expect(flow.
|
107
|
+
expect(flow.users.last.uuid).to eq("11e6be15-0fb1-0a21-a3bd-0242ac110002")
|
98
108
|
end
|
99
109
|
|
100
110
|
end
|
@@ -102,13 +112,15 @@ describe Lifen::Flow do
|
|
102
112
|
|
103
113
|
describe 'attach_users' do
|
104
114
|
|
115
|
+
# let(:valid_token_value) { "REPLACE_ME" }
|
116
|
+
|
105
117
|
context 'invalid flow uuid' do
|
106
118
|
let(:flow) { Lifen::Flow.new(uuid: "invalid-uuid", user: user) }
|
107
119
|
|
108
120
|
it 'raises an error' do
|
109
121
|
expect{
|
110
122
|
VCR.use_cassette "flows/attach_users/invalid_flow_uuid" do
|
111
|
-
flow.attach_users
|
123
|
+
flow.attach_users(user)
|
112
124
|
end
|
113
125
|
}.to raise_error(Lifen::InvalidParamsError)
|
114
126
|
end
|
@@ -116,7 +128,9 @@ describe Lifen::Flow do
|
|
116
128
|
end
|
117
129
|
|
118
130
|
context 'valid flow uuid' do
|
119
|
-
|
131
|
+
|
132
|
+
let(:flow) { Lifen::Flow.new(uuid: "11e6be18-7a35-d759-9177-0242ac110002", user: user) }
|
133
|
+
let(:other_user) { Lifen::User.new(uuid: "11e6be15-0fb1-0a21-a3bd-0242ac110002") }
|
120
134
|
|
121
135
|
context 'invalid user params' do
|
122
136
|
|
@@ -125,7 +139,7 @@ describe Lifen::Flow do
|
|
125
139
|
|
126
140
|
expect{
|
127
141
|
VCR.use_cassette "flows/attach_users/invalid_user_uuid" do
|
128
|
-
flow.attach_users
|
142
|
+
flow.attach_users(invalid_user)
|
129
143
|
end
|
130
144
|
}.to raise_error(Lifen::InvalidParamsError)
|
131
145
|
end
|
@@ -133,11 +147,12 @@ describe Lifen::Flow do
|
|
133
147
|
|
134
148
|
it 'attaches a user' do
|
135
149
|
VCR.use_cassette "flows/attach_users/valid" do
|
136
|
-
flow.attach_users
|
150
|
+
flow.attach_users(other_user)
|
137
151
|
end
|
138
152
|
|
139
|
-
expect(flow.
|
140
|
-
expect(flow.
|
153
|
+
expect(flow.users.size).to eq(2)
|
154
|
+
expect(flow.users.first.uuid).to eq("11e6be14-8267-25ee-a3bd-0242ac110002")
|
155
|
+
expect(flow.users.first.first_name).to eq("Existing")
|
141
156
|
end
|
142
157
|
|
143
158
|
end
|
@@ -146,15 +161,18 @@ describe Lifen::Flow do
|
|
146
161
|
|
147
162
|
describe 'detach_users' do
|
148
163
|
|
164
|
+
# let(:valid_token_value) { "REPLACE_ME" }
|
165
|
+
|
149
166
|
context 'valid flow uuid' do
|
150
|
-
let(:flow) { Lifen::Flow.new(uuid: "
|
167
|
+
let(:flow) { Lifen::Flow.new(uuid: "11e6be18-7a35-d759-9177-0242ac110002", user: user) }
|
168
|
+
let(:other_user) { Lifen::User.new(uuid: "11e6be15-0fb1-0a21-a3bd-0242ac110002") }
|
151
169
|
|
152
170
|
it 'detaches a users' do
|
153
171
|
VCR.use_cassette "flows/detach_users/valid" do
|
154
|
-
flow.detach_users
|
172
|
+
flow.detach_users(other_user)
|
155
173
|
end
|
156
174
|
|
157
|
-
expect(flow.
|
175
|
+
expect(flow.users.size).to eq(1)
|
158
176
|
end
|
159
177
|
|
160
178
|
# it 'raises an error if the error is not detached' do
|
data/spec/messages_spec.rb
CHANGED
@@ -2,9 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Lifen::Message do
|
4
4
|
|
5
|
-
|
6
|
-
let(:
|
7
|
-
|
5
|
+
let(:valid_token_value) { "valide_token" }
|
6
|
+
# let(:valid_token_value) { "REPLACE_ME" }
|
7
|
+
|
8
|
+
let(:valid_token) { Lifen::Token.new(value: valid_token_value, expires_at: Time.now.to_i + 60) }
|
9
|
+
let(:user) { Lifen::User.new(token: valid_token) }
|
10
|
+
|
11
|
+
let(:flow) { Lifen::Flow.new(user: user, uuid: "11e6be18-7a35-d759-9177-0242ac110002") }
|
12
|
+
let(:message) { Lifen::Message.new(flow: flow, content: "Bonjour Lifen") }
|
8
13
|
|
9
14
|
describe "create" do
|
10
15
|
|
@@ -16,10 +21,10 @@ describe Lifen::Message do
|
|
16
21
|
message.create
|
17
22
|
end
|
18
23
|
|
19
|
-
expect(message.uuid).to eq("
|
24
|
+
expect(message.uuid).to eq("11e6be20-5647-8f9b-9177-0242ac110002")
|
20
25
|
expect(message.type).to eq("regular")
|
21
26
|
expect(message.flow).to eq(flow)
|
22
|
-
expect(message.sent_at.to_date).to eq Date.new(2016, 12,
|
27
|
+
expect(message.sent_at.to_date).to eq Date.new(2016, 12, 9)
|
23
28
|
|
24
29
|
end
|
25
30
|
|
data/spec/spec_helper.rb
CHANGED