lifen 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/lib/lifen/token.rb +15 -9
- data/lib/lifen/user.rb +0 -7
- data/lib/lifen/version.rb +1 -1
- data/spec/flows_spec.rb +67 -67
- data/spec/messages_spec.rb +6 -6
- data/spec/spec_helper.rb +3 -3
- data/spec/token_spec.rb +29 -0
- data/spec/users_spec.rb +0 -16
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f43d79863f669ef8d3c3bd3bc020c906b70bba38
|
4
|
+
data.tar.gz: bd2d87955f148b20fbb9f2cfb242d4086f0face7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30a1acc06def39ca6b5525215d0a7920cf9fed8118817bf8ea5793c45e0116d9a7f9cd9d586655233373fe958688f284a39459e652d76d1e84a6942575a5339a
|
7
|
+
data.tar.gz: 688364f874269d69368f788a5510a50274e9ad66d8c9958098a216e1c3ad15fdd9111448466d8595c5bf21dedbb47dc0ff502324a3de899af141f7a371ef0f98
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/lib/lifen/token.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Lifen
|
2
2
|
class Token
|
3
|
-
|
3
|
+
include Virtus.model(finalize: false)
|
4
4
|
|
5
|
-
|
5
|
+
attribute :user, "Lifen::User"
|
6
6
|
|
7
7
|
attribute :value, String
|
8
8
|
attribute :expires_at, Integer
|
@@ -11,15 +11,21 @@ module Lifen
|
|
11
11
|
value
|
12
12
|
end
|
13
13
|
|
14
|
+
def active?
|
15
|
+
valid? and !has_expired?
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?
|
19
|
+
!value.nil? and value.length > 0 and !expires_at.nil?
|
20
|
+
end
|
21
|
+
|
14
22
|
def has_expired?
|
15
|
-
|
23
|
+
return true if expires_at.nil?
|
16
24
|
|
17
|
-
|
25
|
+
return expires_at < Time.now.to_i
|
18
26
|
end
|
19
27
|
|
20
28
|
def refresh
|
21
|
-
# params = {accountUuid: user.uuid}
|
22
|
-
|
23
29
|
json = client.post("/oauth/admin/third_party/access_token?accountUuid=#{user.uuid}")
|
24
30
|
|
25
31
|
self.value = json["access_token"]
|
@@ -27,11 +33,11 @@ module Lifen
|
|
27
33
|
end
|
28
34
|
|
29
35
|
def refresh_once_if_needed
|
30
|
-
|
36
|
+
return if active?
|
31
37
|
|
32
|
-
|
38
|
+
refresh
|
33
39
|
|
34
|
-
|
40
|
+
raise Error, "Token can't be refreshed" if !active?
|
35
41
|
end
|
36
42
|
|
37
43
|
private
|
data/lib/lifen/user.rb
CHANGED
@@ -10,13 +10,6 @@ module Lifen
|
|
10
10
|
attribute :last_name, String
|
11
11
|
attribute :first_name, String
|
12
12
|
|
13
|
-
# def initialize(*args)
|
14
|
-
# self.token = Lifen::Token.new(user: self)
|
15
|
-
# self.status = Lifen::Status.new(user: self)
|
16
|
-
|
17
|
-
# super
|
18
|
-
# end
|
19
|
-
|
20
13
|
def flows
|
21
14
|
Lifen::Flows.new(user: self).all
|
22
15
|
end
|
data/lib/lifen/version.rb
CHANGED
data/spec/flows_spec.rb
CHANGED
@@ -7,22 +7,22 @@ describe Lifen::Flow do
|
|
7
7
|
let(:invalid_token) { Lifen::Token.new(value: "invalid_token", expires_at: Time.now.to_i + 60) }
|
8
8
|
let(:valid_token) { Lifen::Token.new(value: valid_token_value, expires_at: Time.now.to_i + 60) }
|
9
9
|
|
10
|
-
|
10
|
+
let(:user) { Lifen::User.new(token: valid_token, uuid: "25588996-4ff1-2dbb-9643-eabb809fa654") }
|
11
11
|
|
12
12
|
describe "index" do
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
context "invalid token" do
|
15
|
+
it 'raises an error' do
|
16
|
+
user = Lifen::User.new(token: invalid_token)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
expect{
|
19
|
+
VCR.use_cassette "flows/invalid_token" do
|
20
|
+
user.flows
|
21
|
+
end
|
22
|
+
}.to raise_error(Lifen::UnauthorizedError)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
end
|
26
26
|
|
27
27
|
context "valid token but internal error" do
|
28
28
|
it 'raises an error' do
|
@@ -31,7 +31,7 @@ describe Lifen::Flow do
|
|
31
31
|
VCR.use_cassette "flows/internal_error" do
|
32
32
|
user.flows
|
33
33
|
end
|
34
|
-
|
34
|
+
}.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: 2e2eac3a7e3fa2)")
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'raises an error (without trace ID)' do
|
@@ -39,32 +39,32 @@ describe Lifen::Flow do
|
|
39
39
|
VCR.use_cassette "flows/internal_error_without_trace_id" do
|
40
40
|
user.flows
|
41
41
|
end
|
42
|
-
|
42
|
+
}.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: unknown)")
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
context "valid token" do
|
48
48
|
|
49
49
|
# let(:valid_token_value) { "REPLACE_ME" }
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
before(:each) do
|
52
|
+
VCR.use_cassette "flows/valid_token" do
|
53
|
+
@flows = user.flows
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
@flow = @flows.first
|
57
|
+
end
|
58
58
|
|
59
|
-
|
59
|
+
it { expect(@flows.size).to eq(1) }
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
it 'has valid attributes' do
|
62
|
+
expect(@flow.user).to eq(user)
|
63
|
+
expect(@flow.uuid).to eq("11e6be18-7a35-d759-9177-0242ac110002")
|
64
|
+
expect(@flow.title).to eq("Rspec Flow")
|
65
|
+
end
|
66
66
|
|
67
|
-
|
67
|
+
end
|
68
68
|
|
69
69
|
end
|
70
70
|
|
@@ -72,10 +72,10 @@ describe Lifen::Flow do
|
|
72
72
|
|
73
73
|
# let(:valid_token_value) { "REPLACE_ME" }
|
74
74
|
|
75
|
-
|
75
|
+
let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow") }
|
76
76
|
|
77
|
-
|
78
|
-
|
77
|
+
it 'creates a flow' do
|
78
|
+
VCR.use_cassette "flows/create" do
|
79
79
|
@new_flow = flow.create
|
80
80
|
end
|
81
81
|
|
@@ -83,7 +83,7 @@ describe Lifen::Flow do
|
|
83
83
|
expect(@new_flow.user).to eq(user)
|
84
84
|
expect(@new_flow.title).to eq("Rspec Flow")
|
85
85
|
|
86
|
-
|
86
|
+
end
|
87
87
|
|
88
88
|
context 'attaching users at the same time' do
|
89
89
|
|
@@ -114,48 +114,48 @@ describe Lifen::Flow do
|
|
114
114
|
|
115
115
|
# let(:valid_token_value) { "REPLACE_ME" }
|
116
116
|
|
117
|
-
|
118
|
-
|
117
|
+
context 'invalid flow uuid' do
|
118
|
+
let(:flow) { Lifen::Flow.new(uuid: "invalid-uuid", user: user) }
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
it 'raises an error' do
|
121
|
+
expect{
|
122
|
+
VCR.use_cassette "flows/attach_users/invalid_flow_uuid" do
|
123
|
+
flow.attach_users(user)
|
124
|
+
end
|
125
|
+
}.to raise_error(Lifen::InvalidParamsError)
|
126
|
+
end
|
127
127
|
|
128
|
-
|
128
|
+
end
|
129
129
|
|
130
|
-
|
130
|
+
context 'valid flow uuid' do
|
131
131
|
|
132
|
-
|
132
|
+
let(:flow) { Lifen::Flow.new(uuid: "11e6be18-7a35-d759-9177-0242ac110002", user: user) }
|
133
133
|
let(:other_user) { Lifen::User.new(uuid: "11e6be15-0fb1-0a21-a3bd-0242ac110002") }
|
134
134
|
|
135
|
-
|
135
|
+
context 'invalid user params' do
|
136
136
|
|
137
|
-
|
138
|
-
|
137
|
+
it 'raises an error' do
|
138
|
+
invalid_user = Lifen::User.new(uuid: "invalid-uuid")
|
139
139
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
140
|
+
expect{
|
141
|
+
VCR.use_cassette "flows/attach_users/invalid_user_uuid" do
|
142
|
+
flow.attach_users(invalid_user)
|
143
|
+
end
|
144
|
+
}.to raise_error(Lifen::InvalidParamsError)
|
145
|
+
end
|
146
|
+
end
|
147
147
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
it 'attaches a user' do
|
149
|
+
VCR.use_cassette "flows/attach_users/valid" do
|
150
|
+
flow.attach_users(other_user)
|
151
|
+
end
|
152
152
|
|
153
153
|
expect(flow.users.size).to eq(2)
|
154
154
|
expect(flow.users.first.uuid).to eq("11e6be14-8267-25ee-a3bd-0242ac110002")
|
155
155
|
expect(flow.users.first.first_name).to eq("Existing")
|
156
|
-
|
156
|
+
end
|
157
157
|
|
158
|
-
|
158
|
+
end
|
159
159
|
|
160
160
|
end
|
161
161
|
|
@@ -163,17 +163,17 @@ describe Lifen::Flow do
|
|
163
163
|
|
164
164
|
# let(:valid_token_value) { "REPLACE_ME" }
|
165
165
|
|
166
|
-
|
167
|
-
|
166
|
+
context 'valid flow uuid' do
|
167
|
+
let(:flow) { Lifen::Flow.new(uuid: "11e6be18-7a35-d759-9177-0242ac110002", user: user) }
|
168
168
|
let(:other_user) { Lifen::User.new(uuid: "11e6be15-0fb1-0a21-a3bd-0242ac110002") }
|
169
169
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
it 'detaches a users' do
|
171
|
+
VCR.use_cassette "flows/detach_users/valid" do
|
172
|
+
flow.detach_users(other_user)
|
173
|
+
end
|
174
174
|
|
175
175
|
expect(flow.users.size).to eq(1)
|
176
|
-
|
176
|
+
end
|
177
177
|
|
178
178
|
# it 'raises an error if the error is not detached' do
|
179
179
|
# VCR.use_cassette "flows/detach_users/valid_again" do
|
@@ -181,7 +181,7 @@ describe Lifen::Flow do
|
|
181
181
|
# end
|
182
182
|
# end
|
183
183
|
|
184
|
-
|
184
|
+
end
|
185
185
|
|
186
186
|
end
|
187
187
|
|
data/spec/messages_spec.rb
CHANGED
@@ -6,29 +6,29 @@ describe Lifen::Message do
|
|
6
6
|
# let(:valid_token_value) { "REPLACE_ME" }
|
7
7
|
|
8
8
|
let(:valid_token) { Lifen::Token.new(value: valid_token_value, expires_at: Time.now.to_i + 60) }
|
9
|
-
|
9
|
+
let(:user) { Lifen::User.new(token: valid_token) }
|
10
10
|
|
11
11
|
let(:flow) { Lifen::Flow.new(user: user, uuid: "11e6be18-7a35-d759-9177-0242ac110002") }
|
12
12
|
let(:message) { Lifen::Message.new(flow: flow, content: "Bonjour Lifen") }
|
13
13
|
|
14
14
|
describe "create" do
|
15
15
|
|
16
|
-
|
16
|
+
context "valid message" do
|
17
17
|
|
18
|
-
|
18
|
+
it 'has valid attributes' do
|
19
19
|
|
20
20
|
VCR.use_cassette "messages/valid_message" do
|
21
21
|
message.create
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
expect(message.uuid).to eq("11e6be20-5647-8f9b-9177-0242ac110002")
|
25
25
|
expect(message.type).to eq("regular")
|
26
26
|
expect(message.flow).to eq(flow)
|
27
27
|
expect(message.sent_at.to_date).to eq Date.new(2016, 12, 9)
|
28
28
|
|
29
|
-
|
29
|
+
end
|
30
30
|
|
31
|
-
|
31
|
+
end
|
32
32
|
|
33
33
|
end
|
34
34
|
|
data/spec/spec_helper.rb
CHANGED
@@ -16,9 +16,9 @@ end
|
|
16
16
|
|
17
17
|
RSpec.configure do |c|
|
18
18
|
c.before(:each) do
|
19
|
-
|
20
|
-
|
19
|
+
Lifen.configure do |config|
|
20
|
+
config.site = "https://develop.lifen.fr/"
|
21
21
|
config.application_access_token = "valid_application_access_token"
|
22
|
-
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
data/spec/token_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lifen::Token do
|
4
|
+
|
5
|
+
describe 'expired token' do
|
6
|
+
|
7
|
+
let(:expired_token) { Lifen::Token.new(value: "valid_token", expires_at: Time.now.to_i - 60) }
|
8
|
+
|
9
|
+
it 'refreshs the token' do
|
10
|
+
expect(expired_token).to receive(:refresh) do
|
11
|
+
expired_token.expires_at = Time.now.to_i + 60
|
12
|
+
end
|
13
|
+
|
14
|
+
expired_token.refresh_once_if_needed
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'invalid token' do
|
20
|
+
|
21
|
+
let(:invalid_token) { Lifen::Token.new(value: "", expires_at: Time.now.to_i + 60) }
|
22
|
+
|
23
|
+
it 'detects invalid tokens' do
|
24
|
+
expect(invalid_token).to_not be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/users_spec.rb
CHANGED
@@ -101,22 +101,6 @@ describe Lifen::User do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe 'expired token' do
|
105
|
-
|
106
|
-
let(:expired_token) { Lifen::Token.new(value: "valid_token", expires_at: Time.now.to_i - 60) }
|
107
|
-
let(:user) { Lifen::User.new(token: expired_token) }
|
108
|
-
|
109
|
-
|
110
|
-
it 'refreshs the token' do
|
111
|
-
expect(expired_token).to receive(:refresh) do
|
112
|
-
expired_token.expires_at = Time.now.to_i + 60
|
113
|
-
end
|
114
|
-
|
115
|
-
expired_token.refresh_once_if_needed
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
104
|
end
|
121
105
|
|
122
106
|
describe ':status.refresh' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lifen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Etienne Depaulis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- ".gitignore"
|
147
147
|
- ".rspec"
|
148
148
|
- ".ruby-version"
|
149
|
+
- CHANGELOG.md
|
149
150
|
- Gemfile
|
150
151
|
- Gemfile.lock
|
151
152
|
- License.txt
|
@@ -188,6 +189,7 @@ files:
|
|
188
189
|
- spec/flows_spec.rb
|
189
190
|
- spec/messages_spec.rb
|
190
191
|
- spec/spec_helper.rb
|
192
|
+
- spec/token_spec.rb
|
191
193
|
- spec/users_spec.rb
|
192
194
|
homepage: https://github.com/honestica/lifen
|
193
195
|
licenses:
|
@@ -236,4 +238,5 @@ test_files:
|
|
236
238
|
- spec/flows_spec.rb
|
237
239
|
- spec/messages_spec.rb
|
238
240
|
- spec/spec_helper.rb
|
241
|
+
- spec/token_spec.rb
|
239
242
|
- spec/users_spec.rb
|