roqua-core-api 0.0.24 → 0.0.25

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: d816a42b16da76cfcbb6812351e8671667f632a4
4
- data.tar.gz: 60ab8b8db1736cd59c05d0acfe4e2ee04714767c
3
+ metadata.gz: 7110f0db271cc5c78369d2dcc5f788da9d965097
4
+ data.tar.gz: 9925a6328dd33176e147b12d5c996e1c8e798b3d
5
5
  SHA512:
6
- metadata.gz: f977aa5267f7718426a3c1887082a1ba32261d3003c5b246e6ca0cdb326249ed33b0c69194a97071a322fe2e8a01097b4ad0b7d2e1a37c85b932207d2f51b444
7
- data.tar.gz: ee993463a750812373ca0db0d0002ab41303f5fd10fc412a05aca8ec2c1e99f0c9a884e8b621fe5daaa46fe856dd21cb9161912520ff9eaa4676748108f44fa3
6
+ metadata.gz: 82e7756d106c5023ab0f9b7710a652ec0f454a1d314db93466a84fe91c9f4df2976107c2a2529d45ac6fc9f75d7b0d618d11499aa06627dce274141b002d5ded
7
+ data.tar.gz: 4dff71200b5528b02e093c6e21b2caeea1dd529f44b7e2ad251c97e568dedb254915ed239c3368203170f8b66cf29d0f1a9ca9352dfeed363d679725dc08b557
data/ChangeLog.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.0.25 / 2014-03-26
2
+
3
+ * added dossiers list
4
+
1
5
  ### 0.0.24 / 2014-03-24
2
6
 
