defra_ruby_govpay 0.2.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2decfa9d321b4886b2c4aa340730cc04e315318a94df1c1b31ecc4219f1efe1e
4
- data.tar.gz: 5dc7af54e47bf042414ff1f730eb6d2f2444e35c917d68ecca24f3c251116a1a
3
+ metadata.gz: ebc3e1002f53ab4c0e4a467375e730feac353cd05d9fb701e6a643a0b783645a
4
+ data.tar.gz: d6437d4b6f89f745737b903debb6b34819e17eba8ff7f59fbb641b45780e07b9
5
5
  SHA512:
6
- metadata.gz: 7ebef882ca7c22536dd057a6b9117055d0dfee7f82208b2d65f57d142a26e7650941da1c8c3fbc8e4f91eac345ae4fa2e0d9da264d36a6c0494443e7709b4593
7
- data.tar.gz: 126ae4b0e31d66d9ab9a206174da49bc606a84e58d67c67b71b60c0b8108d6aa02aef3bf246dce20f87e471323127fcc77d007dcf0bddc16cabd56c582622304
6
+ metadata.gz: ea2d5f0d93136560796f261b8ed2b7fb955196fa85708b40372ea61a3486cab12f4cf93de3463ea336ccf1ba3dfc672ffee00fa93f10a8305ce936ad2d1a74bd
7
+ data.tar.gz: 6badf44aaa4a8bc9bc0f0b6111f144d8b2fd8f455832be5c1489e2e3b523ea35d95863b939310dadcf68aa6fb7636cdf605d96423def9bb875adbd0117dc89ab
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
8
+ versioning-strategy: lockfile-only
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  *.gem
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .byebug_history
data/.rubocop.yml CHANGED
@@ -1,17 +1,5 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
1
+ inherit_from: .rubocop_todo.yml
3
2
 
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
14
-
15
- Metrics/BlockLength:
16
- Exclude:
17
- - 'spec/**/*'
3
+ inherit_gem:
4
+ defra_ruby_style:
5
+ - default.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,12 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2023-11-03 17:41:17 UTC using RuboCop version 1.57.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Style/OpenStructUse:
11
+ Exclude:
12
+ - 'lib/defra_ruby_govpay/object.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Gemfile CHANGED
@@ -5,10 +5,18 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in govpay_integration.gemspec
6
6
  gemspec
7
7
 
8
+ gem "byebug"
9
+
10
+ gem "github_changelog_generator"
11
+
12
+ gem "defra_ruby_style", "~> 0.4"
13
+
8
14
  gem "rake", "~> 13.0"
9
15
 
10
16
  gem "rspec", "~> 3.0"
11
17
 
12
18
  gem "rubocop", "~> 1.21"
19
+ gem "rubocop-rake"
20
+ gem "rubocop-rspec"
13
21
 
14
22
  gem "webmock", "~> 3.4"
