finapps_core 5.0.4 → 5.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +9 -8
  3. data/.rubocop.yml +131 -74
  4. data/.tmuxinator.yml +20 -0
  5. data/.travis.yml +5 -6
  6. data/RELEASES.md +8 -0
  7. data/finapps_core.gemspec +7 -7
  8. data/lib/finapps_core.rb +1 -0
  9. data/lib/finapps_core/middleware/middleware.rb +7 -3
  10. data/lib/finapps_core/middleware/request/accept_json.rb +2 -1
  11. data/lib/finapps_core/middleware/request/user_agent.rb +1 -1
  12. data/lib/finapps_core/middleware/request/x_consumer_id.rb +20 -0
  13. data/lib/finapps_core/middleware/response/raise_error.rb +36 -7
  14. data/lib/finapps_core/rest/base_client.rb +19 -31
  15. data/lib/finapps_core/rest/configuration.rb +17 -4
  16. data/lib/finapps_core/rest/connection.rb +31 -21
  17. data/lib/finapps_core/rest/defaults.rb +1 -1
  18. data/lib/finapps_core/utils/validatable.rb +1 -1
  19. data/lib/finapps_core/version.rb +1 -1
  20. data/spec/core_extensions/object/is_integer_spec.rb +6 -7
  21. data/spec/middleware/request/accept_json_spec.rb +7 -3
  22. data/spec/middleware/request/no_encoding_basic_authentication_spec.rb +15 -6
  23. data/spec/middleware/request/request_id_spec.rb +4 -4
  24. data/spec/middleware/request/tenant_authentication_spec.rb +21 -14
  25. data/spec/middleware/request/user_agent_spec.rb +8 -3
  26. data/spec/middleware/request/x_consumer_id_spec.rb +16 -0
  27. data/spec/middleware/response/raise_error_spec.rb +47 -15
  28. data/spec/rest/base_client_spec.rb +87 -43
  29. data/spec/rest/configuration_spec.rb +25 -18
  30. data/spec/rest/credentials_spec.rb +4 -4
  31. data/spec/rest/defaults_spec.rb +1 -1
  32. data/spec/rest/resources_spec.rb +10 -20
  33. data/spec/spec_helper.rb +3 -3
  34. data/spec/utils/validatable_spec.rb +9 -8
  35. metadata +61 -56
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d73742939d1896b096ba4ea23eae7381c812565acc344b634467ec581b24bd0e
4
- data.tar.gz: 1e9acbd80be922e20b13ddbc399f07e6adfa2ad9dea799a77a44ea06516029bd
3
+ metadata.gz: 02d94808c56da43ce378a957a15a28a0eb48d5005c785e784ba9142a9652d91f
4
+ data.tar.gz: 2eabf5b84c9839d2cdd9f80245d8a3454bcb863f1b8dcdbea89e0a4a2b3ef8c2
5
5
  SHA512:
6
- metadata.gz: 648f16e4ea04e82aa0bc1d281872b12172653834a41bc950634b38b549b20e25c94bf6a56a471bf0c294f7bc5ea49874fefb2263315cfc5795b49da4cae7229b
7
- data.tar.gz: 163c427e8170c8613acd7cc1d0bcfb56c6270af9d9ec444579b6e3e0103e1cf9759e0da38661a36433088887d4163d5da74d895bc4d670f25249566daede8fc0
6
+ metadata.gz: 2b494fac5ca2d2104d5d40912c440b08e750e137fa4a0bd44bdfa8b540c6ad4e627b2ae5eb372fcf704d915c98028854d9f5ab527ede1a8a29b87e4527ae4f1c
7
+ data.tar.gz: '028ea9d578f9d6a8f97ba73c715d08c65f4f06548c620bc5d6c05c76b505e5268a3736d454a3f39b37c71e3c4744364ee4c658d3913ea7d64031b25bcf77bb76'
@@ -1,6 +1,8 @@
1
- engines:
1
+ version: "2"
2
+ plugins:
2
3
  rubocop:
3
4
  enabled: true
5
+ channel: rubocop-0-74
4
6
  brakeman:
5
7
  enabled: false
6
8
  eslint:
@@ -11,11 +13,10 @@ engines:
11
13
  enabled: true
12
14
  config:
13
15
  languages:
14
- - ruby
15
- ratings:
16
- paths:
17
- - lib/**
18
- - "**.rb"
19
- exclude_paths:
16
+ ruby:
17
+ mass_threshold: 30
18
+ exclude_patterns:
20
19
  - spec/**/*
21
- - "**/vendor/**/*"
20
+ - "**/vendor/**/*"
21
+ - lib/finapps_core/rest/connection.rb
22
+ - lib/core_extensions/string/json_to_hash.rb
@@ -1,24 +1,78 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
1
5
  AllCops:
2
- DisplayCopNames: true
6
+ TargetRubyVersion: 2.6
3
7
  Exclude:
4
- - "finapps_core.gemspec"
5
- UseCache: false
6
-
7
- # Commonly used screens these days easily fit more than 80 characters.
8
- Metrics/LineLength:
9
- Max: 120
10
-
11
- # Re-enable this when the following is resolved:
12
- # https://github.com/rubocop-hq/rubocop/issues/5953
13
- Style/AccessModifierDeclarations:
14
- Enabled: false
8
+ - "vendor/**/*"
9
+ - "bin/**/*"
10
+ CacheRootDirectory: tmp
15
11
 
12
+ Layout/SpaceAroundMethodCallOperator:
13
+ Enabled: true
14
+ Layout/EmptyLinesAroundAttributeAccessor:
15
+ Enabled: true
16
16
  Layout/SpaceInsideBlockBraces:
17
17
  # The space here provides no real gain in readability while consuming
18
18
  # horizontal space that could be used for a better parameter name.
19
19
  # Also {| differentiates better from a hash than { | does.
20
20
  SpaceBeforeBlockParameters: false
21
+ Layout/SpaceInsideHashLiteralBraces:
22
+ EnforcedStyle: no_space
23
+ Layout/DotPosition:
24
+ Description: Checks the position of the dot in multi-line method calls.
25
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
26
+ Enabled: true
27
+ EnforcedStyle: leading
28
+ SupportedStyles:
29
+ - leading
30
+ - trailing
31
+ Layout/LineLength:
32
+ Max: 110
21
33
 
34
+ Lint/DeprecatedOpenSSLConstant:
35
+ Enabled: true
36
+ Lint/MixedRegexpCaptureTypes:
37
+ Enabled: true
38
+ Lint/RaiseException:
39
+ Enabled: true
40
+ Lint/StructNewOverride:
41
+ Enabled: true
42
+
43
+ Metrics/ClassLength:
44
+ Exclude:
45
+ - app/controllers/orders_controller.rb
46
+ - app/models/order.rb
47
+ Metrics/BlockLength:
48
+ ExcludedMethods: ['describe', 'context']
49
+ Exclude:
50
+ - config/environments/**/**
51
+ - '*.gemspec'
52
+ - Guardfile
53
+ - config/routes.rb
54
+ - config/Guardfile
55
+
56
+ Naming/PredicateName:
57
+ Description: Check the names of predicate methods.
58
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
59
+ Enabled: true
60
+ NamePrefix:
61
+ - is_
62
+ - has_
63
+ - have_
64
+ ForbiddenPrefixes:
65
+ - is_
66
+ Exclude:
67
+ - spec/**/*
68
+
69
+ RSpec/FilePath:
70
+ Enabled: false
71
+
72
+ Style/RedundantRegexpCharacterClass:
73
+ Enabled: true
74
+ Style/RedundantRegexpEscape:
75
+ Enabled: true
22
76
  Style/CollectionMethods:
23
77
  Description: Preferred collection methods.
24
78
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
@@ -29,73 +83,76 @@ Style/CollectionMethods:
29
83
  find: detect
30
84
  find_all: select
31
85
  reduce: inject
86
+ Style/GuardClause:
87
+ Description: Check for conditionals that can be replaced with guard clauses
88
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
89
+ Enabled: true
90
+ MinBodyLength: 1
32
91
  Style/OptionHash:
33
92
  Description: Don't use option hashes when you can use keyword arguments.
34
93
  Enabled: false
35
- Naming/PredicateName:
36
- Description: Check the names of predicate methods.
37
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
38
- Enabled: true
39
- NamePrefix:
40
- - is_
41
- - has_
42
- - have_
43
- NamePrefixBlacklist:
44
- - is_
45
- Exclude:
46
- - spec/**/*
47
- Metrics/AbcSize:
48
- Description: A calculated magnitude based on number of assignments, branches, and
49
- conditions.
94
+ Style/PercentLiteralDelimiters:
95
+ Description: Use `%`-literal delimiters consistently
96
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
50
97
  Enabled: false