3
7
  * added person_id to info hash.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  * [Homepage](https://github.com/marten/core_api#readme)
4
4
  * [Issues](https://github.com/marten/core_api/issues)
5
- * [Documentation](http://rubydoc.info/gems/core_api/frames)
5
+ * [Documentation](http://rubydoc.info/gems/roqua-core-api/frames)
6
6
  * [Email](mailto:marten at veldthuis.com)
7
7
 
8
8
  ## Description
@@ -21,6 +21,10 @@ TODO: Description
21
21
 
22
22
  $ gem install core_api
23
23
 
24
+ ### Translations
25
+
26
+ Make sure you have the standard active validations translations (errors.messages) and add to it a translations for errors.messages.invalid_email.
27
+
24
28
  ## Copyright
25
29
 
26
30
  Copyright (c) 2014 Marten Veldthuis
@@ -0,0 +1,22 @@
1
+ module Roqua
2
+ module CoreApi
3
+ # @api private
4
+ class Dossiers < ActiveInteraction::Base
5
+ model :session, class: Sessions::OAuthSession
6
+
7
+ # usage:
8
+ # Roqua.CoreApi.Dossiers.run!.each do |d|
9
+ # puts d.id, d.birth_year, d.gender
10
+ # end
11
+ def execute
12
+ response = session.get "/dossiers"
13
+ create_enum(response['headers'], response['rows'])
14
+ end
15
+
16
+ def create_enum(headers, rows)
17
+ row_class = Struct.new(*headers.map(&:to_sym))
18
+ rows.lazy.map { |row| row_class.new(*row) }.to_enum
19
+ end
20
+ end
21
+ end
22
+ end
@@ -41,11 +41,7 @@ module Roqua
41
41
  when 200..299, 422
42
42
  response
43
43
  when 401
44
- if response['no_session']
45
- fail NoSession
46
- else
47
- fail Unauthorized
48
- end
44
+ access_denied(response)
49
45
  else
50
46
  fail response.parsed_response || 'error'
51
47
  end
@@ -15,6 +15,15 @@ module Roqua
15
15
 
16
16
  private
17
17
 
18
+ # handle 401 response.
19
+ def access_denied(response)
20
+ if response.headers['WWW-Authenticate']
21
+ fail 'basic auth for core invalid'
22
+ else
23
+ fail Unauthorized
24
+ end
25
+ end
26
+
18
27
  def basic_auth
19
28
  {username: username, password: password}
20
29
  end
@@ -21,6 +21,14 @@ module Roqua
21
21
 
22
22
  private
23
23
 
24
+ def access_denied(response)
25
+ if response['no_session']
26
+ fail NoSession
27
+ else
28
+ fail Unauthorized
29
+ end
30
+ end
31
+
24
32
  def headers
25
33
  {"Authorization" => "Bearer #{access_token}"}
26
34
  end
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module CoreApi
3
- VERSION = '0.0.24'
3
+ VERSION = '0.0.25'
4
4
  end
5
5
  end
@@ -2,6 +2,7 @@ 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/dossiers'
5
6
  require 'roqua/core_api/create_dossier'
6
7
  require 'roqua/core_api/create_dossier_group'
7
8
  require 'roqua/core_api/send_email_to'
@@ -59,22 +59,6 @@ describe AuthSession do
59
59
  expect(session.get('/some_path')['errors']['column']).to eq ["wrong"]
60
60
  end
61
61
 
62
- it 'raises a no_session error when response is 401 with a no_session response' do
63
- stub_request(:get, 'http://core.dev/api/v1/some_path.json?').to_return(
64
- status: 401,
65
- body: '{ "no_session": true }',
66
- headers: { 'Content-Type' => 'application/json' })
67
- expect { session.get '/some_path' }.to raise_error(NoSession)
68
- end
69
-
70
- it 'raises a unauthorized error when response is 401 without a no_session response' do
71
- stub_request(:get, 'http://core.dev/api/v1/some_path.json?').to_return(
72
- status: 401,
73
- body: '',
74
- headers: { 'Content-Type' => 'application/json' })
75
- expect { session.get '/some_path' }.to raise_error(Unauthorized)
76
- end
77
-
78
62
  it 'throws an error if the reponse is not within the 200 range' do
79
63
  allow(response).to receive(:code).and_return(500)
80
64
  allow(HTTParty).to receive(:get).and_return(response)
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'webmock/rspec'
2
3
 
3
4
  describe BasicAuthSession do
4
5
  describe '#initialize' do
@@ -48,4 +49,23 @@ describe BasicAuthSession do
48
49
  expect(session.send :basic_auth).to eq(username: 'some_username', password: 'some_password')
49
50
  end
50
51
  end
52
+
53
+ describe '#access_denied' do
54
+ let(:session) { Roqua::CoreApi.basic_auth_session username: 'some_username' }
55
+ let(:response) { double('response', code: 401, parsed_response: 'some_response') }
56
+
57
+ # No NoSession error in this case, since it's not something the user can fix.
58
+ # Plus client_portal redirects to oauth login if they get NoSession.
59
+ it 'throws a StandardError if the basic auth is incorrect' do
60
+ allow(HTTParty).to receive(:get).and_return(response)
61
+ allow(response).to receive(:headers).and_return('WWW-Authenticate' => 'Basic realm="Application"')
62
+ expect { session.get '/some_path' }.to raise_error(StandardError)
63
+ end
64
+
65
+ it 'throws a Unauthorized error on 401 without www-authenticate header' do
66
+ allow(HTTParty).to receive(:get).and_return(response)
67
+ allow(response).to receive(:headers).and_return('foo' => 'bar')
68
+ expect { session.get '/some_path' }.to raise_error(Roqua::CoreApi::Unauthorized)
69
+ end
70
+ end
51
71
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'webmock/rspec'
2
3
 
3
4
  describe OAuthSession do
4
5
  let(:session) { Fabricate :oauth_session }
@@ -41,4 +42,22 @@ describe OAuthSession do
41
42
  session.get 'some_path'
42
43
  end
43
44
  end
45
+
46
+ describe '#access_denied' do
47
+ it 'raises a no_session error when response is 401 with a no_session response' do
48
+ stub_request(:get, 'http://core.dev/api/v1/some_path.json?').to_return(
49
+ status: 401,
50
+ body: '{ "no_session": true }',
51
+ headers: { 'Content-Type' => 'application/json' })
52
+ expect { session.get '/some_path' }.to raise_error(NoSession)
53
+ end
54
+
55
+ it 'raises a unauthorized error when response is 401 without a no_session response' do
56
+ stub_request(:get, 'http://core.dev/api/v1/some_path.json?').to_return(
57
+ status: 401,
58
+ body: '',
59
+ headers: { 'Content-Type' => 'application/json' })
60
+ expect { session.get '/some_path' }.to raise_error(Unauthorized)
61
+ end
62
+ end
44
63
  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.24
4
+ version: 0.0.25
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-24 00:00:00.000000000 Z
11
+ date: 2014-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -185,6 +185,7 @@ files:
185
185
  - lib/roqua/core_api.rb
186
186
  - lib/roqua/core_api/create_dossier.rb
187
187
  - lib/roqua/core_api/create_dossier_group.rb
188
+ - lib/roqua/core_api/dossiers.rb
188
189
  - lib/roqua/core_api/models.rb
189
190
  - lib/roqua/core_api/models/dossier.rb
190
191
  - lib/roqua/core_api/models/dossier_group.rb