finapps_core 5.0.7 → 5.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7da6746a9d41a5a653232294b795c91e9a12b5c6879e3fcd3cef0ae199c7856
4
- data.tar.gz: e6cd9df962d35834b073dea681bc56c4a0283130e535dd9e38e03b0431febc76
3
+ metadata.gz: 893d6f6d8d65e6a2fda82aef09549fef0946de4cb18bb71eb1567a7d25aafc13
4
+ data.tar.gz: cb75d6b2f6ca7edd7cf469b813ebaa5b0f5213283c7ddb1637294ddc7caf9adc
5
5
  SHA512:
6
- metadata.gz: c0adf1096463f145ced38476aed16b78a9e1db262881614e727e74eb6a015fc80fae7a6c15a4452e3bc16de47b3536379caeb19b63da86980da890971885c720
7
- data.tar.gz: d856c0cd51760de8fb94e2b1907acfe594c3bfb8b8afc54f1bf8447c8759b60ecbaedbfae9c533d46d5eacf7af14c088bc9ca0fdd81166e8ffeed19a9c025370
6
+ metadata.gz: 1fa618956bad1c72eca4f6e6a22f7c409cc11f57cef754f39a2a2fee321bbb86b71fa723433b3913cbcc56e5def74622b767bf9f8c6bb5bd6dc731f8c9342883
7
+ data.tar.gz: 2ae2c2d76cf9e878551b2e407eec3a0708bb1602acce8788b7a789987e44b4f5cc2e4bb3927250033e895963724f9706530cdefdc44fb8a8b435c1bf32ab9e89
@@ -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
- Layout/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
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
21
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
- ForbiddenPrefixes:
44
- - is_
45
- Exclude:
46
- - spec/**/*
47
- Metrics/AbcSize:
48
- Description: A calculated magnitude based on number of assignments, branches, and
49
- conditions.
50
- 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
94
+ Style/PercentLiteralDelimiters:
95
+ Description: Use `%`-literal delimiters consistently
96
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
78
97
  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
92
- 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
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
97
139
  Enabled: false
98
- Lint/SuppressedException:
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
@@ -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,11 +26,11 @@ 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.75', '>= 0.75.0'
32
- spec.add_development_dependency 'rubocop-performance', '~> 1.5', '>= 1.5.0'
33
- spec.add_development_dependency 'rubocop-rspec', '~> 1.36', '>= 1.36.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
 
@@ -6,8 +6,10 @@ 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'
12
14
  autoload :XConsumerId, 'finapps_core/middleware/request/x_consumer_id'
13
15
 
@@ -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
 
@@ -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::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)
@@ -31,7 +31,8 @@ module FinAppsCore
31
31
  end
32
32
 
33
33
  # Performs HTTP GET, POST, UPDATE and DELETE requests.
34
- # You shouldn't need to use this method directly, but it can be useful for debugging.
34
+ # You shouldn't need to use this method directly,
35
+ # but it can be useful for debugging.
35
36
  # Returns a hash obtained from parsing the JSON object in the response body.
36
37
  #
37
38
  # @param [String] path
@@ -42,7 +43,7 @@ module FinAppsCore
42
43
  not_blank(path, :path)
43
44
  not_blank(method, :method)
44
45
 
45
- response, error_messages = execute_request(path, method, params)
46
+ response, error_messages = execute_request(method, path, params)
46
47
  result = block_given? ? yield(response) : response_body(response)
47
48
 
48
49
  [result, error_messages]
@@ -76,26 +77,19 @@ module FinAppsCore
76
77
  end
77
78
  end
78
79
 
79
- def execute_request(path, method, params)
80
- response = nil
81
- errors = []
82
-
83
- begin
84
- response = execute_method path, method, params
85
- rescue FinAppsCore::InvalidArgumentsError,
86
- FinAppsCore::MissingArgumentsError,
87
- Faraday::Error::ConnectionFailed => e
88
- handle_error e
89
- rescue Faraday::ClientError => e
90
- errors = handle_client_error(e)
91
- end
92
-
93
- [response, errors]
80
+ def execute_request(method, path, params)
81
+ [send(method, path, params), []]
82
+ rescue FinAppsCore::InvalidArgumentsError,
83
+ FinAppsCore::MissingArgumentsError,
84
+ Faraday::Error::ConnectionFailed => e
85
+ [nil, handle_error(e)]
86
+ rescue Faraday::ClientError => e
87
+ [nil, handle_client_error(e)]
94
88
  end
95
89
 
96
90
  def handle_error(error)
97
91
  logger.fatal "#{self.class}##{__method__} => #{error}"
98
- raise error
92
+ fail error
99
93
  end
100
94
 
101
95
  def handle_client_error(error)
@@ -103,19 +97,13 @@ module FinAppsCore
103
97
  error.response && error.response[:error_messages] ? error.response[:error_messages] : [error.message]
104
98
  end
105
99
 
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 FinAppsCore::UnsupportedHttpMethodError, "Method not supported: #{method}."
100
+ def execute_method(method, path, params)
101
+ unless %i(get post put delete).include?(method)
102
+ fail FinAppsCore::UnsupportedHttpMethodError,
103
+ "Method not supported: #{method}."
118
104
  end
105
+
106
+ send(method, path, params)
119
107
  end
120
108
  end
121
109
  end