51
- Max: 15
52
- Metrics/BlockLength:
53
- ExcludedMethods: ['describe', 'context']
54
- Metrics/ClassLength:
55
- Description: Avoid classes longer than 100 lines of code.
56
- Enabled: false
57
- CountComments: false
58
- Max: 100
59
- Metrics/ModuleLength:
60
- CountComments: false
61
- Max: 100
62
- Description: Avoid modules longer than 100 lines of code.
63
- Enabled: false
64
- Metrics/CyclomaticComplexity:
65
- Description: A complexity metric that is strongly correlated to the number of test
66
- cases needed to validate a method.
67
- Enabled: false
68
- Max: 6
69
- Metrics/MethodLength:
70
- Description: Avoid methods longer than 10 lines of code.
71
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
72
- Enabled: false
73
- CountComments: false
74
- Max: 10
75
- Metrics/ParameterLists:
76
- Description: Avoid parameter lists longer than three or four parameters.
77
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
78
- Enabled: false
79
- Max: 5
80
- CountKeywordArgs: true
81
- Metrics/PerceivedComplexity:
82
- Description: A complexity metric geared towards measuring complexity for a human
83
- reader.
84
- Enabled: false
85
- Max: 7
98
+ PreferredDelimiters:
99
+ "%": "()"
100
+ "%i": "()"
101
+ "%q": "()"
102
+ "%Q": "()"
103
+ "%r": "{}"
104
+ "%s": "()"
105
+ "%w": "()"
106
+ "%W": "()"
107
+ "%x": "()"
108
+ Style/SignalException:
109
+ Description: Checks for proper usage of fail and raise.
110
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
111
+ Enabled: true
112
+ EnforcedStyle: semantic
113
+ SupportedStyles:
114
+ - only_raise
115
+ - only_fail
116
+ - semantic
117
+ Style/StringLiterals:
118
+ Description: Checks if uses of quotes match the configured preference.
119
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
120
+ Enabled: true
121
+ EnforcedStyle: single_quotes
122
+ SupportedStyles:
123
+ - single_quotes
124
+ - double_quotes
125
+ Style/StringLiteralsInInterpolation:
126
+ Description: Checks if uses of quotes inside expressions in interpolated strings
127
+ match the configured preference.
128
+ Enabled: true
129
+ EnforcedStyle: single_quotes
130
+ SupportedStyles:
131
+ - single_quotes
132
+ - double_quotes
86
133
  Style/Documentation:
87
134
  Description: Document classes and non-namespace modules.
88
135
  Enabled: false
89
- Style/EmptyLiteral:
90
- Description: Prefer literals to Array.new/Hash.new/String.new.
91
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
136
+ Style/OneLineConditional:
137
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
138
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
92
139
  Enabled: false
