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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a67207628744fa9170010479e696b05545a73568
4
- data.tar.gz: c88fc831f27439acd3df13d6eca873b159cf8d5d
3
+ metadata.gz: f43d79863f669ef8d3c3bd3bc020c906b70bba38
4
+ data.tar.gz: bd2d87955f148b20fbb9f2cfb242d4086f0face7
5
5
  SHA512:
6
- metadata.gz: 7fbd97528d92d51504930198d3eee85e50b06c2ed530a7597458770a7fe874373d7359af64d032d72d386a983dde4632521a0ae642d7d1bf32813724f1f2c0b0
7
- data.tar.gz: d4430833c1e7849de2446b6b38f14d99a33d5a0a27130a43676f9f8a05c2504e2690908f4bd86ed5d7df3ee0e1e4cdf19548cd2091458412c56f5ba7a7c9e923
6
+ metadata.gz: 30a1acc06def39ca6b5525215d0a7920cf9fed8118817bf8ea5793c45e0116d9a7f9cd9d586655233373fe958688f284a39459e652d76d1e84a6942575a5339a
7
+ data.tar.gz: 688364f874269d69368f788a5510a50274e9ad66d8c9958098a216e1c3ad15fdd9111448466d8595c5bf21dedbb47dc0ff502324a3de899af141f7a371ef0f98
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ 1.0.1
2
+ -----
3
+
4
+ - Token validation is more strict
5
+ - Added a Changelog :)
6
+
7
+
8
+ 1.0.0
9
+ -----
10
+
11
+ - Major refactoring
12
+ - Added OAuth support
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifen (1.0.0)
4
+ lifen (1.0.1)
5
5
  faraday (>= 0.9)
6
6
  inflecto
7
7
  virtus (>= 1.0)
data/lib/lifen/token.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Lifen
2
2
  class Token
3
- include Virtus.model(finalize: false)
3
+ include Virtus.model(finalize: false)
4
4
 
5
- attribute :user, "Lifen::User"
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
- return true if expires_at.nil?
23
+ return true if expires_at.nil?
16
24
 
17
- return expires_at < Time.now.to_i
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
- return if !has_expired?
36
+ return if active?
31
37
 
32
- refresh
38
+ refresh
33
39
 
34
- raise Error, "Token can't be refreshed" if has_expired?
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
@@ -1,3 +1,3 @@
1
1
  module Lifen
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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
- let(:user) { Lifen::User.new(token: valid_token, uuid: "25588996-4ff1-2dbb-9643-eabb809fa654") }
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
- context "invalid token" do
15
- it 'raises an error' do
16
- user = Lifen::User.new(token: invalid_token)
14
+ context "invalid token" do
15
+ it 'raises an error' do
16
+ user = Lifen::User.new(token: invalid_token)
17
17
 
18
- expect{
19
- VCR.use_cassette "flows/invalid_token" do
20
- user.flows
21
- end
22
- }.to raise_error(Lifen::UnauthorizedError)
23
- end
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
- end
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
- }.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: 2e2eac3a7e3fa2)")
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
- }.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: unknown)")
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
- context "valid token" do
47
+ context "valid token" do
48
48
 
49
49
  # let(:valid_token_value) { "REPLACE_ME" }
50
50
 
51
- before(:each) do
52
- VCR.use_cassette "flows/valid_token" do
53
- @flows = user.flows
54
- end
51
+ before(:each) do
52
+ VCR.use_cassette "flows/valid_token" do
53
+ @flows = user.flows
54
+ end
55
55
 
56
- @flow = @flows.first
57
- end
56
+ @flow = @flows.first
57
+ end
58
58
 
59
- it { expect(@flows.size).to eq(1) }
59
+ it { expect(@flows.size).to eq(1) }
60
60
 
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
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
- end
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
- let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow") }
75
+ let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow") }
76
76
 
77
- it 'creates a flow' do
78
- VCR.use_cassette "flows/create" do
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
- end
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
- context 'invalid flow uuid' do
118
- let(:flow) { Lifen::Flow.new(uuid: "invalid-uuid", user: user) }
117
+ context 'invalid flow uuid' do
118
+ let(:flow) { Lifen::Flow.new(uuid: "invalid-uuid", user: user) }
119
119
 
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
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
- end
128
+ end
129
129
 
130
- context 'valid flow uuid' do
130
+ context 'valid flow uuid' do
131
131
 
132
- let(:flow) { Lifen::Flow.new(uuid: "11e6be18-7a35-d759-9177-0242ac110002", user: user) }
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
- context 'invalid user params' do
135
+ context 'invalid user params' do
136
136
 
137
- it 'raises an error' do
138
- invalid_user = Lifen::User.new(uuid: "invalid-uuid")
137
+ it 'raises an error' do
138
+ invalid_user = Lifen::User.new(uuid: "invalid-uuid")
139
139
 
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
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
- it 'attaches a user' do
149
- VCR.use_cassette "flows/attach_users/valid" do
150
- flow.attach_users(other_user)
151
- end
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
- end
156
+ end
157
157
 
158
- end
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
- context 'valid flow uuid' do
167
- let(:flow) { Lifen::Flow.new(uuid: "11e6be18-7a35-d759-9177-0242ac110002", user: user) }
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
- it 'detaches a users' do
171
- VCR.use_cassette "flows/detach_users/valid" do
172
- flow.detach_users(other_user)
173
- end
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
- end
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
- end
184
+ end
185
185
 
186
186
  end
187
187
 
@@ -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
- let(:user) { Lifen::User.new(token: valid_token) }
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
- context "valid message" do
16
+ context "valid message" do
17
17
 
18
- it 'has valid attributes' do
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
- expect(message.uuid).to eq("11e6be20-5647-8f9b-9177-0242ac110002")
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
- end
29
+ end
30
30
 
31
- end
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
- Lifen.configure do |config|
20
- config.site = "https://develop.lifen.fr/"
19
+ Lifen.configure do |config|
20
+ config.site = "https://develop.lifen.fr/"
21
21
  config.application_access_token = "valid_application_access_token"
22
- end
22
+ end
23
23
  end
24
24
  end
@@ -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.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-09 00:00:00.000000000 Z
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