lifen 0.2.0 → 0.2.1
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/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/lifen/flow.rb +27 -2
- data/lib/lifen/version.rb +1 -1
- data/spec/cassettes/flows/create.yml +2 -2
- data/spec/cassettes/flows/create_with_users.yml +56 -0
- data/spec/flows_spec.rb +24 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75f915f68d0f6d3185d5830ffb7d35519516a306
|
4
|
+
data.tar.gz: bccbde30e8be900129a9752f9735024a73335707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22b519b174c804ec29e6670be2b0dc48b595d4166af8df4537b831cef28e898f6fd1e1d5f3b9843e1ae2e8892555018262130d6112bc7c39d4debd73ea9313cb
|
7
|
+
data.tar.gz: 2416769de82ff4d2cdc68ab766e35ce6f171d6c4c41826b061efe189b70640f07ed79daa235ec418e7f37af954acbe419617e45eebf9b9f79d95a6b66780f4fd
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -47,6 +47,9 @@ Lifen can be configured (ideally inside an initializer) like so:
|
|
47
47
|
flow.attach_users!(user)
|
48
48
|
flow.detach_users!(user)
|
49
49
|
|
50
|
+
flow = Lifen::Flow.new(user: user, title: "honestica Rocks !", active_users: [user_1, user_2])
|
51
|
+
flow.create
|
52
|
+
|
50
53
|
### Managing messages
|
51
54
|
|
52
55
|
message = Lifen::Message.new(flow: flow, content: "Hello World !")
|
data/lib/lifen/flow.rb
CHANGED
@@ -7,13 +7,35 @@ module Lifen
|
|
7
7
|
attribute :active_users, Array[Lifen::User]
|
8
8
|
|
9
9
|
def create
|
10
|
-
|
10
|
+
params = {title: title}
|
11
11
|
|
12
|
-
|
12
|
+
users_to_attach = []
|
13
|
+
if !active_users.empty?
|
14
|
+
users_to_attach = active_users
|
15
|
+
params[:users] = active_users.map(&:uuid)
|
16
|
+
end
|
17
|
+
|
18
|
+
json = client.post("central/api/chats?rel=activeUsers", params)
|
19
|
+
|
20
|
+
json_flow = json.first
|
21
|
+
|
22
|
+
flow = self.class.new(json_flow)
|
13
23
|
|
14
24
|
self.user = user
|
15
25
|
self.uuid = flow.uuid
|
26
|
+
|
16
27
|
self.active_users = []
|
28
|
+
Array(json_flow["activeUsers"]).each do |element|
|
29
|
+
element[:first_name] = element["firstName"]
|
30
|
+
element[:last_name] = element["lastName"]
|
31
|
+
|
32
|
+
self.active_users << Lifen::User.new(element)
|
33
|
+
end
|
34
|
+
|
35
|
+
users_to_attach.each do |user|
|
36
|
+
raise Lifen::Error, "User #{user.uuid} was not attached to this flow" if !active_users.map(&:uuid).include? user.uuid
|
37
|
+
end
|
38
|
+
|
17
39
|
self.title = flow.title
|
18
40
|
|
19
41
|
self
|
@@ -27,6 +49,9 @@ module Lifen
|
|
27
49
|
json = client.post("central/api/chats/#{uuid}/attach_users?rel=activeUsers", params)
|
28
50
|
|
29
51
|
Array(json["activeUsers"]).each do |element|
|
52
|
+
element[:first_name] = element["firstName"]
|
53
|
+
element[:last_name] = element["lastName"]
|
54
|
+
|
30
55
|
self.active_users << Lifen::User.new(element)
|
31
56
|
end
|
32
57
|
|
data/lib/lifen/version.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://develop.lifen.fr/central/api/chats
|
5
|
+
uri: https://develop.lifen.fr/central/api/chats?rel=activeUsers
|
6
6
|
body:
|
7
7
|
encoding: UTF-8
|
8
8
|
string: '{"title":"Rspec Flow"}'
|
@@ -51,7 +51,7 @@ http_interactions:
|
|
51
51
|
body:
|
52
52
|
encoding: UTF-8
|
53
53
|
string: '[{"uuid":"11e65eca-4af7-d795-bf1a-0242ac110002","version":0,"title":"Rspec
|
54
|
-
Flow","type":"regular"}]'
|
54
|
+
Flow","type":"regular","activeUsers":[{"uuid":"11e6b876-ba09-1d98-9f4c-0242ac110002","version":0,"firstName":"User","lastName":"User","hasEmail":false,"activated":false,"registered":false}]}]'
|
55
55
|
http_version:
|
56
56
|
recorded_at: Wed, 10 Aug 2016 07:16:01 GMT
|
57
57
|
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,56 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://develop.lifen.fr/central/api/chats?rel=activeUsers
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"title":"Rspec Flow","users":["11e6b877-2997-01eb-9f4c-0242ac110002"]}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.10.0
|
12
|
+
X-Auth-Token:
|
13
|
+
- valid_token
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
Accept:
|
19
|
+
- "*/*"
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- Apache-Coyote/1.1
|
27
|
+
X-B3-Sampled:
|
28
|
+
- '1'
|
29
|
+
X-B3-Spanid:
|
30
|
+
- 6cd65dd2be54abcb
|
31
|
+
X-B3-Traceid:
|
32
|
+
- 6cd65dd2be54abcb
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
X-Xss-Protection:
|
36
|
+
- 1; mode=block
|
37
|
+
Cache-Control:
|
38
|
+
- no-cache, no-store, max-age=0, must-revalidate
|
39
|
+
Pragma:
|
40
|
+
- no-cache
|
41
|
+
Expires:
|
42
|
+
- '0'
|
43
|
+
Content-Type:
|
44
|
+
- application/hal+json;charset=UTF-8
|
45
|
+
Transfer-Encoding:
|
46
|
+
- chunked
|
47
|
+
Date:
|
48
|
+
- Fri, 02 Dec 2016 10:48:50 GMT
|
49
|
+
Connection:
|
50
|
+
- close
|
51
|
+
body:
|
52
|
+
encoding: UTF-8
|
53
|
+
string: '[{"uuid":"11e6b878-2da2-d06c-ac0e-0242ac110002","version":0,"title":"Essai","activeUsers":[{"uuid":"11e6b876-ba09-1d98-9f4c-0242ac110002","version":0,"firstName":"User","lastName":"User","hasEmail":false,"activated":false,"registered":false},{"uuid":"11e6b877-2997-01eb-9f4c-0242ac110002","version":0,"firstName":"User","lastName":"User","hasEmail":false,"activated":false,"registered":false}],"type":"regular"}]'
|
54
|
+
http_version:
|
55
|
+
recorded_at: Fri, 02 Dec 2016 10:48:16 GMT
|
56
|
+
recorded_with: VCR 3.0.3
|
data/spec/flows_spec.rb
CHANGED
@@ -74,6 +74,30 @@ describe Lifen::Flow do
|
|
74
74
|
expect(@new_flow.title).to eq("Rspec Flow")
|
75
75
|
|
76
76
|
end
|
77
|
+
|
78
|
+
context 'attaching users at the same time' do
|
79
|
+
|
80
|
+
let(:user) { Lifen::User.new(token: "valid_token", uuid: "11e6b876-ba09-1d98-9f4c-0242ac110002") }
|
81
|
+
let(:other_user) { Lifen::User.new(uuid: "11e6b877-2997-01eb-9f4c-0242ac110002") }
|
82
|
+
|
83
|
+
let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow", active_users: [other_user]) }
|
84
|
+
|
85
|
+
it 'creates a flow with attached users' do
|
86
|
+
|
87
|
+
VCR.use_cassette "flows/create_with_users" do
|
88
|
+
flow.create
|
89
|
+
end
|
90
|
+
|
91
|
+
expect(flow.active_users.size).to eq(2)
|
92
|
+
first_user = flow.active_users.first
|
93
|
+
|
94
|
+
expect(first_user.uuid).to eq("11e6b876-ba09-1d98-9f4c-0242ac110002")
|
95
|
+
expect(first_user.first_name).to eq("User")
|
96
|
+
|
97
|
+
expect(flow.active_users.last.uuid).to eq("11e6b877-2997-01eb-9f4c-0242ac110002")
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
77
101
|
end
|
78
102
|
|
79
103
|
describe 'attach_users' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lifen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Etienne Depaulis
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- spec/cassettes/flows/attach_users/invalid_user_uuid.yml
|
157
157
|
- spec/cassettes/flows/attach_users/valid.yml
|
158
158
|
- spec/cassettes/flows/create.yml
|
159
|
+
- spec/cassettes/flows/create_with_users.yml
|
159
160
|
- spec/cassettes/flows/detach_users/valid.yml
|
160
161
|
- spec/cassettes/flows/detach_users/valid_again.yml
|
161
162
|
- spec/cassettes/flows/internal_error.yml
|
@@ -204,6 +205,7 @@ test_files:
|
|
204
205
|
- spec/cassettes/flows/attach_users/invalid_user_uuid.yml
|
205
206
|
- spec/cassettes/flows/attach_users/valid.yml
|
206
207
|
- spec/cassettes/flows/create.yml
|
208
|
+
- spec/cassettes/flows/create_with_users.yml
|
207
209
|
- spec/cassettes/flows/detach_users/valid.yml
|
208
210
|
- spec/cassettes/flows/detach_users/valid_again.yml
|
209
211
|
- spec/cassettes/flows/internal_error.yml
|