93
- Style/VariableInterpolation:
94
- Description: Don't interpolate global, instance and class variables directly in
95
- strings.
96
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
97
- Enabled: false
98
- Lint/HandleExceptions:
99
- Description: Don't suppress exception.
100
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
101
- Enabled: false
140
+ Style/ExponentialNotation:
141
+ Enabled: true
142
+ Style/HashEachMethods:
143
+ Enabled: true
144
+ Style/HashTransformKeys:
145
+ Enabled: true
146
+ Style/HashTransformValues:
147
+ Enabled: true
148
+ Style/RedundantFetchBlock:
149
+ Enabled: true
150
+ Style/SlicingWithRange:
151
+ Enabled: true
152
+
153
+ RSpec/NestedGroups:
154
+ Max: 5
155
+ RSpec/DescribeClass:
156
+ Exclude:
157
+ - spec/system/*
158
+ - spec/factories_spec.rb
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: ruby-client-core
3
+ root: ~/projects/ruby-client-core/
4
+ windows:
5
+ -
6
+ editor:
7
+ layout: main-vertical
8
+ panes:
9
+ - vim: $EDITOR
10
+ - bash:
11
+ - git pull
12
+ - git status
13
+ - bundle
14
+ - bundle outdated
15
+ -
16
+ guard:
17
+ layout: even-horizontal
18
+ panes:
19
+ - guard:
20
+ - bundle exec guard
@@ -1,17 +1,16 @@
1
- sudo: false
2
1
  language: ruby
2
+ os: ["linux"]
3
+ dist: "xenial"
4
+
3
5
  cache:
4
6
  bundler: true
5
7
 
6
8
  rvm:
7
- - 2.5
8
9
  - 2.6
9
- - ruby-head
10
10
 
11
11
  before_install:
12
12
  - "echo 'gem: --no-document' > ~/.gemrc"
13
- - gem update --system
14
- - gem install bundler -v "~>2.0"
13
+ - gem install bundler --force --quiet
15
14
 
16
15
  script:
17
16
  - bundle exec rspec
@@ -23,4 +22,4 @@ addons:
23
22
  code_climate:
24
23
  repo_token: 5a8d194cbc23aa4c171e3478e3b6bbea9dd96041071380ec25bf80c07770b39a
25
24
  after_success:
26
- - bundle exec codeclimate-test-reporter
25
+ - bundle exec codeclimate-test-reporter
@@ -0,0 +1,8 @@
1
+ ## [5.0.7] - 2020-02-11
2
+
3
+ ### Added
4
+ * X-Consumer-ID header ([#49][i49])
5
+
6
+ [i49]: https://github.com/finapps/ruby-client-core/issues/49
7
+
8
+ [5.0.7]: https://github.com/finapps/ruby-client-core/compare/5.0.6...5.0.7
@@ -1,6 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
- lib = File.expand_path('../lib', __FILE__)
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'finapps_core/version'
6
6
  Gem::Specification.new do |spec|
@@ -26,14 +26,14 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.2'
27
27
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.9'
28
28
  spec.add_development_dependency 'gem-release', '~> 2.0', '>= 2.0.3'
29
- spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.2'
29
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
30
30
  spec.add_development_dependency 'rspec', '~> 3.8', '>= 3.8.0'
31
- spec.add_development_dependency 'rubocop', '~> 0.73', '>= 0.73.0'
32
- spec.add_development_dependency 'rubocop-performance', '~> 1.4', '>= 1.4.0'
33
- spec.add_development_dependency 'rubocop-rspec', '~> 1.33', '>= 1.33.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.86', '>= 0.86.0'
32
+ spec.add_development_dependency 'rubocop-performance', '~> 1.6', '>= 1.6.1'
33
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.40', '>= 1.40.0'
34
34
  spec.add_development_dependency 'sinatra', '~> 2.0', '>= 2.0.5'
35
35
  spec.add_development_dependency 'webmock', '~> 3.6', '>= 3.6.0'
36
36
 
37
37
  spec.extra_rdoc_files = %w(README.md LICENSE)
38
38
  spec.rdoc_options = %w(--line-numbers --inline-source --title finapps-ruby-core --main README.md)
39
- end
39
+ end
@@ -17,6 +17,7 @@ require 'finapps_core/middleware/request/no_encoding_basic_authentication'
17
17
  require 'finapps_core/middleware/request/accept_json'
18
18
  require 'finapps_core/middleware/request/user_agent'
19
19
  require 'finapps_core/middleware/request/request_id'
20
+ require 'finapps_core/middleware/request/x_consumer_id'
20
21
  require 'finapps_core/middleware/response/raise_error'
21
22
  require 'finapps_core/middleware/middleware'
22
23
 
@@ -6,9 +6,12 @@ module FinAppsCore
6
6
  module Middleware
7
7
  autoload :AcceptJson, 'finapps_core/middleware/request/accept_json'
8
8
  autoload :UserAgent, 'finapps_core/middleware/request/user_agent'
9
- autoload :NoEncodingBasicAuthentication, 'finapps_core/middleware/request/no_encoding_basic_authentication'
10
- autoload :TenantAuthentication, 'finapps_core/middleware/request/tenant_authentication'
9
+ autoload :NoEncodingBasicAuthentication,
10
+ 'finapps_core/middleware/request/no_encoding_basic_authentication'
11
+ autoload :TenantAuthentication,
12
+ 'finapps_core/middleware/request/tenant_authentication'
11
13
  autoload :RequestId, 'finapps_core/middleware/request/request_id'
14
+ autoload :XConsumerId, 'finapps_core/middleware/request/x_consumer_id'
12
15
 
13
16
  if Faraday::Middleware.respond_to? :register_middleware
14
17
  Faraday::Request.register_middleware \
@@ -16,7 +19,8 @@ module FinAppsCore
16
19
  user_agent: -> { UserAgent },
17
20
  no_encoding_basic_authentication: -> { NoEncodingBasicAuthentication },
18
21
  tenant_authentication: -> { TenantAuthentication },
19
- request_id: -> { RequestId }
22
+ request_id: -> { RequestId },
23
+ x_consumer_id: -> { XConsumerId }
20
24
  end
21
25
  end
22
26
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  module FinAppsCore
4
4
  module Middleware
5
- # This middleware sets the Accept request-header field to specify JSON as acceptable media type for the response.
5
+ # This middleware sets the Accept request-header field to specify JSON
6
+ # as acceptable media type for the response.
6
7
  class AcceptJson < Faraday::Middleware
7
8
  KEY = 'Accept' unless defined? KEY
8
9
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module FinAppsCore
4
4
  module Middleware
5
- # This middleware sets the User-Agent request-header field to identify thei client.
5
+ # This middleware sets the User-Agent request-header field to identify the client.
6
6
  class UserAgent < Faraday::Middleware
7
7
  KEY = 'User-Agent' unless defined? KEY
8
8
  RUBY = "#{RUBY_ENGINE}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FinAppsCore
4
+ module Middleware
5
+ # Adds a header to specify consumer to retrieve data for
6
+ class XConsumerId < Faraday::Middleware
7
+ KEY = 'X-Consumer-ID' unless defined? KEY
8
+
9
+ def initialize(app, x_consumer_id)
10
+ super(app)
11
+ @x_consumer_id = x_consumer_id.to_s.strip
12
+ end
13
+
14
+ def call(env)
15
+ env[:request_headers][KEY] ||= @x_consumer_id
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -16,12 +16,7 @@ module FinAppsCore
16
16
  def on_complete(env)
17
17
  return if SUCCESS_STATUSES.include?(env[:status])
18
18
 
19
- raise(FinAppsCore::ApiUnauthenticatedError, 'API Invalid Session') if env[:status] == API_UNAUTHENTICATED
20
- raise(FinAppsCore::ApiSessionTimeoutError, 'API Session Timed out') if env[:status] == API_SESSION_TIMEOUT
21
- raise(FinAppsCore::ConnectionFailedError, 'Connection Failed') if env[:status] == CONNECTION_FAILED_STATUS
22
- raise(FinAppsCore::UserLockoutError, 'User is Locked') if user_is_locked?(env)
23
-
24
- raise(Faraday::Error::ClientError, response_values(env))
19
+ failures env
25
20
  end
26
21
 
27
22
  def response_values(env)
@@ -35,6 +30,39 @@ module FinAppsCore
35
30
 
36
31
  private
37
32
 
33
+ def failures(env)
34
+ api_authentication_fail env
35
+ api_session_timeout_fail env
36
+ locked_user_fail env
37
+ connection_fail env
38
+
39
+ fail(Faraday::ClientError, response_values(env))
40
+ end
41
+
42
+ def locked_user_fail(env)
43
+ return unless user_is_locked?(env)
44
+
45
+ fail(FinAppsCore::UserLockoutError, 'User is Locked')
46
+ end
47
+
48
+ def api_session_timeout_fail(env)
49
+ return unless env[:status] == API_SESSION_TIMEOUT
50
+
51
+ fail(FinAppsCore::ApiSessionTimeoutError, 'API Session Timed out')
52
+ end
53
+
54
+ def connection_fail(env)
55
+ return unless env[:status] == CONNECTION_FAILED_STATUS
56
+
57
+ fail(FinAppsCore::ConnectionFailedError, 'Connection Failed')
58
+ end
59
+
60
+ def api_authentication_fail(env)
61
+ return unless env[:status] == API_UNAUTHENTICATED
62
+
63
+ fail(FinAppsCore::ApiUnauthenticatedError, 'API Invalid Session')
64
+ end
65
+
38
66
  def error_messages(body)
39
67
  return nil if empty?(body)
40
68
 
@@ -59,7 +87,8 @@ module FinAppsCore
59
87
  end
60
88
 
61
89
  def user_is_locked?(env)
62
- env.status == FORBIDDEN && error_messages(env.body)&.[](0)&.downcase == LOCKOUT_MESSAGE
90
+ env.status == FORBIDDEN &&
91
+ error_messages(env.body)&.[](0)&.downcase == LOCKOUT_MESSAGE
63
92
  end
64
93
 
65
94
  def symbolize(obj)