finapps 2.0.30 → 2.1.1

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: e61830b719532ffe68a3133e861514c0080918ff
4
- data.tar.gz: 81d526e72235f792beca947b2647e702cf3d3e92
3
+ metadata.gz: 5096a6b1981fc503ff5718b188c8b54f960db534
4
+ data.tar.gz: 28f39fcf4370f57c640d9b7bb555585fa1fc6455
5
5
  SHA512:
6
- metadata.gz: 468d231c40ff6a9f766b2537d104b04483ae7ccbd199871cbb5f844136f01c2b13a26265aa53f8a5652b8c983febe25030f921a88fccd5b461a4a46b4a634b48
7
- data.tar.gz: 2c26b47ada9b8cec80d034e67717ba28ed19a86c9cc6f536a74eaf5bdfc9a3aac3606b2f663b75b7b2bc82763077dc143d4f124e909e3d490d16a06d29a0d1f3
6
+ metadata.gz: 25f29fe1caafca96681e176dba45ce2cd941eb83a357a635ee66f93a41238cadb4a07fccb14b6b22b6d3ab3d83b6546dd5848e3a775d582f73a10a49d0d7b3b8
7
+ data.tar.gz: 374ea976bc0ed5e4ccb93b390b618f64858f8353c19565b7fbcd44bc201efa701e51e41c0888e43f784ba69261939a1fbd5c09c9a46b2be3c4b5201bbc315196
data/finapps.gemspec CHANGED
@@ -4,6 +4,7 @@ lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'finapps/version'
6
6
 
7
+ # rubocop:disable Metrics/BlockLength
7
8
  Gem::Specification.new do |spec|
8
9
  spec.name = 'finapps'
9
10
  spec.version = FinApps::VERSION
data/lib/finapps/error.rb CHANGED
@@ -8,5 +8,10 @@ module FinApps # :nodoc:
8
8
  # Raised whenever a required argument is missing.
9
9
  class MissingArgumentsError < Error; end
10
10
 
11
- %i(InvalidArgumentsError MissingArgumentsError).each {|const| Error.const_set(const, FinApps.const_get(const)) }
11
+ # Raised whenever there is a session timeout at the API.
12
+ class ApiSessionTimeoutError < Error; end
13
+
14
+ %i(InvalidArgumentsError MissingArgumentsError ApiSessionTimeoutError).each do |const|
15
+ Error.const_set(const, FinApps.const_get(const))
16
+ end
12
17
  end
@@ -5,6 +5,7 @@ module FinApps
5
5
  module Middleware
6
6
  autoload :AcceptJson, 'finapps/middleware/request/accept_json'
7
7
  autoload :UserAgent, 'finapps/middleware/request/user_agent'
8
+ autoload :NoEncodingBasicAuthentication, 'finapps/middleware/request/no_encoding_basic_authentication'
8
9
  autoload :TenantAuthentication, 'finapps/middleware/request/tenant_authentication'
9
10
  autoload :CustomLogger, 'finapps/middleware/response/custom_logger'
10
11
 
@@ -12,6 +13,7 @@ module FinApps
12
13
  Faraday::Request.register_middleware \
13
14
  accept_json: -> { AcceptJson },
14
15
  user_agent: -> { UserAgent },
16
+ no_encoding_basic_authentication: -> { NoEncodingBasicAuthentication },
15
17
  tenant_authentication: -> { TenantAuthentication }
16
18
  Faraday::Response.register_middleware \
17
19
  custom_logger: -> { CustomLogger }
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module FinApps
3
+ module Middleware
4
+ class NoEncodingBasicAuthentication < ::Faraday::Request.load_middleware(:authorization)
5
+ def self.header(value)
6
+ sanitized = value.delete("\n")
7
+ super(:Basic, sanitized)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -7,10 +7,13 @@ module FinApps
7
7
 
8
8
  SUCCESS_STATUSES = 200..299
9
9
  CONNECTION_FAILED_STATUS = 407
10
+ API_SESSION_TIMEOUT = 419
10
11
 
11
12
  def on_complete(env)
12
- if SUCCESS_STATUSES.include? env[:status]
13
- # do nothing
13
+ return if SUCCESS_STATUSES.include?(env[:status])
14
+
15
+ if env[:status] == API_SESSION_TIMEOUT
16
+ raise(FinApps::Error::ApiSessionTimeoutError, 'Api Session Timed out')
14
17
  elsif env[:status] == CONNECTION_FAILED_STATUS
