finapps_core 5.0.13 → 5.0.14

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
  SHA256:
3
- metadata.gz: '048fa78b23468e14dd5756a875178f323687de38537d46db6b0f7da842bbf375'
4
- data.tar.gz: fe171551416bfc98902f958cae69220f4923f6e9b0445883689a3d4edff73c08
3
+ metadata.gz: 4a0b9d68f085e0831b039da71cd442e4c96d58f8e6cd9787c4b8ec4eef9edf8d
4
+ data.tar.gz: aacb0dc131db339c2360f38fa8918360bdcc2f5ada120e97b21cdd1c15a2daf4
5
5
  SHA512:
6
- metadata.gz: 947a8a2ee8caff1d0de36924480926db3c12e4dc76d3904735929265f3a981e98062695dfbd54dfebdde462fd8a6244086a86f5a3e2d2877d52ee3cc4187a3c3
7
- data.tar.gz: c5b3d107db58545e5eafadf8ab09c87e834af608ba8294ae857cb15abb16eb6ec3079eff290cb8f04322c7a3b66bdf4fad0ecf6d2a81af57d0dcc9727feacebf
6
+ metadata.gz: 1487eb6356e82eccf6b8584b0a7074fb8af3ef893b74bbda50b1e4087fdb35132e84c8eb44801f376f504b44e6d80e7fcb1a45cdf4a8520c49ad08c148659d2d
7
+ data.tar.gz: 61838248219a84def621b1136da25ac25a93404a35cd67d8e2435e3ec16d84873862e52453293fa22f3c8cb73382e2ee5a259057c7b295207e0edaec31e1c724
@@ -11,10 +11,11 @@ module FinAppsCore
11
11
  :log_level, :request_id, :consumer_id, :tenant_id
12
12
 
13
13
  def initialize(options = {})
14
- FinAppsCore::REST::Defaults::DEFAULTS.merge(remove_empty_options(options))
15
- .each {|key, value| public_send("#{key}=", value) }
16
- fail_invalid_host
14
+ assign_attributes FinAppsCore::REST::Defaults::DEFAULTS
15
+ .merge(options.compact)
17
16
  fail_invalid_timeout
17
+ fail_invalid_host
18
+ @host = @host.chomp('/')
18
19
  end
19
20
 
20
21
  def valid_user_credentials?
@@ -23,6 +24,27 @@ module FinAppsCore
23
24
 
24
25
  private
25
26
 
27
+ def assign_attributes(new_attributes)
28
+ unless new_attributes.respond_to?(:each_pair)
29
+ fail ArgumentError, 'When assigning attributes, '\
30
+ "you must pass a hash argument, #{new_attributes.class} passed."
31
+ end
32
+ return if new_attributes.empty?
33
+
34
+ _assign_attributes new_attributes
35
+ end
36
+
37
+ def _assign_attributes(attributes)
38
+ attributes.each {|key, value| _assign_attribute(key, value) }
39
+ end
40
+
41
+ def _assign_attribute(key, value)
42
+ setter = :"#{key}="
43
+ fail UnknownAttributeError.new(self, key.to_s) unless respond_to?(setter)
44
+
45
+ public_send(setter, value)
46
+ end
47
+
26
48
  def fail_invalid_host
27
49
  return if valid_host?
28
50
 
@@ -40,10 +62,6 @@ module FinAppsCore
40
62
  def valid_host?
41
63
  host.start_with?('http://', 'https://')
42
64
  end
43
-
44
- def remove_empty_options(hash)
45
- hash.compact
46
- end
47
65
  end
48
66
  end
49
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FinAppsCore
4
- VERSION = '5.0.13'
4
+ VERSION = '5.0.14'
5
5
  end
@@ -4,33 +4,59 @@ require 'finapps_core/error'
4
4
 
5
5
  RSpec.describe FinAppsCore::REST::Configuration do
6
6
  describe '#new' do
7
+ expected_error = FinAppsCore::InvalidArgumentsError
8
+ default_host = FinAppsCore::REST::Defaults::DEFAULTS[:host]
9
+ default_timeout = FinAppsCore::REST::Defaults::DEFAULTS[:timeout]
10
+
7
11
  context 'with invalid timeout configuration' do
8
- subject(:configuration) { described_class.new(timeout: 'whatever') }
12
+ subject(:configuration) { described_class.new(timeout: 'foo') }
9
13
 
10
- expected_error = FinAppsCore::InvalidArgumentsError
11
- it { expect { configuration }.to raise_error(expected_error, 'Invalid argument. {timeout: whatever}') }
14
+ it {
15
+ expect { configuration }
16
+ .to raise_error(expected_error, 'Invalid argument. {timeout: foo}')
17
+ }
12
18
  end
