lifen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +70 -0
  7. data/License.txt +22 -0
  8. data/README.md +76 -0
  9. data/Rakefile +7 -0
  10. data/lib/lifen.rb +19 -0
  11. data/lib/lifen/app_authenticated_client.rb +32 -0
  12. data/lib/lifen/authentication.rb +29 -0
  13. data/lib/lifen/base.rb +7 -0
  14. data/lib/lifen/client.rb +18 -0
  15. data/lib/lifen/configuration.rb +13 -0
  16. data/lib/lifen/error.rb +26 -0
  17. data/lib/lifen/flow.rb +67 -0
  18. data/lib/lifen/flows.rb +31 -0
  19. data/lib/lifen/user.rb +39 -0
  20. data/lib/lifen/user_authenticated_client.rb +38 -0
  21. data/lib/lifen/version.rb +3 -0
  22. data/lifen.gemspec +29 -0
  23. data/spec/cassettes/flows/attach_users/invalid_flow_uuid.yml +57 -0
  24. data/spec/cassettes/flows/attach_users/invalid_user_uuid.yml +57 -0
  25. data/spec/cassettes/flows/attach_users/valid.yml +57 -0
  26. data/spec/cassettes/flows/create.yml +57 -0
  27. data/spec/cassettes/flows/detach_users/valid.yml +57 -0
  28. data/spec/cassettes/flows/detach_users/valid_again.yml +57 -0
  29. data/spec/cassettes/flows/invalid_token.yml +56 -0
  30. data/spec/cassettes/flows/valid_token.yml +58 -0
  31. data/spec/cassettes/users/create/existing_user.yml +54 -0
  32. data/spec/cassettes/users/create/invalid_token.yml +54 -0
  33. data/spec/cassettes/users/create/missing_fields.yml +55 -0
  34. data/spec/cassettes/users/create/valid_attributes.yml +54 -0
  35. data/spec/cassettes/users/refresh/invalid_user_uuid.yml +55 -0
  36. data/spec/cassettes/users/refresh/valid_user_uuid.yml +54 -0
  37. data/spec/flows_spec.rb +126 -0
  38. data/spec/spec_helper.rb +24 -0
  39. data/spec/users_spec.rb +101 -0
  40. metadata +211 -0
