roqua-core-api 0.0.12 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71324b1ca72553ac40ddcf189844d29165eb3ac6
4
- data.tar.gz: 168757a7425bafbb275d4e9ff8f76ba8a15ac575
3
+ metadata.gz: b6629a5792c576139c32eaf0a255f0785ab591bf
4
+ data.tar.gz: 899779caf5d2fb5352a44a21136097830c298f44
5
5
  SHA512:
6
- metadata.gz: 551a34059fa64fa400f80da95efc44eaae46b517847f47407d1680145c189606947d7274590e208c3cdd62a281bc9291f3e63037addd54356a9d01f607654d6e
7
- data.tar.gz: 62a53f9504b6ee2a45e07714760a50ecb536e0bd88ade84edffc95c15bd93616b494f9fd8115480d87eb1c016eb0b844280a9a282509fdafca331873cc4588ae
6
+ metadata.gz: a015867ee81c83bf90d53a458606ea866aab4dccfe90268754dce4936d66d3da4e6fd6b85eb7ab9cb4504f66ed857484ec91c08b72c83c1944d0fecb428f59ac
7
+ data.tar.gz: 79ba4c56d28fd44fc1589dbeecdc7d6a99a1b4b688bbba5f8c869542bf86c4be6032921f4d839c427fe5c21087a04a9b7345ff5a96dc19ec32f066a4cb1bf10c
data/ChangeLog.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.0.13 / 2014-03-11
2
+
3
+ * Fix doorkeeper setup
4
+
1
5
  ### 0.0.12 / 2014-03-10
2
6
 
3
7
  * Update gemspec to contain omniauth-oauth2
data/core_api.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency 'httparty', '~> 0.12.0'
21
21
  gem.add_dependency 'active_interaction', '~> 1.0.4'
22
22
  gem.add_dependency 'omniauth-oauth2', '~> 1.1.2'
23
+ gem.add_dependency 'activemodel', '>= 3.2', '< 5'
23
24
 
24
25
  gem.add_development_dependency 'bundler', '~> 1.0'
25
26
  gem.add_development_dependency 'rake', '~> 10.0'
@@ -1,15 +1,35 @@
1
- module Roqua
2
- module CoreApi
3
- module Models
4
- class Person
5
- def initialize(attributes)
6
- @attributes = attributes
7
- end
8
-
9
- def id
10
- @attributes.fetch("id")
11
- end
12
- end
13
- end
1
+ class Roqua::CoreApi::Models::Person
2
+ # when support for rails 3 is dropped: replace by include ActiveModel::Model
3
+ extend ActiveModel::Naming
4
+ extend ActiveModel::Translation
5
+ include ActiveModel::Validations
6
+ include ActiveModel::Conversion
7
+ include ActiveModel::Serialization
8
+
9
+ attr_reader :id
10
+ attr_accessor :role, :firstname, :lastname, :initials,
11
+ :email, :phone_home, :phone_work, :phone_cell,
12
+ :birthdate, :gender, :country_of_birth,
13
+ :address_type, :street, :city, :zipcode, :country
14
+
15
+ validates :role, inclusion: { in: %w( professional patient parent ) }
16
+
17
+ def initialize(params = {})
18
+ @id = params.delete('id')
19
+ params.each do |attr, value|
20
+ public_send("#{attr}=", value)
21
+ end if params
22
+
23
+ super()
24
+ end
25
+
26
+ def assign_attributes(params = {})
27
+ params.each do |attr, value|
28
+ public_send("#{attr}=", value)
29
+ end if params
30
+ end
31
+
32
+ def attributes
33
+ as_json
14
34
  end
15
35
  end
@@ -1,3 +1,4 @@
1
1
  require 'roqua/core_api/models/dossier_group'
2
2
  require 'roqua/core_api/models/dossier'
3
+ require 'active_model'
3
4
  require 'roqua/core_api/models/person'
@@ -0,0 +1,14 @@
1
+ module Roqua
2
+ module CoreApi
3
+ # @api private
4
+ class People < ActiveInteraction::Base
5
+ model :session, class: Sessions::OAuthSession
6
+ string :dossier_id
7
+
8
+ def execute
9
+ response = session.get "/dossiers/#{dossier_id}/people"
10
+ response["people"].map { |p| Models::Person.new(p) }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Roqua
2
+ module CoreApi
3
+ # @api private
4
+ class Person < ActiveInteraction::Base
5
+ model :session, class: Sessions::OAuthSession
6
+ string :person_id
7
+
8
+ def execute
9
+ response = session.get "/people/#{person_id}"
10
+ Models::Person.new(response['person'])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -3,38 +3,42 @@ module Roqua
3
3
  module Sessions
4
4
  class AuthSession
5
5
  attr_reader :core_host
6
+ attr_reader :default_timeout
6
7
 