13
19
 
14
20
  context 'with missing timeout configuration' do
15
21
  subject(:configuration) { described_class.new(timeout: nil) }
16
22
 
17
23
  it 'has a default timeout value' do
18
- expect(configuration.timeout).to eq(FinAppsCore::REST::Defaults::DEFAULTS[:timeout])
24
+ expect(configuration.timeout).to eq(default_timeout)
19
25
  end
20
26
  end
21
27
 
22
28
  context 'with invalid host configuration' do
23
- subject(:configuration) { described_class.new(host: 'whatever') }
29
+ subject(:configuration) { described_class.new(host: 'foo') }
24
30
 
25
- expected_error = FinAppsCore::InvalidArgumentsError
26
- it { expect { configuration }.to raise_error(expected_error, 'Invalid argument. {host: whatever}') }
31
+ it do
32
+ expect { configuration }
33
+ .to raise_error(expected_error, 'Invalid argument. {host: foo}')
34
+ end
35
+ end
36
+
37
+ context 'with valid host configuration' do
38
+ subject(:configuration) { described_class.new(host: 'https://api.com/') }
39
+
40
+ it 'the default host value is not used' do
41
+ expect(configuration.host).not_to eq(default_host)
42
+ end
43
+
44
+ it 'the provided host value is assigned to host' do
45
+ expect(configuration.host).to include('https://api.com')
46
+ end
47
+
48
+ context 'when given host value ends on /' do
49
+ it 'the / character is removed' do
50
+ expect(configuration.host).not_to end_with('/')
51
+ end
52
+ end
27
53
  end
28
54
 
29
55
  context 'with missing host configuration' do
30
56
  subject(:configuration) { described_class.new(host: nil) }
31
57
 
32
58
  it 'has a default host value' do
33
- expect(configuration.host).to eq(FinAppsCore::REST::Defaults::DEFAULTS[:host])
59
+ expect(configuration.host).to eq(default_host)
34
60
  end
35
61
  end
36
62
  end
@@ -43,7 +69,9 @@ RSpec.describe FinAppsCore::REST::Configuration do
43
69
  end
44
70
 
45
71
  context 'when user credentials were set' do
46
- subject(:configuration) { described_class.new(user_identifier: 1, user_token: 2) }
72
+ subject(:configuration) do
73
+ described_class.new(user_identifier: 1, user_token: 2)
74
+ end
47
75
 
48
76
  it { expect(configuration.valid_user_credentials?).to eq(true) }
49
77
  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: 5.0.13
4
+ version: 5.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -357,21 +357,21 @@ signing_key:
357
357
  specification_version: 4
358
358
  summary: FinApps REST API ruby client - Core.
359
359
  test_files:
360
- - spec/rest/resources_spec.rb
361
- - spec/rest/defaults_spec.rb
362
- - spec/rest/credentials_spec.rb
363
- - spec/rest/base_client_spec.rb
364
- - spec/rest/configuration_spec.rb
365
- - spec/support/fake_api.rb
360
+ - spec/spec_helpers/client.rb
366
361
  - spec/spec_helper.rb
362
+ - spec/core_extensions/object/is_integer_spec.rb
367
363
  - spec/utils/validatable_spec.rb
368
- - spec/spec_helpers/client.rb
369
- - spec/middleware/request/request_id_spec.rb
370
- - spec/middleware/request/x_consumer_id_spec.rb
371
- - spec/middleware/request/user_agent_spec.rb
372
- - spec/middleware/request/tenant_authentication_spec.rb
373
- - spec/middleware/request/x_tenant_id_spec.rb
364
+ - spec/support/fake_api.rb
374
365
  - spec/middleware/request/no_encoding_basic_authentication_spec.rb
366
+ - spec/middleware/request/x_tenant_id_spec.rb
367
+ - spec/middleware/request/tenant_authentication_spec.rb
375
368
  - spec/middleware/request/accept_json_spec.rb
369
+ - spec/middleware/request/user_agent_spec.rb
370
+ - spec/middleware/request/x_consumer_id_spec.rb
371
+ - spec/middleware/request/request_id_spec.rb
376
372
  - spec/middleware/response/raise_error_spec.rb
377
- - spec/core_extensions/object/is_integer_spec.rb
373
+ - spec/rest/credentials_spec.rb
374
+ - spec/rest/defaults_spec.rb
375
+ - spec/rest/configuration_spec.rb
376
+ - spec/rest/resources_spec.rb
377
+ - spec/rest/base_client_spec.rb