finapps 2.1.4 → 2.2.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 +4 -4
- data/.rubocop.yml +2 -18
- data/.ruby-gemset +1 -1
- data/.travis.yml +5 -2
- data/README.md +1 -1
- data/finapps.gemspec +10 -12
- data/lib/finapps.rb +5 -21
- data/lib/finapps/rest/client.rb +42 -53
- data/lib/finapps/rest/institutions.rb +2 -2
- data/lib/finapps/rest/institutions_forms.rb +2 -2
- data/lib/finapps/rest/order_reports.rb +4 -4
- data/lib/finapps/rest/order_statuses.rb +2 -2
- data/lib/finapps/rest/order_tokens.rb +2 -3
- data/lib/finapps/rest/orders.rb +6 -6
- data/lib/finapps/rest/password_resets.rb +4 -4
- data/lib/finapps/rest/sessions.rb +2 -2
- data/lib/finapps/rest/user_institutions.rb +21 -26
- data/lib/finapps/rest/user_institutions_forms.rb +2 -2
- data/lib/finapps/rest/user_institutions_statuses.rb +2 -2
- data/lib/finapps/rest/users.rb +5 -5
- data/lib/finapps/rest/version.rb +1 -1
- data/lib/finapps/version.rb +1 -1
- data/spec/rest/client_spec.rb +4 -13
- data/spec/rest/institutions_forms_spec.rb +5 -2
- data/spec/rest/institutions_spec.rb +4 -2
- data/spec/rest/order_reports_spec.rb +4 -4
- data/spec/rest/order_statuses_spec.rb +3 -2
- data/spec/rest/order_tokens_spec.rb +3 -2
- data/spec/rest/orders_spec.rb +6 -5
- data/spec/rest/password_resets_spec.rb +4 -4
- data/spec/rest/sessions_spec.rb +2 -2
- data/spec/rest/user_institutions_forms_spec.rb +5 -2
- data/spec/rest/user_institutions_spec.rb +10 -9
- data/spec/rest/user_institutions_statuses_spec.rb +3 -2
- data/spec/rest/users_spec.rb +4 -4
- data/spec/rest/version_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -3
- data/spec/spec_helpers/client.rb +1 -1
- metadata +49 -124
- data/lib/core_extensions/hash/compact.rb +0 -23
- data/lib/core_extensions/object/blank.rb +0 -69
- data/lib/core_extensions/object/is_integer.rb +0 -10
- data/lib/core_extensions/string/json_to_hash.rb +0 -10
- data/lib/finapps/error.rb +0 -17
- data/lib/finapps/middleware/middleware.rb +0 -22
- data/lib/finapps/middleware/request/accept_json.rb +0 -14
- data/lib/finapps/middleware/request/no_encoding_basic_authentication.rb +0 -21
- data/lib/finapps/middleware/request/tenant_authentication.rb +0 -20
- data/lib/finapps/middleware/request/user_agent.rb +0 -15
- data/lib/finapps/middleware/response/custom_logger.rb +0 -41
- data/lib/finapps/middleware/response/raise_error.rb +0 -46
- data/lib/finapps/rest/base_client.rb +0 -122
- data/lib/finapps/rest/configuration.rb +0 -31
- data/lib/finapps/rest/connection.rb +0 -35
- data/lib/finapps/rest/credentials.rb +0 -21
- data/lib/finapps/rest/defaults.rb +0 -80
- data/lib/finapps/rest/resources.rb +0 -64
- data/lib/finapps/utils/loggeable.rb +0 -14
- data/lib/finapps/utils/parameter_filter.rb +0 -32
- data/spec/core_extensions/hash/compact_spec.rb +0 -21
- data/spec/core_extensions/object/is_integer_spec.rb +0 -17
- data/spec/middleware/request/accept_json_spec.rb +0 -12
- data/spec/middleware/request/no_encoding_basic_authentication_spec.rb +0 -32
- data/spec/middleware/request/tenant_authentication_spec.rb +0 -34
- data/spec/middleware/request/user_agent_spec.rb +0 -12
- data/spec/middleware/response/raise_error_spec.rb +0 -24
- data/spec/rest/base_client_spec.rb +0 -120
- data/spec/rest/configuration_spec.rb +0 -39
- data/spec/rest/credentials_spec.rb +0 -20
- data/spec/rest/resources_spec.rb +0 -76
- data/spec/rest/timeout_spec.rb +0 -9
- data/spec/support/fixtures/relevance_ruleset_names.json +0 -47
- data/spec/utils/parameter_filter_spec.rb +0 -23
data/lib/finapps/error.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Defines some errors to identify Exceptions within this gem
|
3
|
-
module FinApps # :nodoc:
|
4
|
-
# Base error class.
|
5
|
-
class Error < StandardError; end
|
6
|
-
# Raised for existing but invalid arguments.
|
7
|
-
class InvalidArgumentsError < Error; end
|
8
|
-
# Raised whenever a required argument is missing.
|
9
|
-
class MissingArgumentsError < Error; end
|
10
|
-
|
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
|
17
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'faraday' unless defined? Faraday
|
3
|
-
|
4
|
-
module FinApps
|
5
|
-
module Middleware
|
6
|
-
autoload :AcceptJson, 'finapps/middleware/request/accept_json'
|
7
|
-
autoload :UserAgent, 'finapps/middleware/request/user_agent'
|
8
|
-
autoload :NoEncodingBasicAuthentication, 'finapps/middleware/request/no_encoding_basic_authentication'
|
9
|
-
autoload :TenantAuthentication, 'finapps/middleware/request/tenant_authentication'
|
10
|
-
autoload :CustomLogger, 'finapps/middleware/response/custom_logger'
|
11
|
-
|
12
|
-
if Faraday::Middleware.respond_to? :register_middleware
|
13
|
-
Faraday::Request.register_middleware \
|
14
|
-
accept_json: -> { AcceptJson },
|
15
|
-
user_agent: -> { UserAgent },
|
16
|
-
no_encoding_basic_authentication: -> { NoEncodingBasicAuthentication },
|
17
|
-
tenant_authentication: -> { TenantAuthentication }
|
18
|
-
Faraday::Response.register_middleware \
|
19
|
-
custom_logger: -> { CustomLogger }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module Middleware
|
4
|
-
# This middleware sets the Accept request-header field to specify JSON as acceptable media type for the response.
|
5
|
-
class AcceptJson < Faraday::Middleware
|
6
|
-
KEY = 'Accept' unless defined? KEY
|
7
|
-
|
8
|
-
def call(env)
|
9
|
-
env[:request_headers][KEY] = 'application/json'
|
10
|
-
@app.call(env)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module Middleware
|
4
|
-
# Adds a custom header for basic authorization.
|
5
|
-
# If the value for this header already exists, it is not overriden.
|
6
|
-
class NoEncodingBasicAuthentication < Faraday::Middleware
|
7
|
-
KEY = 'Authorization' unless defined? KEY
|
8
|
-
|
9
|
-
def initialize(app, token)
|
10
|
-
super(app)
|
11
|
-
sanitized = token.to_s.strip.delete("\n")
|
12
|
-
@header_value = "Basic #{sanitized}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
env[:request_headers][KEY] ||= @header_value
|
17
|
-
@app.call(env)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module Middleware
|
4
|
-
# Adds a custom header for tenant level authorization.
|
5
|
-
# If the value for this header already exists, it is not overriden.
|
6
|
-
class TenantAuthentication < Faraday::Middleware
|
7
|
-
KEY = 'X-FinApps-Token' unless defined? KEY
|
8
|
-
|
9
|
-
def initialize(app, identifier, token)
|
10
|
-
super(app)
|
11
|
-
@header_value = "#{identifier.to_s.strip}=#{token.to_s.strip}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
env[:request_headers][KEY] ||= @header_value
|
16
|
-
@app.call(env)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module Middleware
|
4
|
-
# This middleware sets the User-Agent request-header field to identify thei client.
|
5
|
-
class UserAgent < Faraday::Middleware
|
6
|
-
KEY = 'User-Agent' unless defined? KEY
|
7
|
-
RUBY = "#{RUBY_ENGINE}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
env[:request_headers][KEY] = "finapps-ruby/#{FinApps::VERSION} (#{RUBY})"
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module Middleware
|
4
|
-
class CustomLogger < Faraday::Response::Middleware
|
5
|
-
extend Forwardable
|
6
|
-
include FinApps::Utils::ParameterFilter
|
7
|
-
|
8
|
-
DEFAULT_OPTIONS = {bodies: false}.freeze
|
9
|
-
|
10
|
-
def initialize(app, logger=nil, options={})
|
11
|
-
super(app)
|
12
|
-
@logger = logger || begin
|
13
|
-
require 'logger'
|
14
|
-
::Logger.new(STDOUT)
|
15
|
-
end
|
16
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
20
|
-
|
21
|
-
def call(env)
|
22
|
-
debug "#{self.class.name}##{__method__} => URL: #{env.method.upcase} #{env.url}"
|
23
|
-
debug "#{self.class.name}##{__method__} => Request Headers: #{dump env.request_headers}"
|
24
|
-
|
25
|
-
super
|
26
|
-
end
|
27
|
-
|
28
|
-
def on_complete(env)
|
29
|
-
debug "#{self.class.name}##{__method__} => URL: #{env.method.upcase} #{env.url}"
|
30
|
-
debug "#{self.class.name}##{__method__} => Response Headers: #{dump env.response_headers}"
|
31
|
-
debug "#{self.class.name}##{__method__} => Response Body: #{dump env.body}" if env.body
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def dump(value)
|
37
|
-
skip_sensitive_data(value.is_a?(Array) ? value.to_h : value).to_json
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module Middleware
|
4
|
-
class RaiseError < Faraday::Response::Middleware # :nodoc:
|
5
|
-
using ObjectExtensions
|
6
|
-
using StringExtensions
|
7
|
-
|
8
|
-
SUCCESS_STATUSES = 200..299
|
9
|
-
CONNECTION_FAILED_STATUS = 407
|
10
|
-
API_SESSION_TIMEOUT = 419
|
11
|
-
|
12
|
-
def on_complete(env)
|
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')
|
17
|
-
elsif env[:status] == CONNECTION_FAILED_STATUS
|
18
|
-
raise(Faraday::Error::ConnectionFailed, '407 "Proxy Authentication Required"')
|
19
|
-
else
|
20
|
-
raise(Faraday::Error::ClientError, response_values(env))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def response_values(env)
|
25
|
-
{
|
26
|
-
status: env.status,
|
27
|
-
headers: env.response_headers,
|
28
|
-
body: env.body,
|
29
|
-
error_messages: error_messages(env.body)
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def error_messages(body)
|
36
|
-
return nil if body.blank?
|
37
|
-
body = body.json_to_hash if body.is_a?(String)
|
38
|
-
has_message_key?(body) ? body['messages'] : nil
|
39
|
-
end
|
40
|
-
|
41
|
-
def has_message_key?(body)
|
42
|
-
body.respond_to?(:key?) && body.key?('messages')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module REST
|
4
|
-
# base client functionality
|
5
|
-
class BaseClient
|
6
|
-
include ::FinApps::Utils::Loggeable
|
7
|
-
include ::FinApps::REST::Connection
|
8
|
-
using ObjectExtensions
|
9
|
-
using StringExtensions
|
10
|
-
|
11
|
-
attr_reader :config
|
12
|
-
|
13
|
-
def initialize(options, logger=nil)
|
14
|
-
@config = FinApps::REST::Configuration.new options
|
15
|
-
@logger = logger
|
16
|
-
end
|
17
|
-
|
18
|
-
def user_credentials?
|
19
|
-
config.valid_user_credentials?
|
20
|
-
end
|
21
|
-
|
22
|
-
# Returns an initialized Faraday connection object.
|
23
|
-
#
|
24
|
-
# @return Faraday::Connection.
|
25
|
-
def connection
|
26
|
-
@connection ||= faraday(config, logger)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Performs HTTP GET, POST, UPDATE and DELETE requests.
|
30
|
-
# You shouldn't need to use this method directly, but it can be useful for debugging.
|
31
|
-
# Returns a hash obtained from parsing the JSON object in the response body.
|
32
|
-
#
|
33
|
-
# @param [String] path
|
34
|
-
# @param [String] method
|
35
|
-
# @param [Hash] params
|
36
|
-
# @return [Hash,Array<String>]
|
37
|
-
def send_request(path, method, params={})
|
38
|
-
raise FinApps::MissingArgumentsError.new 'Missing argument: path.' if path.blank?
|
39
|
-
raise FinApps::MissingArgumentsError.new 'Missing argument: method.' if method.blank?
|
40
|
-
|
41
|
-
response, error_messages = execute_request(path, method, params)
|
42
|
-
result = if empty?(response)
|
43
|
-
nil
|
44
|
-
else
|
45
|
-
block_given? ? yield(response) : response.body
|
46
|
-
end
|
47
|
-
|
48
|
-
[result, error_messages]
|
49
|
-
end
|
50
|
-
|
51
|
-
# Defines methods to perform HTTP GET, POST, PUT and DELETE requests.
|
52
|
-
# Returns a hash obtained from parsing the JSON object in the response body.
|
53
|
-
#
|
54
|
-
def method_missing(method_id, *arguments, &block)
|
55
|
-
if %i(get post put delete).include? method_id
|
56
|
-
connection.send(method_id) do |req|
|
57
|
-
req.url arguments.first
|
58
|
-
req.body = arguments[1] unless method_id == :get
|
59
|
-
end
|
60
|
-
else
|
61
|
-
super
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def respond_to_missing?(method_sym, include_private=false)
|
66
|
-
[:get, :post, :put, :delete].include?(method_sym) ? true : super
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def empty?(response)
|
72
|
-
response.blank? || (response.respond_to?(:body) && response.body.blank?)
|
73
|
-
end
|
74
|
-
|
75
|
-
def execute_request(path, method, params)
|
76
|
-
errors = []
|
77
|
-
|
78
|
-
begin
|
79
|
-
response = execute_method path, method, params
|
80
|
-
|
81
|
-
rescue FinApps::ApiSessionTimeoutError => error
|
82
|
-
handle_error(error)
|
83
|
-
rescue FinApps::InvalidArgumentsError => error
|
84
|
-
handle_error error
|
85
|
-
rescue FinApps::MissingArgumentsError => error
|
86
|
-
handle_error error
|
87
|
-
rescue Faraday::Error::ConnectionFailed => error
|
88
|
-
handle_error error
|
89
|
-
rescue Faraday::Error::ClientError => error
|
90
|
-
errors = handle_client_error(error)
|
91
|
-
end
|
92
|
-
|
93
|
-
[response, errors]
|
94
|
-
end
|
95
|
-
|
96
|
-
def handle_error(error)
|
97
|
-
logger.fatal "#{self.class}##{__method__} => #{error}"
|
98
|
-
raise error
|
99
|
-
end
|
100
|
-
|
101
|
-
def handle_client_error(error)
|
102
|
-
logger.warn "#{self.class}##{__method__} => #{error.class.name}, #{error}"
|
103
|
-
error.response.present? && error.response[:error_messages] ? error.response[:error_messages] : [error.message]
|
104
|
-
end
|
105
|
-
|
106
|
-
def execute_method(path, method, params)
|
107
|
-
case method
|
108
|
-
when :get
|
109
|
-
get(path)
|
110
|
-
when :post
|
111
|
-
post(path, params)
|
112
|
-
when :put
|
113
|
-
put(path, params)
|
114
|
-
when :delete
|
115
|
-
delete(path, params)
|
116
|
-
else
|
117
|
-
raise FinApps::InvalidArgumentsError.new "Method not supported: #{method}."
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module REST
|
4
|
-
# Represents the client configuration options
|
5
|
-
class Configuration # :nodoc:
|
6
|
-
using ObjectExtensions
|
7
|
-
using HashExtensions
|
8
|
-
|
9
|
-
attr_accessor :host,
|
10
|
-
:tenant_identifier, :tenant_token,
|
11
|
-
:user_identifier, :user_token,
|
12
|
-
:proxy, :timeout, :retry_limit, :log_level
|
13
|
-
|
14
|
-
def initialize(options={})
|
15
|
-
FinApps::REST::Defaults::DEFAULTS.merge(options.compact).each {|key, value| public_send("#{key}=", value) }
|
16
|
-
raise FinApps::InvalidArgumentsError.new "Invalid argument. {host: #{host}}" unless valid_host?
|
17
|
-
raise FinApps::InvalidArgumentsError.new "Invalid argument. {timeout: #{timeout}}" unless timeout.integer?
|
18
|
-
end
|
19
|
-
|
20
|
-
def valid_user_credentials?
|
21
|
-
FinApps::REST::Credentials.new(user_identifier, user_token).valid?
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def valid_host?
|
27
|
-
host.start_with?('http://', 'https://')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module REST
|
4
|
-
module Connection # :nodoc:
|
5
|
-
# @return [Faraday::Connection]
|
6
|
-
def faraday(config, logger)
|
7
|
-
options = {
|
8
|
-
url: "#{config.host}/v#{Defaults::API_VERSION}/",
|
9
|
-
request: {open_timeout: config.timeout,
|
10
|
-
timeout: config.timeout}
|
11
|
-
}
|
12
|
-
|
13
|
-
Faraday.new(options) do |conn|
|
14
|
-
conn.request :accept_json
|
15
|
-
conn.request :user_agent
|
16
|
-
conn.request :tenant_authentication, config.tenant_identifier, config.tenant_token
|
17
|
-
conn.request :json
|
18
|
-
conn.request :retry
|
19
|
-
conn.request :multipart
|
20
|
-
conn.request :url_encoded
|
21
|
-
conn.request :no_encoding_basic_authentication, config.user_token if config.valid_user_credentials?
|
22
|
-
|
23
|
-
conn.use FinApps::Middleware::RaiseError
|
24
|
-
conn.response :rashify
|
25
|
-
conn.response :json, content_type: /\bjson$/
|
26
|
-
conn.response :custom_logger, logger, bodies: (ENV['SILENT_LOG_BODIES'] != 'true')
|
27
|
-
|
28
|
-
# Adapter (ensure that the adapter is always last.)
|
29
|
-
conn.adapter :typhoeus
|
30
|
-
end
|
31
|
-
end
|
32
|
-
module_function :faraday # becomes available as a *private instance method* to classes that mix in the module
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module FinApps
|
3
|
-
module REST
|
4
|
-
# represents both tenant and user credentials
|
5
|
-
class Credentials
|
6
|
-
using ObjectExtensions
|
7
|
-
using StringExtensions
|
8
|
-
|
9
|
-
attr_reader :identifier, :token
|
10
|
-
|
11
|
-
def initialize(identifier, token)
|
12
|
-
@identifier = identifier
|
13
|
-
@token = token
|
14
|
-
end
|
15
|
-
|
16
|
-
def valid?
|
17
|
-
identifier.present? && token.present?
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|