15
18
  raise(Faraday::Error::ConnectionFailed, '407 "Proxy Authentication Required"')
16
19
  else
@@ -73,9 +73,13 @@ module FinApps
73
73
  end
74
74
 
75
75
  def execute_request(path, method, params)
76
- error_messages = []
76
+ errors = []
77
+
77
78
  begin
78
79
  response = execute_method path, method, params
80
+
81
+ rescue FinApps::ApiSessionTimeoutError => error
82
+ handle_error(error)
79
83
  rescue FinApps::InvalidArgumentsError => error
80
84
  handle_error error
81
85
  rescue FinApps::MissingArgumentsError => error
@@ -83,10 +87,10 @@ module FinApps
83
87
  rescue Faraday::Error::ConnectionFailed => error
84
88
  handle_error error
85
89
  rescue Faraday::Error::ClientError => error
86
- error_messages = handle_client_error error
90
+ errors = handle_client_error(error)
87
91
  end
88
92
 
89
- [response, error_messages]
93
+ [response, errors]
90
94
  end
91
95
 
92
96
  def handle_error(error)
@@ -95,7 +99,7 @@ module FinApps
95
99
  end
96
100
 
97
101
  def handle_client_error(error)
98
- logger.warn "#{self.class}##{__method__} => Faraday::Error::ClientError, #{error}"
102
+ logger.warn "#{self.class}##{__method__} => #{error.class.name}, #{error}"
99
103
  error.response.present? && error.response[:error_messages] ? error.response[:error_messages] : [error.message]
100
104
  end
101
105
 
@@ -18,7 +18,7 @@ module FinApps
18
18
  conn.request :retry
19
19
  conn.request :multipart
20
20
  conn.request :url_encoded
21
- conn.request :basic_auth, config.user_identifier, config.user_token if config.valid_user_credentials?
21
+ conn.request :no_encoding_basic_authentication, config.user_token if config.valid_user_credentials?
22
22
 
23
23
  conn.use FinApps::Middleware::RaiseError
24
24
  conn.response :rashify
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module FinApps
3
- VERSION = '2.0.30'
3
+ VERSION = '2.1.1'
4
4
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe FinApps::Middleware::NoEncodingBasicAuthentication do
3
+ let(:valid_credentials) { VALID_CREDENTIALS }
4
+
5
+ describe '.header' do
6
+ it 'does not encode the values' do
7
+ actual_token = FinApps::Middleware::NoEncodingBasicAuthentication.header(valid_credentials[:token])
8
+ expect(actual_token).to eq("Basic #{valid_credentials[:token]}")
9
+ end
10
+ end
11
+ end
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.30
4
+ version: 2.1.1
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-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -254,6 +254,7 @@ files:
254
254
  - lib/finapps/error.rb
255
255
  - lib/finapps/middleware/middleware.rb
256
256
  - lib/finapps/middleware/request/accept_json.rb
257
+ - lib/finapps/middleware/request/no_encoding_basic_authentication.rb
257
258
  - lib/finapps/middleware/request/tenant_authentication.rb
258
259
  - lib/finapps/middleware/request/user_agent.rb
259
260
  - lib/finapps/middleware/response/custom_logger.rb
@@ -283,6 +284,7 @@ files:
283
284
  - spec/core_extensions/hash/compact_spec.rb
284
285
  - spec/core_extensions/object/is_integer_spec.rb
285
286
  - spec/middleware/request/accept_json_spec.rb
287
+ - spec/middleware/request/no_encoding_basic_authentication_spec.rb
286
288
  - spec/middleware/request/tenant_authentication_spec.rb
287
289
  - spec/middleware/request/user_agent_spec.rb
288
290
  - spec/middleware/response/raise_error_spec.rb
@@ -361,6 +363,7 @@ specification_version: 4
361
363
  summary: FinApps REST API ruby client.
362
364
  test_files:
363
365
  - spec/support/fake_api.rb
366
+ - spec/middleware/request/no_encoding_basic_authentication_spec.rb
364
367
  - spec/middleware/request/user_agent_spec.rb
365
368
  - spec/middleware/request/tenant_authentication_spec.rb
366
369
  - spec/middleware/request/accept_json_spec.rb