finapps_core 2.1.1 → 2.1.2
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/lib/finapps_core/middleware/response/custom_logger.rb +12 -6
- data/lib/finapps_core/middleware/response/raise_error.rb +15 -5
- data/lib/finapps_core/rest/base_client.rb +1 -1
- data/lib/finapps_core/rest/configuration.rb +1 -1
- data/lib/finapps_core/rest/connection.rb +1 -1
- data/lib/finapps_core/rest/defaults.rb +0 -2
- data/lib/finapps_core/rest/resources.rb +17 -13
- data/lib/finapps_core/version.rb +1 -1
- data/spec/rest/defaults_spec.rb +18 -0
- data/spec/rest/resources_spec.rb +14 -0
- data/spec/spec_helpers/client.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41bc937b65e6ecf5335b7cb97699fbe8e82777dd
|
4
|
+
data.tar.gz: 17af81422ffcd553eaa86e7538df811b6c5369a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8b266d0d81086d294e9456d70870eab4c5041c6a1c19aeaed69f1f1cd69ab1eaac3348c04aa1b036f7296f0b9dba830c8c8f70b2db3597c8082467567f787ae
|
7
|
+
data.tar.gz: fcce2dba8db4d9bd0f2dc500f73737a1bf3620d514e2639e274b8521c0895af7f0b7710a197952cbaac815477fc520b66941cecd660ec62114f39fe12ad746da
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
|
3
5
|
module FinAppsCore
|
4
6
|
module Middleware
|
5
7
|
class CustomLogger < Faraday::Response::Middleware
|
@@ -10,14 +12,11 @@ module FinAppsCore
|
|
10
12
|
|
11
13
|
def initialize(app, logger=nil, options={})
|
12
14
|
super(app)
|
13
|
-
@logger = logger ||
|
14
|
-
require 'logger'
|
15
|
-
::Logger.new(STDOUT)
|
16
|
-
end
|
15
|
+
@logger = logger || new_logger
|
17
16
|
@options = DEFAULT_OPTIONS.merge(options)
|
18
17
|
end
|
19
18
|
|
20
|
-
def_delegators :@logger, :debug
|
19
|
+
def_delegators :@logger, :debug
|
21
20
|
|
22
21
|
def call(env)
|
23
22
|
debug "#{self.class.name}##{__method__} => URL: #{env.method.upcase} #{env.url}"
|
@@ -33,7 +32,14 @@ module FinAppsCore
|
|
33
32
|
private
|
34
33
|
|
35
34
|
def dump(value)
|
36
|
-
skip_sensitive_data(value.is_a?(Array) ? value.to_h : value)
|
35
|
+
s = skip_sensitive_data(value.is_a?(Array) ? value.to_h : value)
|
36
|
+
s.nil? ? 'NO-CONTENT' : s.to_json
|
37
|
+
end
|
38
|
+
|
39
|
+
def new_logger
|
40
|
+
logger = Logger.new(STDOUT)
|
41
|
+
logger.level = FinAppsCore::REST::Defaults::DEFAULTS[:log_level]
|
42
|
+
logger
|
37
43
|
end
|
38
44
|
end
|
39
45
|
end
|
@@ -34,13 +34,23 @@ module FinAppsCore
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def error_messages(body)
|
37
|
-
return nil if
|
38
|
-
|
39
|
-
|
37
|
+
return nil if empty?(body)
|
38
|
+
hash = to_hash body
|
39
|
+
messages hash
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
43
|
-
|
42
|
+
def messages(hash)
|
43
|
+
return nil unless hash.respond_to?(:key?) && hash.key?('messages')
|
44
|
+
hash['messages']
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_hash(source)
|
48
|
+
return source unless source.is_a?(String)
|
49
|
+
source.json_to_hash
|
50
|
+
end
|
51
|
+
|
52
|
+
def empty?(o)
|
53
|
+
o.nil? || (o.respond_to?(:empty?) && o.empty?)
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
@@ -77,7 +77,7 @@ module FinAppsCore
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def empty_body?(response)
|
80
|
-
response.respond_to?(:body)
|
80
|
+
!response.respond_to?(:body) || !response.body || (response.body.respond_to?(:empty?) && response.body.empty?)
|
81
81
|
end
|
82
82
|
|
83
83
|
def execute_request(path, method, params)
|
@@ -22,7 +22,7 @@ module FinAppsCore
|
|
22
22
|
conn.request :no_encoding_basic_authentication, config.user_token if config.valid_user_credentials?
|
23
23
|
|
24
24
|
conn.use FinAppsCore::Middleware::RaiseError
|
25
|
-
conn.response :rashify
|
25
|
+
conn.response :rashify if config.rashify
|
26
26
|
conn.response :json, content_type: /\bjson$/
|
27
27
|
conn.response :custom_logger, logger, bodies: (ENV['SILENT_LOG_BODIES'] != 'true')
|
28
28
|
|
@@ -24,23 +24,23 @@ module FinAppsCore
|
|
24
24
|
|
25
25
|
def list(path=nil)
|
26
26
|
path = end_point.to_s if path.nil?
|
27
|
-
|
27
|
+
send_request path, :get
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
30
|
+
def show(id=nil, path=nil)
|
31
|
+
send_request_for_id path, :get, id
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
|
34
|
+
def create(params={}, path=nil)
|
35
|
+
send_request path, :post, params
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
|
38
|
+
def update(params={}, path=nil)
|
39
|
+
send_request path, :put, params
|
40
40
|
end
|
41
41
|
|
42
42
|
def destroy(id=nil, path=nil)
|
43
|
-
|
43
|
+
send_request_for_id path, :delete, id
|
44
44
|
end
|
45
45
|
|
46
46
|
protected
|
@@ -51,13 +51,17 @@ module FinAppsCore
|
|
51
51
|
|
52
52
|
private
|
53
53
|
|
54
|
-
def
|
55
|
-
|
56
|
-
path
|
57
|
-
|
54
|
+
def send_request_for_id(path, method, id)
|
55
|
+
path = resource_path(id) if path.nil?
|
56
|
+
send_request path, method
|
57
|
+
end
|
58
|
+
|
59
|
+
def resource_path(id)
|
60
|
+
not_blank id, :id
|
61
|
+
"#{end_point}/#{ERB::Util.url_encode(id)}"
|
58
62
|
end
|
59
63
|
|
60
|
-
def
|
64
|
+
def send_request(path, method, params={})
|
61
65
|
path = end_point if path.nil?
|
62
66
|
logger.debug "#{self.class.name}##{__method__} => path: #{path} params: #{skip_sensitive_data(params)}"
|
63
67
|
|
data/lib/finapps_core/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe FinAppsCore::REST::Defaults do
|
4
|
+
let(:fake_class) { Class.new }
|
5
|
+
|
6
|
+
describe 'set constants' do
|
7
|
+
before { stub_const(described_class.to_s, fake_class) }
|
8
|
+
|
9
|
+
it('sets API_VERSION') { expect(described_class::API_VERSION).to eq '2' }
|
10
|
+
it('sets DEFAULTS') { expect(described_class::DEFAULTS).to be_a(Hash) }
|
11
|
+
it('freezes DEFAULTS') { expect(described_class::DEFAULTS).to be_frozen }
|
12
|
+
it('sets DEFAULTS[:host]') { expect(described_class::DEFAULTS[:host]).to eq 'https://api.financialapps.com' }
|
13
|
+
it('sets DEFAULTS[:timeout]') { expect(described_class::DEFAULTS[:timeout]).to eq 30 }
|
14
|
+
it('does not set DEFAULTS[:proxy]') { expect(described_class::DEFAULTS[:proxy]).to be_nil }
|
15
|
+
it('sets DEFAULTS[:retry_limit]') { expect(described_class::DEFAULTS[:retry_limit]).to eq 1 }
|
16
|
+
it('sets DEFAULTS[:log_level]') { expect(described_class::DEFAULTS[:log_level]).to eq Logger::INFO }
|
17
|
+
end
|
18
|
+
end
|
data/spec/rest/resources_spec.rb
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'spec_helpers/client'
|
4
|
+
|
3
5
|
RSpec.describe FinAppsCore::REST::Resources do
|
6
|
+
include SpecHelpers::Client
|
7
|
+
subject { FinAppsCore::REST::Resources.new client }
|
8
|
+
|
4
9
|
describe '#new' do
|
10
|
+
context 'for a valid client param' do
|
11
|
+
it { expect { subject }.not_to raise_error }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when missing client param' do
|
15
|
+
subject { FinAppsCore::REST::Resources.new nil }
|
16
|
+
it { expect { subject }.to raise_error(FinAppsCore::MissingArgumentsError) }
|
17
|
+
end
|
5
18
|
end
|
19
|
+
|
6
20
|
describe '#list' do
|
7
21
|
end
|
8
22
|
describe '#create' do
|
data/spec/spec_helpers/client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finapps_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erich Quintero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -297,6 +297,7 @@ files:
|
|
297
297
|
- spec/rest/base_client_spec.rb
|
298
298
|
- spec/rest/configuration_spec.rb
|
299
299
|
- spec/rest/credentials_spec.rb
|
300
|
+
- spec/rest/defaults_spec.rb
|
300
301
|
- spec/rest/resources_spec.rb
|
301
302
|
- spec/spec_helper.rb
|
302
303
|
- spec/spec_helpers/client.rb
|
@@ -340,6 +341,7 @@ signing_key:
|
|
340
341
|
specification_version: 4
|
341
342
|
summary: FinApps REST API ruby client - Core.
|
342
343
|
test_files:
|
344
|
+
- spec/rest/defaults_spec.rb
|
343
345
|
- spec/rest/base_client_spec.rb
|
344
346
|
- spec/rest/credentials_spec.rb
|
345
347
|
- spec/rest/configuration_spec.rb
|