data/Gemfile.lock CHANGED
@@ -1,45 +1,124 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- defra_ruby_govpay (0.1.2)
4
+ defra_ruby_govpay (0.2.2)
5
5
  rest-client (~> 2.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ activesupport (7.1.1)
11
+ base64
12
+ bigdecimal
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ connection_pool (>= 2.2.5)
15
+ drb
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ mutex_m
19
+ tzinfo (~> 2.0)
10
20
  addressable (2.8.5)
11
21
  public_suffix (>= 2.0.2, < 6.0)
12
22
  ast (2.4.2)
23
+ async (2.6.5)
24
+ console (~> 1.10)
25
+ fiber-annotation
26
+ io-event (~> 1.1)
27
+ timers (~> 4.1)
28
+ async-http (0.61.0)
29
+ async (>= 1.25)
30
+ async-io (>= 1.28)
31
+ async-pool (>= 0.2)
32
+ protocol-http (~> 0.25.0)
33
+ protocol-http1 (~> 0.16.0)
34
+ protocol-http2 (~> 0.15.0)
35
+ traces (>= 0.10.0)
36
+ async-http-faraday (0.12.0)
37
+ async-http (~> 0.42)
38
+ faraday
39
+ async-io (1.36.1)
40
+ async
41
+ async-pool (0.4.0)
42
+ async (>= 1.25)
43
+ base64 (0.1.1)
44
+ bigdecimal (3.1.4)
45
+ byebug (11.1.3)
46
+ concurrent-ruby (1.2.2)
47
+ connection_pool (2.4.1)
48
+ console (1.23.2)
49
+ fiber-annotation
50
+ fiber-local
13
51
  crack (0.4.5)
14
52
  rexml
53
+ defra_ruby_style (0.4.0)
54
+ rubocop (>= 1.0, < 2.0)
55
+ rubocop-factory_bot
56
+ rubocop-rake
57
+ rubocop-rspec
15
58
  diff-lcs (1.5.0)
16
59
  domain_name (0.5.20190701)
17
60
  unf (>= 0.0.5, < 1.0.0)
61
+ drb (2.1.1)
62
+ ruby2_keywords
63
+ faraday (2.7.11)
64
+ base64
65
+ faraday-net_http (>= 2.0, < 3.1)
66
+ ruby2_keywords (>= 0.0.4)
67
+ faraday-http-cache (2.5.0)
68
+ faraday (>= 0.8)
69
+ faraday-net_http (3.0.2)
70
+ fiber-annotation (0.2.0)
71
+ fiber-local (1.0.0)
72
+ github_changelog_generator (1.16.4)
73
+ activesupport
74
+ async (>= 1.25.0)
75
+ async-http-faraday
76
+ faraday-http-cache
77
+ multi_json
78
+ octokit (~> 4.6)
79
+ rainbow (>= 2.2.1)
80
+ rake (>= 10.0)
18
81
  hashdiff (1.0.1)
19
82
  http-accept (1.7.0)
20
83
  http-cookie (1.0.5)
21
84
  domain_name (~> 0.5)
85
+ i18n (1.14.1)
86
+ concurrent-ruby (~> 1.0)
87
+ io-event (1.3.3)
22
88
  json (2.6.3)
23
89
  language_server-protocol (3.17.0.3)
24
90
  mime-types (3.5.1)
25
91
  mime-types-data (~> 3.2015)
26
92
  mime-types-data (3.2023.0808)
93
+ minitest (5.20.0)
94
+ multi_json (1.15.0)
95
+ mutex_m (0.1.2)
27
96
  netrc (0.11.0)
97
+ octokit (4.25.1)
98
+ faraday (>= 1, < 3)
99
+ sawyer (~> 0.9)
28
100
  parallel (1.23.0)
29
- parser (3.2.2.3)
101
+ parser (3.2.2.4)
30
102
  ast (~> 2.4.1)
31
103
  racc
104
+ protocol-hpack (1.4.2)
105
+ protocol-http (0.25.0)
106
+ protocol-http1 (0.16.0)
107
+ protocol-http (~> 0.22)
108
+ protocol-http2 (0.15.1)
109
+ protocol-hpack (~> 1.4)
110
+ protocol-http (~> 0.18)
32
111
  public_suffix (5.0.3)
33
- racc (1.7.1)
112
+ racc (1.7.2)
34
113
  rainbow (3.1.1)
35
114
  rake (13.0.6)
36
- regexp_parser (2.8.1)
115
+ regexp_parser (2.8.2)
37
116
  rest-client (2.1.0)
38
117
  http-accept (>= 1.7.0, < 2.0)
39
118
  http-cookie (>= 1.0.2, < 2.0)
40
119
  mime-types (>= 1.16, < 4.0)
41
120
  netrc (~> 0.8)
42
- rexml (3.2.5)
121
+ rexml (3.2.6)
43
122
  rspec (3.12.0)
44
123
  rspec-core (~> 3.12.0)
45
124
  rspec-expectations (~> 3.12.0)
@@ -53,38 +132,62 @@ GEM
53
132
  diff-lcs (>= 1.2.0, < 2.0)
54
133
  rspec-support (~> 3.12.0)
55
134
  rspec-support (3.12.1)
56
- rubocop (1.54.1)
135
+ rubocop (1.57.2)
57
136
  json (~> 2.3)
58
137
  language_server-protocol (>= 3.17.0)
59
138
  parallel (~> 1.10)
60
- parser (>= 3.2.2.3)
139
+ parser (>= 3.2.2.4)
61
140
  rainbow (>= 2.2.2, < 4.0)
62
141
  regexp_parser (>= 1.8, < 3.0)
63
142
  rexml (>= 3.2.5, < 4.0)
64
- rubocop-ast (>= 1.28.0, < 2.0)
143
+ rubocop-ast (>= 1.28.1, < 2.0)
65
144
  ruby-progressbar (~> 1.7)
66
145
  unicode-display_width (>= 2.4.0, < 3.0)
67
- rubocop-ast (1.29.0)
146
+ rubocop-ast (1.30.0)
68
147
  parser (>= 3.2.1.0)
148
+ rubocop-capybara (2.19.0)
149
+ rubocop (~> 1.41)
150
+ rubocop-factory_bot (2.24.0)
151
+ rubocop (~> 1.33)
152
+ rubocop-rake (0.6.0)
153
+ rubocop (~> 1.0)
154
+ rubocop-rspec (2.25.0)
155
+ rubocop (~> 1.40)
156
+ rubocop-capybara (~> 2.17)
157
+ rubocop-factory_bot (~> 2.22)
69
158
  ruby-progressbar (1.13.0)
159
+ ruby2_keywords (0.0.5)
160
+ sawyer (0.9.2)
161
+ addressable (>= 2.3.5)
162
+ faraday (>= 0.17.3, < 3)
163
+ timers (4.3.5)
164
+ traces (0.11.1)
165
+ tzinfo (2.0.6)
166
+ concurrent-ruby (~> 1.0)
70
167
  unf (0.1.4)
71
168
  unf_ext
72
169
  unf_ext (0.0.8.2)
73
- unicode-display_width (2.4.2)
170
+ unicode-display_width (2.5.0)
74
171
  webmock (3.19.1)
75
172
  addressable (>= 2.8.0)
76
173
  crack (>= 0.3.2)
77
174
  hashdiff (>= 0.4.0, < 2.0.0)
78
175
 
79
176
  PLATFORMS
177
+ x86_64-darwin-21
80
178
  x86_64-darwin-22
81
179
 
82
180
  DEPENDENCIES
181
+ byebug
83
182
  defra_ruby_govpay!
183
+ defra_ruby_style (~> 0.4)
184
+ github_changelog_generator
84
185
  rake (~> 13.0)
85
186
  rspec (~> 3.0)
86
187
  rubocop (~> 1.21)
188
+ rubocop-rake
189
+ rubocop-rspec
87
190
  webmock (~> 3.4)
88
191
 
89
192
  BUNDLED WITH
90
- 2.4.8
193
+ 2.4.13
@@ -12,14 +12,15 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "This gem abstracts the Govpay integration code, facilitating " \
13
13
  "integration within defra ruby applications."
14
14
  spec.homepage = "https://github.com/DEFRA/defra-ruby-govpay"
15
- spec.required_ruby_version = ">= 2.6.0"
15
+ spec.required_ruby_version = ">= 3.2.0"
16
16
 
17
17
  spec.metadata["source_code_uri"] = "https://github.com/DEFRA/defra-ruby-govpay"
18
18
 
19
19
  spec.add_dependency "rest-client", "~> 2.1"
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
23
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
24
  end
25
+ spec.metadata["rubygems_mfa_required"] = "true"
25
26
  end
@@ -22,38 +22,41 @@ module DefraRubyGovpay
22
22
  end
23
23
 
24
24
  def send_request(method:, path:, params: nil, is_moto: false)
25
- Rails.logger.info build_log_message(method, path, params, is_moto)
25
+ @is_moto = is_moto
26
+ DefraRubyGovpay.logger.debug build_log_message(method, path, params)
26
27
 
27
28
  begin
28
- response = execute_request(method, path, params, is_moto)
29
- Rails.logger.info "Received response from Govpay: #{response}"
29
+ response = execute_request(method, path, params)
30
+ DefraRubyGovpay.logger.debug "Received response from Govpay: #{response}"
30
31
  response
31
- rescue StandardError => error
32
- handle_error(error, method, path, params)
32
+ rescue StandardError => e
33
+ handle_error(e, method, path, params)
33
34
  end
34
35
  end
35
36
 
36
37
  private
37
38
 
38
- def build_log_message(method, path, params, is_moto)
39
- "#{self.class} sending #{method} request to govpay (#{path}), params: #{params}, moto: #{is_moto}"
39
+ def build_log_message(method, path, params)
40
+ "#{self.class} sending #{method} request to govpay (#{path}), params: #{params}, moto: #{@is_moto}, " \
41
+ "govpay API token ending \"#{bearer_token[-5..]}\""
40
42
  end
41
43
 
42
- def execute_request(method, path, params, is_moto)
44
+ def execute_request(method, path, params)
43
45
  RestClient::Request.execute(
44
46
  method: method,
45
47
  url: url(path),
46
48
  payload: payload(params),
47
49
  headers: {
48
- "Authorization" => "Bearer #{bearer_token(is_moto)}",
50
+ "Authorization" => "Bearer #{bearer_token}",
49
51
  "Content-Type" => "application/json"
50
52
  }
51
53
  )
52
54
  end
53
55
 
54
56
  def handle_error(error, method, path, params)
55
- error_message = "Error sending request to govpay (#{method} #{path}, params: #{params}): #{error}"
56
- Rails.logger.info error_message
57
+ error_message = "Error sending request to govpay (#{method} #{path}, params: #{params}), " \
58
+ "response body #{JSON.parse(error.response.body)}: #{error}"
59
+ DefraRubyGovpay.logger.error error_message
57
60
  raise GovpayApiError, error_message
58
61
  end
59
62
 
@@ -61,10 +64,12 @@ module DefraRubyGovpay
61
64
  "#{@config.govpay_url}#{path}"
62
65
  end
63
66
 
64
- def bearer_token(is_moto)
65
- return @front_office_token unless @is_back_office
66
-
67
- is_moto ? @back_office_token : @front_office_token
67
+ def bearer_token
68
+ @bearer_token ||= if @is_back_office
69
+ @is_moto ? @back_office_token : @front_office_token
70
+ else
71
+ @front_office_token
72
+ end
68
73
  end
69
74
 
70
75
  def payload(params)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyGovpay
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
@@ -20,4 +20,13 @@ module DefraRubyGovpay
20
20
  self.configuration ||= Configuration.new
21
21
  yield(configuration)
22
22
  end
23
+
24
+ # Use DefraRubyGovpay.logger if it exists, else use a simple console logger
25
+ def self.logger
26
+ @logger ||= defined?(Rails) ? Rails.logger : Logger.new($stdout)
27
+ end
28
+
29
+ def self.logger=(logger)
30
+ @logger = logger
31
+ end
23
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_govpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Pratt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-03 00:00:00.000000000 Z
11
+ date: 2023-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -32,9 +32,12 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
+ - ".github/dependabot.yml"
35
36
  - ".gitignore"
36
37
  - ".rspec"
37
38
  - ".rubocop.yml"
39
+ - ".rubocop_todo.yml"
40
+ - ".ruby-version"
38
41
  - CHANGELOG.md
39
42
  - Gemfile
40
43
  - Gemfile.lock
@@ -56,6 +59,7 @@ homepage: https://github.com/DEFRA/defra-ruby-govpay
56
59
  licenses: []
57
60
  metadata:
58
61
  source_code_uri: https://github.com/DEFRA/defra-ruby-govpay
62
+ rubygems_mfa_required: 'true'
59
63
  post_install_message:
60
64
  rdoc_options: []
61
65
  require_paths:
@@ -64,14 +68,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
68
  requirements:
65
69
  - - ">="
66
70
  - !ruby/object:Gem::Version
67
- version: 2.6.0
71
+ version: 3.2.0
68
72
  required_rubygems_version: !ruby/object:Gem::Requirement
69
73
  requirements:
70
74
  - - ">="
71
75
  - !ruby/object:Gem::Version
72
76
  version: '0'
73
77
  requirements: []
74
- rubygems_version: 3.3.7
78
+ rubygems_version: 3.4.10
75
79
  signing_key:
76
80
  specification_version: 4
77
81
  summary: A Ruby gem facilitating integration with Govpay services in ruby applications.