7
- def initialize(core_host: ENV['CORE_HOST'])
8
+ # timeout for requests in seconds
9
+ def initialize(core_host: ENV['CORE_HOST'], timeout: 5)
8
10
  @core_host = core_host
11
+ @default_timeout = timeout
9
12
  end
10
13
 
11
- def get(path, params = {})
14
+ def get(path, timeout: default_timeout, **params)
12
15
  perform_request_or_fail do
13
- HTTParty.get(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth)
16
+ HTTParty.get(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth, timeout: timeout)
14
17
  end
15
18
  end
16
19
 
17
- def post(path, params = {})
20
+ def post(path, timeout: default_timeout, **params)
18
21
  perform_request_or_fail do
19
- HTTParty.post(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth)
22
+ HTTParty.post(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth, timeout: timeout)
20
23
  end
21
24
  end
22
25
 
23
- def patch(path, params = {})
26
+ def patch(path, timeout: default_timeout, **params)
24
27
  perform_request_or_fail do
25
- HTTParty.patch(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth)
28
+ HTTParty.patch(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth, timeout: timeout)
26
29
  end
27
30
  end
28
31
 
29
- def delete(path, params = {})
30
- HTTParty.delete(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth)
32
+ def delete(path, timeout: default_timeout, **params)
33
+ HTTParty.delete(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth, timeout: timeout)
31
34
  end
32
35
 
33
36
  private
34
37
 
35
38
  def perform_request_or_fail(&block)
36
39
  response = yield
37
- fail response.parsed_response unless (200..299).include? response.code
40
+ fail response.parsed_response unless (200..299).include?(response.code) ||
41
+ 422 == response.code
38
42
  response
39
43
  end
40
44
 
@@ -0,0 +1,33 @@
1
+ module Roqua
2
+ module CoreApi
3
+ # @api private
4
+ class UpdatePerson < ActiveInteraction::Base
5
+ model :session, class: Sessions::OAuthSession
6
+ model :person, class: Models::Person
7
+
8
+ # Saves the person attributes to server.
9
+ # Returns true on success, false on validation errors.
10
+ # Adds errors to person object based on I18n errors.messages.
11
+ # Raises on other errors.
12
+ def execute
13
+ response = session.patch "/people/#{person.id}", person: person.serializable_hash
14
+ if response.code == 422
15
+ errors_to_object(response, person)
16
+ false
17
+ else
18
+ true
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def errors_to_object(json, obj)
25
+ json['errors'].each do |attribute, errors|
26
+ errors.each do |error|
27
+ obj.errors.add(attribute, I18n.t("errors.messages.#{error}"))
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module CoreApi
3
- VERSION = "0.0.12"
3
+ VERSION = "0.0.13"
4
4
  end
5
5
  end
@@ -2,8 +2,10 @@ require 'active_interaction'
2
2
  require 'roqua/core_api/version'
3
3
  require 'roqua/core_api/sessions'
4
4
  require 'roqua/core_api/models'
5
- require 'roqua/core_api/me'
6
5
  require 'roqua/core_api/create_dossier'
7
6
  require 'roqua/core_api/create_dossier_group'
8
7
  require 'roqua/core_api/send_email_to'
9
8
  require 'roqua/core_api/send_invite_email'
9
+ require 'roqua/core_api/people'
10
+ require 'roqua/core_api/person'
11
+ require 'roqua/core_api/update_person'
@@ -15,7 +15,7 @@ module OmniAuth
15
15
  end
16
16
 
17
17
  def raw_info
18
- @raw_info ||= access_token.get('/api/v1/me.json').parsed
18
+ @raw_info ||= access_token.get('/api/v1/me.json').parsed['me']
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ module Roqua
4
+ module CoreApi
5
+ module Models
6
+ describe Person do
7
+ let(:valid_person) { Person.new }
8
+
9
+ describe '#new' do
10
+ subject { Person.new firstname: 'first', lastname: 'last' }
11
+ it 'accepts a hash of attributes' do
12
+ expect(subject.firstname).to eq 'first'
13
+ end
14
+ end
15
+
16
+ describe '#assign_attributes' do
17
+ subject { Person.new firstname: 'first', lastname: 'last' }
18
+ it 'accepts a hash of attributes' do
19
+ subject.assign_attributes(firstname: 'new')
20
+ expect(subject.firstname).to eq 'new'
21
+ end
22
+ end
23
+
24
+ describe '#role' do
25
+ it 'allows values: professional patient parent' do
26
+ %w( professional patient parent ).each do |role|
27
+ valid_person.role = role
28
+ expect(valid_person.valid?).to be_truthy
29
+ end
30
+ end
31
+ it 'does not allow other values' do
32
+ valid_person.role = 'foobar'
33
+ expect(valid_person.valid?).to be_falsy
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -17,6 +17,11 @@ describe AuthSession do
17
17
  ENV['CORE_HOST'] = orginal_env_core_host
