finapps_core 2.1.1 → 2.1.2

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: dccff941fb23d4e52867d5895707394afbd1964b
4
- data.tar.gz: 855768812fb098270db4b006a30c954c76c45c7a
3
+ metadata.gz: 41bc937b65e6ecf5335b7cb97699fbe8e82777dd
4
+ data.tar.gz: 17af81422ffcd553eaa86e7538df811b6c5369a6
5
5
  SHA512:
6
- metadata.gz: 75b638cf49af713d61eb982e8ee8e53e8e085e87b4d1b87b406b8e3e2c67c10f885eb6e49e2f1bed4536ec5ab099ad3ce11162eb1d561152a667500485db4ff3
7
- data.tar.gz: 25949fba5f1303c77ec2234377addaa265761b81b09abb44817c1ca885aa55134b2f6bb7a409ccf08f2204c43af3c17eb5cf7ba89bdb780a79fbe2b8e6b2b643
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 || begin
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, :info, :warn, :error, :fatal
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).to_json
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 !body || (body.respond_to?(:empty?) && body.empty?)
38
- body = body.json_to_hash if body.is_a?(String)
39
- has_message_key?(body) ? body['messages'] : nil
37
+ return nil if empty?(body)
38
+ hash = to_hash body
39
+ messages hash
40
40
  end
41
41
 
42
- def has_message_key?(body)
43
- body.respond_to?(:key?) && body.key?('messages')
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) && (!response.body || (response.body.respond_to?(:empty?) && response.body.empty?))
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)
@@ -7,7 +7,7 @@ module FinAppsCore
7
7
  using ObjectExtensions
8
8
 
9
9
  attr_accessor :tenant_token, :user_identifier, :user_token,
10
- :host, :proxy, :timeout, :retry_limit,
10
+ :host, :proxy, :timeout, :retry_limit, :rashify,
11
11
  :log_level
12
12
 
13
13
  def initialize(options={})
@@ -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
 
@@ -8,8 +8,6 @@ module FinAppsCore
8
8
  # noinspection SpellCheckingInspection
9
9
  DEFAULTS = {
10
10
  host: 'https://api.financialapps.com',
11
- user_identifier: nil,
12
- user_token: nil,
13
11
  timeout: 30,
14
12
  proxy: nil,
15
13
  retry_limit: 1,
@@ -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
- request_with_body(path, :get, {})
27
+ send_request path, :get
28
28
  end
29
29
 
30
- def create(params={}, path=nil)
31
- request_with_body(path, :post, params)
30
+ def show(id=nil, path=nil)
31
+ send_request_for_id path, :get, id
32
32
  end
33
33
 
34
- def update(params={}, path=nil)
35
- request_with_body(path, :put, params)
34
+ def create(params={}, path=nil)
35
+ send_request path, :post, params
36
36
  end
37
37
 
38
- def show(id=nil, path=nil)
39
- request_without_body(path, :get, id)
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
- request_without_body(path, :delete, id)
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 request_without_body(path, method, id)
55
- not_blank(id, :id) if path.nil?
56
- path = "#{end_point}/:id".sub ':id', ERB::Util.url_encode(id) if path.nil?
57
- request_with_body path, method, {}
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 request_with_body(path, method, params)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FinAppsCore
4
- VERSION = '2.1.1'
4
+ VERSION = '2.1.2'
5
5
  end
@@ -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
@@ -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
@@ -3,7 +3,7 @@
3
3
  module SpecHelpers
4
4
  module Client
5
5
  def client
6
- FinAppsCore::REST::Client.new :tenant_id, :tenant_token
6
+ FinAppsCore::REST::BaseClient.new tenant_token: :tenant_token
7
7
  end
8
8
  end
9
9
  end
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.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-09-19 00:00:00.000000000 Z
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