@@ -0,0 +1,39 @@
1
+ module Lifen
2
+ class User < Base
3
+
4
+ attribute :uuid, String
5
+ attribute :token, String
6
+
7
+ attribute :email, String
8
+ attribute :last_name, String
9
+ attribute :first_name, String
10
+
11
+ def flows
12
+ Lifen::Flows.new(self).all
13
+ end
14
+
15
+ def create!
16
+ authentication = Lifen::Authentication.new(user: self)
17
+ authentication.register!
18
+
19
+ self.token = authentication.token
20
+ self.uuid = authentication.uuid
21
+
22
+ self
23
+ end
24
+
25
+ def refresh_token
26
+ authentication = Lifen::Authentication.new(user: self)
27
+ authentication.refresh_token
28
+
29
+ self.token = authentication.token
30
+
31
+ self
32
+ end
33
+
34
+ def client
35
+ UserAuthenticatedClient.new(token)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ module Lifen
2
+ class UserAuthenticatedClient < Client
3
+
4
+ def initialize(token)
5
+ @token = token
6
+ end
7
+
8
+ attr_reader :token
9
+
10
+ def request(mode, url, params = {})
11
+ response = faraday_client.send(mode) do |req|
12
+ req.url url
13
+
14
+ req.headers['x-auth-token'] = token
15
+ req.headers['Content-Type'] = "application/json"
16
+
17
+ req.body = JSON.generate(params)
18
+ end
19
+
20
+ raise UnauthorizedError, "Token is not valid" if response.status == 401
21
+ raise Error, "Action is forbidden" if response.status == 403
22
+ raise InvalidParamsError, "Invalid params" if response.status == 400
23
+
24
+ json = JSON.parse response.body
25
+
26
+ json
27
+ end
28
+
29
+ def post(url, params = {})
30
+ request(:post, url, params)
31
+ end
32
+
33
+ def get(url, params = {})
34
+ request(:get, url, params)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Lifen
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'lifen/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lifen"
7
+ spec.version = Lifen::VERSION
8
+ spec.authors = ["Etienne Depaulis"]
9
+ spec.email = ["etienne.depaulis@honestica.com"]
10
+ spec.homepage = "https://github.com/honestica/lifen"
11
+ spec.description = %q{Lifen API ruby client}
12
+ spec.summary = %q{Lifen JSON API ruby client}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", '~> 1.12'
21
+ spec.add_development_dependency "rake", '~> 10.5'
22
+ spec.add_development_dependency "rspec", '~> 3.5'
23
+ spec.add_development_dependency "vcr", '~> 3.0'
24
+ spec.add_development_dependency "webmock", '~> 1.24'
25
+ spec.add_development_dependency "awesome_print"
26
+
27
+ spec.add_runtime_dependency "virtus", '~> 1.0'
28
+ spec.add_runtime_dependency "faraday", '~> 0.9'
29
+ end
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://develop.lifen.fr/central/api/chats/invalid-uuid/attach_users?rel=activeUsers
6
+ body:
7
+ encoding: UTF-8
8
+ string: '["25588996-4ff1-2dbb-9643-eabb809fa654"]'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
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: 400
23
+ message: Bad Request
24
+ headers:
25
+ Server:
26
+ - Apache-Coyote/1.1
27
+ X-B3-Sampled:
28
+ - '1'
29
+ X-B3-Spanid:
30
+ - 6711763f068ffd6a
31
+ X-B3-Traceid:
32
+ - 6711763f068ffd6a
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/json;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Wed, 10 Aug 2016 07:19:02 GMT
49
+ Connection:
50
+ - close
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"timestamp":"2016-08-10T07:19:02.782+0000","status":400,"error":"Bad
54
+ Request","code":"error.400","X-B3-TraceId":"6711763f068ffd6a","X-B3-SpanId":"6711763f068ffd6a"}'
55
+ http_version:
56
+ recorded_at: Wed, 10 Aug 2016 07:19:02 GMT
57
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://develop.lifen.fr/central/api/chats/11e65eca-4af7-d795-bf1a-0242ac110002/attach_users?rel=activeUsers
6
+ body:
7
+ encoding: UTF-8
8
+ string: '["invalid-uuid"]'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
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: 400
23
+ message: Bad Request
24
+ headers:
25
+ Server:
26
+ - Apache-Coyote/1.1
27
+ X-B3-Sampled:
28
+ - '1'
29
+ X-B3-Spanid:
30
+ - 34d5716dd10fb931
31
+ X-B3-Traceid:
32
+ - 34d5716dd10fb931
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/json;charset=UTF-8
45
+ Transfer-Encoding:
46
+ - chunked
47
+ Date:
48
+ - Wed, 10 Aug 2016 07:46:14 GMT
49
+ Connection:
50
+ - close
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"timestamp":"2016-08-10T07:46:14.047+0000","status":400,"error":"Bad
54
+ Request","code":"error.badrequest","X-B3-TraceId":"34d5716dd10fb931","X-B3-SpanId":"34d5716dd10fb931"}'
55
+ http_version:
56
+ recorded_at: Wed, 10 Aug 2016 07:46:14 GMT
57
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://develop.lifen.fr/central/api/chats/11e65eca-4af7-d795-bf1a-0242ac110002/attach_users?rel=activeUsers
6
+ body:
7
+ encoding: UTF-8
8
+ string: '["25588996-4ff1-2dbb-9643-eabb809fa654"]'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
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
+ - 6abde30c277e69a4
31
+ X-B3-Traceid:
32
+ - 6abde30c277e69a4
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
+ - Wed, 10 Aug 2016 07:21:04 GMT
49
+ Connection:
50
+ - close
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"uuid":"11e65eca-4af7-d795-bf1a-0242ac110002","version":0,"title":"Rspec
54
+ Flow","activeUsers":[{"uuid":"25588996-4ff1-2dbb-9643-eabb809fa654","version":0,"firstName":"Albert","lastName":"Coeur","civilite":"DR","profilePicUrl":"//develop.lifen.fr/app/docbook/profilePic/a5/77/b3/b4/fd99f8b6ae471b2e2a64ebcd09bf37fa/25588996-4ff1-2dbb-9643-eabb809fa654.jpg","speciality":"Cardiologie","hasEmail":false,"activated":false}],"type":"regular"}'
55
+ http_version:
56
+ recorded_at: Wed, 10 Aug 2016 07:21:04 GMT
57
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://develop.lifen.fr/central/api/chats
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"title":"Rspec Flow"}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
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
+ - f9e559ae8d3a29c3
31
+ X-B3-Traceid:
32
+ - f9e559ae8d3a29c3
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
+ - Wed, 10 Aug 2016 07:16:01 GMT
49
+ Connection:
50
+ - close
51
+ body:
52
+ encoding: UTF-8
53
+ string: '[{"uuid":"11e65eca-4af7-d795-bf1a-0242ac110002","version":0,"title":"Rspec
54
+ Flow","type":"regular"}]'
55
+ http_version:
56
+ recorded_at: Wed, 10 Aug 2016 07:16:01 GMT
57
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://develop.lifen.fr/central/api/chats/11e65eca-4af7-d795-bf1a-0242ac110002/detach_users?rel=activeUsers
6
+ body:
7
+ encoding: UTF-8
8
+ string: '["25588996-4ff1-2dbb-9643-eabb809fa654"]'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
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
+ - b01671e24905ea23
31
+ X-B3-Traceid:
32
+ - b01671e24905ea23
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
+ - Wed, 10 Aug 2016 07:34:28 GMT
49
+ Connection:
50
+ - close
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"uuid":"11e65eca-4af7-d795-bf1a-0242ac110002","version":0,"title":"Rspec
54
+ Flow","activeUsers":[],"type":"regular"}'
55
+ http_version:
56
+ recorded_at: Wed, 10 Aug 2016 07:34:28 GMT
57
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://develop.lifen.fr/central/api/chats/11e65eca-4af7-d795-bf1a-0242ac110002/detach_users?rel=activeUsers
6
+ body:
7
+ encoding: UTF-8
8
+ string: '["25588996-4ff1-2dbb-9643-eabb809fa654"]'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
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
+ - 65008d9ee1e9b85c
31
+ X-B3-Traceid:
32
+ - 65008d9ee1e9b85c
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
+ - Wed, 10 Aug 2016 07:37:16 GMT
49
+ Connection:
50
+ - close
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"uuid":"11e65eca-4af7-d795-bf1a-0242ac110002","version":0,"title":"Rspec
54
+ Flow","activeUsers":[],"type":"regular"}'
55
+ http_version:
56
+ recorded_at: Wed, 10 Aug 2016 07:37:16 GMT
57
+ recorded_with: VCR 3.0.3