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,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lifen::Flow do
4
+
5
+ let(:user) { Lifen::User.new(token: "valid_token", uuid: "25588996-4ff1-2dbb-9643-eabb809fa654") }
6
+
7
+ describe "index" do
8
+
9
+ context "invalid token" do
10
+ it 'raises an error' do
11
+ user = Lifen::User.new(token: "invalid-token")
12
+
13
+ expect{
14
+ VCR.use_cassette "flows/invalid_token" do
15
+ @flows = user.flows
16
+ end
17
+ }.to raise_error(Lifen::UnauthorizedError)
18
+ end
19
+
20
+ end
21
+
22
+ context "valid token" do
23
+
24
+ before(:each) do
25
+ VCR.use_cassette "flows/valid_token" do
26
+ @flows = user.flows
27
+ end
28
+
29
+ @flow = @flows.first
30
+ end
31
+
32
+ it { expect(@flows.size).to eq(3) }
33
+
34
+ it 'has valid attributes' do
35
+ expect(@flow.user).to eq(user)
36
+ expect(@flow.uuid).to eq("11e5c68b-85e9-96e8-9d33-027026ae8c87")
37
+ expect(@flow.title).to be_nil
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ describe 'create' do
45
+ let(:flow) { Lifen::Flow.new(user: user, title: "Rspec Flow") }
46
+
47
+ it 'creates a flow' do
48
+ VCR.use_cassette "flows/create" do
49
+ @new_flow = flow.create
50
+ end
51
+
52
+ expect(@new_flow.uuid).to_not be_nil
53
+ expect(@new_flow.user).to eq(user)
54
+ expect(@new_flow.title).to eq("Rspec Flow")
55
+
56
+ end
57
+ end
58
+
59
+ describe 'attach_users' do
60
+
61
+ context 'invalid flow uuid' do
62
+ let(:flow) { Lifen::Flow.new(uuid: "invalid-uuid", user: user) }
63
+
64
+ it 'raises an error' do
65
+ expect{
66
+ VCR.use_cassette "flows/attach_users/invalid_flow_uuid" do
67
+ flow.attach_users!(user)
68
+ end
69
+ }.to raise_error(Lifen::InvalidParamsError)
70
+ end
71
+
72
+ end
73
+
74
+ context 'valid flow uuid' do
75
+ let(:flow) { Lifen::Flow.new(uuid: "11e65eca-4af7-d795-bf1a-0242ac110002", user: user) }
76
+
77
+ context 'invalid user params' do
78
+
79
+ it 'raises an error' do
80
+ invalid_user = Lifen::User.new(uuid: "invalid-uuid")
81
+
82
+ expect{
83
+ VCR.use_cassette "flows/attach_users/invalid_user_uuid" do
84
+ flow.attach_users!(invalid_user)
85
+ end
86
+ }.to raise_error(Lifen::InvalidParamsError)
87
+ end
88
+ end
89
+
90
+ it 'attaches a user' do
91
+ VCR.use_cassette "flows/attach_users/valid" do
92
+ flow.attach_users!(user)
93
+ end
94
+
95
+ expect(flow.active_users.size).to eq(1)
96
+ expect(flow.active_users.first.uuid).to eq("25588996-4ff1-2dbb-9643-eabb809fa654")
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+
103
+ describe 'detach_users' do
104
+
105
+ context 'valid flow uuid' do
106
+ let(:flow) { Lifen::Flow.new(uuid: "11e65eca-4af7-d795-bf1a-0242ac110002", user: user) }
107
+
108
+ it 'detaches a users' do
109
+ VCR.use_cassette "flows/detach_users/valid" do
110
+ flow.detach_users!(user)
111
+ end
112
+
113
+ expect(flow.active_users.size).to eq(0)
114
+ end
115
+
116
+ # it 'raises an error if the error is not detached' do
117
+ # VCR.use_cassette "flows/detach_users/valid_again" do
118
+ # flow.detach_users!(user)
119
+ # end
120
+ # end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,24 @@
1
+ require 'bundler/setup'
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+ require 'awesome_print'
5
+
6
+ require_relative '../lib/lifen.rb'
7
+
8
+ VCR.configure do |c|
9
+ c.cassette_library_dir = 'spec/cassettes'
10
+ c.hook_into :webmock
11
+ c.allow_http_connections_when_no_cassette = false
12
+ c.before_record do |i|
13
+ i.response.body.force_encoding('UTF-8')
14
+ end
15
+ end
16
+
17
+ RSpec.configure do |c|
18
+ c.before(:each) do
19
+ Lifen.configure do |config|
20
+ config.site = "http://develop.lifen.fr/"
21
+ config.secret_key = "valid_secret_key"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lifen::User do
4
+
5
+ describe ':create' do
6
+ context 'missing field' do
7
+
8
+ let(:user) { Lifen::User.new() }
9
+
10
+ it 'raises an error' do
11
+ expect{
12
+ VCR.use_cassette "users/create/missing_fields" do
13
+ user.create!
14
+ end
15
+ }.to raise_error(Lifen::Error)
16
+ end
17
+ end
18
+
19
+ context 'invalid secret key' do
20
+
21
+ let(:user) { Lifen::User.new(email: "invalid-key-email@test.tld") }
22
+
23
+ before do
24
+ Lifen.configure do |config|
25
+ config.secret_key = "invalid-secret-key"
26
+ end
27
+ end
28
+
29
+ it 'raises an error' do
30
+ expect{
31
+ VCR.use_cassette "users/create/invalid_token" do
32
+ user.create!
33
+ end
34
+ }.to raise_error(Lifen::InvalidSecretTokenError)
35
+ end
36
+ end
37
+
38
+ context 'exisiting user' do
39
+ let(:user) { Lifen::User.new(email: "existing-user@domain.tld") }
40
+
41
+ it 'creates the user' do
42
+
43
+ expect{
44
+ VCR.use_cassette "users/create/existing_user" do
45
+ user.create!
46
+ end
47
+ }.to raise_error(Lifen::UserAlreadyExistingError)
48
+ end
49
+ end
50
+
51
+ context 'valid attributes' do
52
+ let(:user) { Lifen::User.new(email: "valid-email-spec@domain.tld") }
53
+
54
+ it 'creates the user' do
55
+
56
+ VCR.use_cassette "users/create/valid_attributes" do
57
+ user.create!
58
+ end
59
+
60
+ expect(user.token).to_not be_nil
61
+ expect(user.uuid).to_not be_nil
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+
68
+ describe ':refresh_token' do
69
+
70
+ context 'invalid user uuid' do
71
+
72
+ let(:user) { Lifen::User.new(uuid: "invalid-user-uuid") }
73
+
74
+ it 'raises an error' do
75
+ expect{
76
+ VCR.use_cassette "users/refresh/invalid_user_uuid" do
77
+ user.refresh_token
78
+ end
79
+ }.to raise_error(Lifen::Error)
80
+ end
81
+ end
82
+
83
+ context 'valid user uuid' do
84
+
85
+ let(:user) { Lifen::User.new(uuid: "valid_uuid") }
86
+
87
+ it 'raises an error' do
88
+
89
+ previous_token = user.token
90
+
91
+ VCR.use_cassette "users/refresh/valid_user_uuid" do
92
+ user.refresh_token
93
+ end
94
+
95
+ expect(user.token).to_not be_nil
96
+ expect(user.token).to_not eq previous_token
97
+ end
98
+ end
99
+
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lifen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Etienne Depaulis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.24'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.24'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: virtus
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ description: Lifen API ruby client
126
+ email:
127
+ - etienne.depaulis@honestica.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".ruby-version"
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - License.txt
138
+ - README.md
139
+ - Rakefile
140
+ - lib/lifen.rb
141
+ - lib/lifen/app_authenticated_client.rb
142
+ - lib/lifen/authentication.rb
143
+ - lib/lifen/base.rb
144
+ - lib/lifen/client.rb
145
+ - lib/lifen/configuration.rb
146
+ - lib/lifen/error.rb
147
+ - lib/lifen/flow.rb
148
+ - lib/lifen/flows.rb
149
+ - lib/lifen/user.rb
150
+ - lib/lifen/user_authenticated_client.rb
151
+ - lib/lifen/version.rb
152
+ - lifen.gemspec
153
+ - spec/cassettes/flows/attach_users/invalid_flow_uuid.yml
154
+ - spec/cassettes/flows/attach_users/invalid_user_uuid.yml
155
+ - spec/cassettes/flows/attach_users/valid.yml
156
+ - spec/cassettes/flows/create.yml
157
+ - spec/cassettes/flows/detach_users/valid.yml
158
+ - spec/cassettes/flows/detach_users/valid_again.yml
159
+ - spec/cassettes/flows/invalid_token.yml
160
+ - spec/cassettes/flows/valid_token.yml
161
+ - spec/cassettes/users/create/existing_user.yml
162
+ - spec/cassettes/users/create/invalid_token.yml
163
+ - spec/cassettes/users/create/missing_fields.yml
164
+ - spec/cassettes/users/create/valid_attributes.yml
165
+ - spec/cassettes/users/refresh/invalid_user_uuid.yml
166
+ - spec/cassettes/users/refresh/valid_user_uuid.yml
167
+ - spec/flows_spec.rb
168
+ - spec/spec_helper.rb
169
+ - spec/users_spec.rb
170
+ homepage: https://github.com/honestica/lifen
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.5.1
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Lifen JSON API ruby client
194
+ test_files:
195
+ - spec/cassettes/flows/attach_users/invalid_flow_uuid.yml
196
+ - spec/cassettes/flows/attach_users/invalid_user_uuid.yml
197
+ - spec/cassettes/flows/attach_users/valid.yml
198
+ - spec/cassettes/flows/create.yml
199
+ - spec/cassettes/flows/detach_users/valid.yml
200
+ - spec/cassettes/flows/detach_users/valid_again.yml
201
+ - spec/cassettes/flows/invalid_token.yml
202
+ - spec/cassettes/flows/valid_token.yml
203
+ - spec/cassettes/users/create/existing_user.yml
204
+ - spec/cassettes/users/create/invalid_token.yml
205
+ - spec/cassettes/users/create/missing_fields.yml
206
+ - spec/cassettes/users/create/valid_attributes.yml
207
+ - spec/cassettes/users/refresh/invalid_user_uuid.yml
208
+ - spec/cassettes/users/refresh/valid_user_uuid.yml
209
+ - spec/flows_spec.rb
210
+ - spec/spec_helper.rb
211
+ - spec/users_spec.rb