finapps 2.0.16 → 2.0.17

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: 7acc8269730e6c9379955eadb06949d765436767
4
- data.tar.gz: 60954938368277bfd3d29b76ab001c67f71025d9
3
+ metadata.gz: d92b2ccd2cbe3f2d7088938232d1c73f0c0c95b4
4
+ data.tar.gz: 5b0f6965de1b07f36ce1f0584e475a7a8e8d1461
5
5
  SHA512:
6
- metadata.gz: eb7dae092bd33046c5f7f605e92eb4b6f454595a9a8089fbc1543308dafc78166e9fb3fb5c922efe828a38a624f9511cfc1bcb456266a24e3485174badb75740
7
- data.tar.gz: fcb7e7fd5186a691e8948a67d874bbc090b99f34226a9c9bd7b360d8a3e4289581b8ab29d9693db817fcbcd6d3d771f9fa5bca223347193c7ac621309a0dc919
6
+ metadata.gz: 5a909e96ebb509f0f975b2892355343ba890d1cf85eaca4d0b368f01b3d7a8a6054521c0ad93327128e0484fc0a1eae2bed91f596c0c18f987c0d7ecdcd9bdd3
7
+ data.tar.gz: 6156ca6318427f8f0c8557182d8b965a58a7aedee84ba8c06c121f90adf4ba81d0c43972fd8ac846eca42c74356ea93b29e356216dd2dbe66e9c8af6b880984a
data/README.md CHANGED
@@ -5,6 +5,7 @@ FinApps Ruby-Client
5
5
  [![Gem Version](https://badge.fury.io/rb/finapps.svg)](https://badge.fury.io/rb/finapps)
6
6
  [![Build Status](http://img.shields.io/travis/finapps/ruby-client.svg?style=flat-square)](https://travis-ci.org/finapps/ruby-client)
7
7
  [![Code Climate](https://codeclimate.com/github/finapps/ruby-client/badges/gpa.svg)](https://codeclimate.com/github/finapps/ruby-client)
8
+ [![Test Coverage](https://codeclimate.com/github/finapps/ruby-client/badges/coverage.svg)](https://codeclimate.com/github/finapps/ruby-client/coverage)
8
9
  [![Dependency Status](https://gemnasium.com/badges/github.com/finapps/ruby-client.svg)](https://gemnasium.com/github.com/finapps/ruby-client)
9
10
  [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://finapps.mit-license.org)
10
11
 
@@ -38,7 +38,7 @@ module FinApps
38
38
  raise FinApps::MissingArgumentsError.new 'Missing argument: path.' if path.blank?
39
39
  raise FinApps::MissingArgumentsError.new 'Missing argument: method.' if method.blank?
40
40
 
41
- response, error_messages = execute_request(method, params, path)
41
+ response, error_messages = execute_request(path, method, params)
42
42
  result = if empty?(response)
43
43
  nil
44
44
  else
@@ -54,10 +54,10 @@ module FinApps
54
54
  response.blank? || (response.respond_to?(:body) && response.body.blank?)
55
55
  end
56
56
 
57
- def execute_request(method, params, path)
57
+ def execute_request(path, method, params)
58
58
  error_messages = []
59
59
  begin
60
- response = execute_method method, params, path
60
+ response = execute_method path, method, params
61
61
  rescue FinApps::InvalidArgumentsError,
62
62
  FinApps::MissingArgumentsError,
63
63
  Faraday::Error::ConnectionFailed => error
@@ -86,7 +86,7 @@ module FinApps
86
86
  ['Unexpected error.']
87
87
  end
88
88
 
89
- def execute_method(method, params, path)
89
+ def execute_method(path, method, params)
90
90
  case method
91
91
  when :get
92
92
  get(path)
@@ -24,6 +24,10 @@ module FinApps
24
24
  @users ||= FinApps::REST::Users.new self
25
25
  end
26
26
 
27
+ def sessions
28
+ @sessions ||= FinApps::REST::Sessions.new self
29
+ end
30
+
27
31
  def order_tokens
28
32
  @order_tokens ||= FinApps::REST::OrderTokens.new self
29
33
  end
@@ -11,39 +11,37 @@ module FinApps
11
11
  def initialize(client)
12
12
  raise MissingArgumentsError.new 'Missing argument: client.' if client.nil?
13
13
  raise InvalidArgumentsError.new 'Invalid argument: client.' unless client.is_a?(FinApps::REST::Client)
14
+
14
15
  @client = client
15
16
  end
16
17
 
17
18
  def create(params={}, path=nil)
18
- path = end_point if path.nil?
19
- logger.debug "#{self.class.name}##{__method__} => path: #{path} params: #{params}"
20
- results, error_messages = client.send_request(path, :post, params)
21
- [results, error_messages]
19
+ request_with_body(path, :post, params)
22
20
  end
23
21
 
24
22
  def update(params={}, path=nil)
25
- path = end_point if path.nil?
26
- logger.debug "#{self.class.name}##{__method__} => path: #{path} params: #{params}"
27
- results, error_messages = client.send_request(path, :put, params)
28
- [results, error_messages]
23
+ request_with_body(path, :put, params)
29
24
  end
30
25
 
31
26
  def show(id=nil, path=nil)
32
- raise MissingArgumentsError.new 'Missing argument: id.' if id.nil? && path.nil?
33
-
34
- path = "#{end_point}/:id".sub ':id', ERB::Util.url_encode(id) if path.nil?
35
- logger.debug "#{self.class.name}##{__method__} => path: #{path}"
36
- results, error_messages = client.send_request(path, :get)
37
- [results, error_messages]
27
+ request_without_body(path, :get, id)
38
28
  end
39
29
 
40
30
  def destroy(id=nil, path=nil)
41
- raise MissingArgumentsError.new 'Missing argument: id.' if id.nil? && path.nil?
31
+ request_without_body(path, :delete, id)
32
+ end
42
33
 
34
+ def request_without_body(path, method, id)
35
+ raise MissingArgumentsError.new 'Missing argument: id.' if id.nil? && path.nil?
43
36
  path = "#{end_point}/:id".sub ':id', ERB::Util.url_encode(id) if path.nil?
44
- logger.debug "#{self.class.name}##{__method__} => path: #{path}"
45
- results, error_messages = client.send_request(path, :delete)
46
- [results, error_messages]
37
+ request_with_body path, method, {}
38
+ end
39
+
40
+ def request_with_body(path, method, params)
41
+ path = end_point if path.nil?
42
+ logger.debug "#{self.class.name}##{__method__} => path: #{path} params: #{params}"
43
+
44
+ client.send_request path, method, params
47
45
  end
48
46
 
49
47
  protected
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module FinApps
3
+ module REST
4
+ class Sessions < FinApps::REST::Resources # :nodoc:
5
+ require 'erb'
6
+
7
+ using ObjectExtensions
8
+ using StringExtensions
9
+
10
+ # @param [Hash] params
11
+ # @return [Array<String>]
12
+ def create(params)
13
+ raise InvalidArgumentsError.new 'Invalid argument: params.' unless validates params
14
+
15
+ super params, 'login'
16
+ end
17
+
18
+ private
19
+
20
+ def validates(params)
21
+ params.key?(:email) && params[:email].present? && params.key?(:password) && params[:password].present?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module FinApps
3
- VERSION = '2.0.16'
3
+ VERSION = '2.0.17'
4
4
  end
data/lib/finapps.rb CHANGED
@@ -22,6 +22,7 @@ require 'finapps/rest/defaults'
22
22
  require 'finapps/rest/resources'
23
23
 
24
24
  require 'finapps/rest/users'
25
+ require 'finapps/rest/sessions'
25
26
  require 'finapps/rest/order_tokens'
26
27
  require 'finapps/rest/orders'
27
28
 
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe FinApps::Middleware::RaiseError do
3
+ let(:fake_app) { proc {|env| env } }
4
+ Env = Struct.new(:status, :response_headers, :body)
5
+
6
+ describe '#on_complete' do
7
+ subject { FinApps::Middleware::RaiseError.new(fake_app) }
8
+
9
+ context 'for succesful requests' do
10
+ let(:env) { Env.new(200) }
11
+ it { expect { subject.on_complete(env) }.not_to raise_error }
12
+ end
13
+ context 'for client errors' do
14
+ let(:env) { Env.new(401, {}, '{"messages":["Invalid User Identifier or Credentials"]}') }
15
+ error_message = 'the server responded with status 401'
16
+ it { expect { subject.on_complete(env) }.to raise_error(Faraday::Error::ClientError, error_message) }
17
+ end
18
+ context 'for connection failed error' do
19
+ let(:env) { Env.new(407) }
20
+ error_message = '407 "Proxy Authentication Required"'
21
+ it { expect { subject.on_complete(env) }.to raise_error(Faraday::Error::ConnectionFailed, error_message) }
22
+ end
23
+ end
24
+ end
@@ -69,9 +69,8 @@ RSpec.describe FinApps::REST::BaseClient do
69
69
  subject { FinApps::REST::BaseClient.new(valid_tenant_options).send_request('client_error', :get) }
70
70
 
71
71
  it('result is null') { expect(subject[RESPONSE]).to be_nil }
72
- it('error_messages is not null') { expect(subject[ERROR_MESSAGES]).not_to be_nil }
73
72
  it('error_messages is an array') { expect(subject[ERROR_MESSAGES]).to be_a(Array) }
74
- it('error messages array contains elements') { expect(subject[ERROR_MESSAGES].length).to be > 0 }
73
+ it('error_messages gets populated'){expect(subject[ERROR_MESSAGES].first).to eq 'Password Minimum size is 8'}
75
74
  end
76
75
 
77
76
  context 'for server errors' do
@@ -97,4 +96,10 @@ RSpec.describe FinApps::REST::BaseClient do
97
96
  end
98
97
  end
99
98
  end
99
+
100
+ describe '#method_missing' do
101
+ context 'for unsupported methods' do
102
+ it { expect { subject.unsupported }.to raise_error(NoMethodError) }
103
+ end
104
+ end
100
105
  end
@@ -13,7 +13,7 @@ RSpec.describe FinApps::REST::Client do
13
13
  context 'an instance of Client' do
14
14
  subject { FinApps::REST::Client.new(:company_identifier, :company_token) }
15
15
 
16
- %i(users orders order_tokens).each do |method|
16
+ %i(users sessions orders order_tokens).each do |method|
17
17
  it "responds to #{method}" do
18
18
  expect(subject).to respond_to(method)
19
19
  end
@@ -23,6 +23,10 @@ RSpec.describe FinApps::REST::Client do
23
23
  it { expect(subject.users).to be_an_instance_of(FinApps::REST::Users) }
24
24
  end
25
25
 
26
+ describe '#sessions' do
27
+ it { expect(subject.sessions).to be_an_instance_of(FinApps::REST::Sessions) }
28
+ end
29
+
26
30
  describe '#order_tokens' do
27
31
  it { expect(subject.order_tokens).to be_an_instance_of(FinApps::REST::OrderTokens) }
28
32
  end
@@ -34,7 +38,7 @@ RSpec.describe FinApps::REST::Client do
34
38
  # [:users, :institutions, :user_institutions, :transactions, :categories,
35
39
  # :budget_models, :budget_calculation, :budgets, :cashflows,
36
40
  # :alert, :alert_definition, :alert_preferences, :alert_settings, :rule_sets]
37
- %i(users orders order_tokens).each do |method|
41
+ %i(users sessions orders order_tokens).each do |method|
38
42
  it "memoizes the result of #{method}" do
39
43
  first = subject.send(method)
40
44
  second = subject.send(method)
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helpers/client'
3
+
4
+ RSpec.describe FinApps::REST::Sessions, 'initialized with valid FinApps::Client object' do
5
+ include SpecHelpers::Client
6
+
7
+ describe '#create' do
8
+ subject { FinApps::REST::Sessions.new(client) }
9
+ let(:create) { subject.create(credentials) }
10
+ let(:results) { create[0] }
11
+ let(:error_messages) { create[1] }
12
+
13
+ context 'when missing email or password' do
14
+ message = 'Invalid argument: params.'
15
+ it do
16
+ expect { subject.create(email: nil, password: 'password') }
17
+ .to raise_error(FinApps::InvalidArgumentsError, message)
18
+ end
19
+ it do
20
+ expect { subject.create(email: 'email', password: nil) }
21
+ .to raise_error(FinApps::InvalidArgumentsError, message)
22
+ end
23
+ end
24
+
25
+ context 'for invalid credentials' do
26
+ let(:credentials) { {email: 'email@domain.com', password: 'invalid_password'} }
27
+
28
+ it { expect { create }.not_to raise_error }
29
+ it('results is nil') { expect(results).to be_nil }
30
+ error_message = 'Invalid User Identifier or Credentials'
31
+ it('error_messages are populated') { expect(error_messages.first).to eq(error_message) }
32
+ end
33
+
34
+ context 'for valid credentials' do
35
+ let(:credentials) { {email: 'email@domain.com', password: 'valid_password'} }
36
+
37
+ it('results is a Hashie::Rash') { expect(results).to be_a(Hashie::Rash) }
38
+ it('token value is in the result') { expect(results).to respond_to(:token) }
39
+ it('error_messages is empty') { expect(error_messages).to be_empty }
40
+ end
41
+ end
42
+ end
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
+ require 'spec_helpers/client'
3
+
2
4
  RSpec.describe FinApps::REST::Users, 'initialized with valid FinApps::Client object' do
5
+ include SpecHelpers::Client
6
+
3
7
  missing_public_id = 'Missing argument: public_id.'
4
- client = FinApps::REST::Client.new :company_identifier, :company_token
5
8
 
6
9
  describe '#show' do
7
10
  subject(:users) { FinApps::REST::Users.new(client) }
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module SpecHelpers
3
+ module Client
4
+ def client
5
+ FinApps::REST::Client.new :tenant_id, :tenant_token
6
+ end
7
+ end
8
+ end
@@ -18,8 +18,19 @@ class FakeApi < Sinatra::Base
18
18
  get('/v2/users/valid_public_id') { json_response 200, 'user.json' }
19
19
  get('/v2/users/invalid_public_id') { json_response 404, 'resource_not_found.json' }
20
20
  put('/v2/users/valid_public_id') { status 204 }
21
- put('/v2/users/valid_public_id/password'){ json_response 200, 'user.json'}
22
- put('/v2/users/invalid_public_id/password'){ json_response 404, 'resource_not_found.json' }
21
+ put('/v2/users/valid_public_id/password') { json_response 200, 'user.json' }
22
+ put('/v2/users/invalid_public_id/password') { json_response 404, 'resource_not_found.json' }
23
+
24
+ # session
25
+ post('/v2/login') do
26
+ request.body.rewind
27
+ request_payload = JSON.parse request.body.read
28
+ if request_payload['password'] == 'valid_password'
29
+ json_response(200, 'user.json')
30
+ else
31
+ json_response(401, 'unauthorized.json')
32
+ end
33
+ end
23
34
 
24
35
  # relevance
25
36
  get('/v2/relevance/ruleset/names') { json_response 200, 'relevance_ruleset_names.json' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finapps
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.16
4
+ version: 2.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-26 00:00:00.000000000 Z
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -264,15 +264,17 @@ files:
264
264
  - lib/finapps/rest/order_tokens.rb
265
265
  - lib/finapps/rest/orders.rb
266
266
  - lib/finapps/rest/resources.rb
267
+ - lib/finapps/rest/sessions.rb
267
268
  - lib/finapps/rest/users.rb
268
269
  - lib/finapps/utils/loggeable.rb
269
270
  - lib/finapps/version.rb
270
271
  - lib/tasks/releaser.rake
271
272
  - spec/core_extensions/hash/compact_spec.rb
272
273
  - spec/core_extensions/object/is_integer_spec.rb
273
- - spec/middleware/accept_json_spec.rb
274
- - spec/middleware/tenant_authentication_spec.rb
275
- - spec/middleware/user_agent_spec.rb
274
+ - spec/middleware/request/accept_json_spec.rb
275
+ - spec/middleware/request/tenant_authentication_spec.rb
276
+ - spec/middleware/request/user_agent_spec.rb
277
+ - spec/middleware/response/raise_error_spec.rb
276
278
  - spec/rest/base_client_spec.rb
277
279
  - spec/rest/client_spec.rb
278
280
  - spec/rest/configuration_spec.rb
@@ -280,8 +282,10 @@ files:
280
282
  - spec/rest/order_tokens_spec.rb
281
283
  - spec/rest/orders_spec.rb
282
284
  - spec/rest/resources_spec.rb
285
+ - spec/rest/sessions_spec.rb
283
286
  - spec/rest/users_spec.rb
284
287
  - spec/spec_helper.rb
288
+ - spec/spec_helpers/client.rb
285
289
  - spec/support/fake_api.rb
286
290
  - spec/support/fixtures/error.json
287
291
  - spec/support/fixtures/order_token.json
@@ -316,23 +320,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
320
  version: '0'
317
321
  requirements: []
318
322
  rubyforge_project:
319
- rubygems_version: 2.5.1
323
+ rubygems_version: 2.6.6
320
324
  signing_key:
321
325
  specification_version: 4
322
326
  summary: FinApps REST API ruby client.
323
327
  test_files:
324
- - spec/core_extensions/hash/compact_spec.rb
325
- - spec/core_extensions/object/is_integer_spec.rb
326
- - spec/middleware/accept_json_spec.rb
327
- - spec/middleware/tenant_authentication_spec.rb
328
- - spec/middleware/user_agent_spec.rb
329
- - spec/rest/base_client_spec.rb
330
- - spec/rest/client_spec.rb
331
- - spec/rest/configuration_spec.rb
328
+ - spec/spec_helper.rb
329
+ - spec/support/fake_api.rb
330
+ - spec/spec_helpers/client.rb
331
+ - spec/middleware/request/user_agent_spec.rb
332
+ - spec/middleware/request/tenant_authentication_spec.rb
333
+ - spec/middleware/request/accept_json_spec.rb
334
+ - spec/middleware/response/raise_error_spec.rb
332
335
  - spec/rest/credentials_spec.rb
333
- - spec/rest/order_tokens_spec.rb
334
- - spec/rest/orders_spec.rb
335
336
  - spec/rest/resources_spec.rb
337
+ - spec/rest/sessions_spec.rb
338
+ - spec/rest/client_spec.rb
339
+ - spec/rest/orders_spec.rb
340
+ - spec/rest/order_tokens_spec.rb
341
+ - spec/rest/base_client_spec.rb
342
+ - spec/rest/configuration_spec.rb
336
343
  - spec/rest/users_spec.rb
337
- - spec/spec_helper.rb
338
- - spec/support/fake_api.rb
344
+ - spec/core_extensions/object/is_integer_spec.rb
345
+ - spec/core_extensions/hash/compact_spec.rb