18
18
  expect(session.core_host).to eq('some_env_core_host')
19
19
  end
20
+
21
+ it 'defaults the timeout to 5 seconds' do
22
+ session = AuthSession.new
23
+ expect(session.default_timeout).to eq 5
24
+ end
20
25
  end
21
26
 
22
27
  describe '#get' do
@@ -26,7 +31,8 @@ describe AuthSession do
26
31
  expect(HTTParty).to receive(:get).with('http://core.dev/api/v1/some_path.json',
27
32
  query: {some: 'param'},
28
33
  headers: {some: 'header'},
29
- basic_auth: {username: 'some_username', password: 'some_password'})
34
+ basic_auth: {username: 'some_username', password: 'some_password'},
35
+ timeout: 5)
30
36
  .and_return(response)
31
37
  session.get '/some_path', some: 'param'
32
38
  end
@@ -36,7 +36,8 @@ describe OAuthSession do
36
36
  expect(HTTParty).to receive(:get).with(an_instance_of(String),
37
37
  headers: {"Authorization" => "Bearer some_access_token"},
38
38
  query: {},
39
- basic_auth: nil).and_return(response)
39
+ basic_auth: nil,
40
+ timeout: 5).and_return(response)
40
41
  session.get 'some_path'
41
42
  end
42
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-core-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -52,6 +52,26 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.1.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: activemodel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '5'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '3.2'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '5'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: bundler
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -143,17 +163,19 @@ files:
143
163
  - lib/roqua/core_api.rb
144
164
  - lib/roqua/core_api/create_dossier.rb
145
165
  - lib/roqua/core_api/create_dossier_group.rb
146
- - lib/roqua/core_api/me.rb
147
166
  - lib/roqua/core_api/models.rb
148
167
  - lib/roqua/core_api/models/dossier.rb
149
168
  - lib/roqua/core_api/models/dossier_group.rb
150
169
  - lib/roqua/core_api/models/person.rb
170
+ - lib/roqua/core_api/people.rb
171
+ - lib/roqua/core_api/person.rb
151
172
  - lib/roqua/core_api/send_email_to.rb
152
173
  - lib/roqua/core_api/send_invite_email.rb
153
174
  - lib/roqua/core_api/sessions.rb
154
175
  - lib/roqua/core_api/sessions/auth_session.rb
155
176
  - lib/roqua/core_api/sessions/basic_auth_session.rb
156
177
  - lib/roqua/core_api/sessions/oauth_session.rb
178
+ - lib/roqua/core_api/update_person.rb
157
179
  - lib/roqua/core_api/version.rb
158
180
  - lib/roqua/omniauth/rails_initializer.rb
159
181
  - lib/roqua/omniauth/strategies/doorkeeper.rb
@@ -163,7 +185,7 @@ files:
163
185
  - spec/fabricators/oauth_session_fabricator.rb
164
186
  - spec/lib/roqua/core_api/create_dossier_group_spec.rb
165
187
  - spec/lib/roqua/core_api/create_dossier_spec.rb
166
- - spec/lib/roqua/core_api/me_spec.rb
188
+ - spec/lib/roqua/core_api/models/person_spec.rb
167
189
  - spec/lib/roqua/core_api/send_email_to_spec.rb
168
190
  - spec/lib/roqua/core_api/send_invite_email_spec.rb
169
191
  - spec/lib/roqua/core_api/sessions/auth_session_spec.rb
@@ -201,7 +223,7 @@ test_files:
201
223
  - spec/fabricators/oauth_session_fabricator.rb
202
224
  - spec/lib/roqua/core_api/create_dossier_group_spec.rb
203
225
  - spec/lib/roqua/core_api/create_dossier_spec.rb
204
- - spec/lib/roqua/core_api/me_spec.rb
226
+ - spec/lib/roqua/core_api/models/person_spec.rb
205
227
  - spec/lib/roqua/core_api/send_email_to_spec.rb
206
228
  - spec/lib/roqua/core_api/send_invite_email_spec.rb
207
229
  - spec/lib/roqua/core_api/sessions/auth_session_spec.rb
@@ -1,12 +0,0 @@
1
- module Roqua
2
- module CoreApi
3
- # @api private
4
- class Me < ActiveInteraction::Base
5
- model :session, class: Sessions::OAuthSession
6
-
7
- def execute
8
- session.get('/me')['me']
9
- end
10
- end
11
- end
12
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Me do
4
- let(:session) { Fabricate :oauth_session }
5
-
6
- it 'performs a get on the /me api path' do
7
- expect(session).to receive(:get).with('/me').and_return({})
8
- Me.run!(session: session)
9
- end
10
-
11
- it 'returns the me entry from the response' do
12
- allow(session).to receive(:get).with('/me').and_return 'me' => 'some_info'
13
- expect(Me.run!(session: session)).to eq('some_info')
14
- end
15
- end