usps-imis-api 0.9.11 → 0.9.12

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: cb22ca224852ea6118af6df2c429bfa597903c4fe4583243ea3a28b6886a21db
4
- data.tar.gz: 606da2d8b21e9008b402bf66cacee53de74ebec860141b5a960690fa8364ab3a
3
+ metadata.gz: 68a7b6152d35f64ce54c4245ac83f6de5bac21fcf1618c0f1c249fd0f08f4573
4
+ data.tar.gz: b7a8033a52dc11c2afea8ef69b19a01a07a4aceb5055dde274c6f0551f2b3eb9
5
5
  SHA512:
6
- metadata.gz: a347f809fa6eba2e229fcbb1cdc0107ca2797d56950190ad299495c8525f9d858e78e8953aa53dd871906e5b8a95899e64837f31a298cca00e215835d1198aed
7
- data.tar.gz: 5768933b5586148a67abd45236e7cbcf7084cb25e8ed7c4c8e509fb9fe9f23f1225c6b5d0f7fecf3be350f48459edbee6f6ec80626f70c041c7de6ee3998a429
6
+ metadata.gz: 7610661e87565844fdb391ecd0a4fca7a0d0fb269b7de604827846b99f57d97cc0b580a1a1bfdc6d856a19124b8f8f76ca03dcb3edfa869b894e0e662b0766f1
7
+ data.tar.gz: dbd76fb61d391ad072f5f431e3539ba64af667abe22f4b8f0521359ac9a60aa4d92a00fba37a2f92585adf955c238d165f2b221e6451c5917786a434fc46dea8
data/Readme.md CHANGED
@@ -365,6 +365,41 @@ allow(api).to(
365
365
  )
366
366
  ```
367
367
 
368
+ ### VCR
369
+
370
+ If you would like to use the included VCR config, make sure your Gemfile includes the required gems:
371
+
372
+ ```ruby
373
+ gem 'cgi' # 2025-10-27 - Currently required for Ruby 3.5
374
+ gem 'vcr'
375
+ gem 'webmock'
376
+ ```
377
+
378
+ In `spec_helper.rb`, add the following:
379
+
380
+ ```ruby
381
+ require 'usps/vcr'
382
+ Usps::Vcr::Config.configure!
383
+ ```
384
+
385
+ You can also pass additional VCR config options through:
386
+
387
+ ```ruby
388
+ Usps::Vcr::Config.configure! do |config|
389
+ config.ignore_localhost = true
390
+ end
391
+ ```
392
+
393
+ If you have any tests that are dependent on ordering to (re-)generate cassettes, a helper is also
394
+ available to support adding example metadata, which will use a fixed order when the environment
395
+ varialbe `VCR=all` is set:
396
+
397
+ ```ruby
398
+ describe 'examples that care about order', order: Usps::Vcr::Config.vcr_record_ordered do
399
+ # ...
400
+ end
401
+ ```
402
+
368
403
  ## Exception Handling
369
404
 
370
405
  All internal exceptions inherit from `Usps::Imis::Error`.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.9.11'
5
+ VERSION = '0.9.12'
6
6
  end
7
7
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps
4
+ module Vcr
5
+ module Config
6
+ class << self
7
+ def configure!
8
+ WebMock.disable_net_connect!
9
+
10
+ VCR.configure do |config|
11
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
12
+ config.hook_into :webmock
13
+ default_options(config)
14
+ config.configure_rspec_metadata!
15
+ apply_filters(config)
16
+
17
+ yield(config) if block_given?
18
+ end
19
+ end
20
+
21
+ def vcr_record_ordered
22
+ ENV['VCR'] == 'all' ? :defined : :random
23
+ end
24
+
25
+ private
26
+
27
+ def default_options(config)
28
+ config.default_cassette_options = {
29
+ record: ENV['VCR'] ? ENV['VCR'].to_sym : :once,
30
+ match_requests_on: %i[method uri]
31
+ }
32
+ end
33
+
34
+ def apply_filters(config)
35
+ Filters.apply!(
36
+ config,
37
+ *%i[
38
+ username password access_token bearer_token
39
+ ignore_response_headers cf_ray cookie date
40
+ issued expires
41
+ ]
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps
4
+ module Vcr
5
+ module Filters
6
+ class << self
7
+ def apply!(config, *filters)
8
+ filters.each { public_send(it, config) }
9
+ end
10
+
11
+ def username(config)
12
+ value = ENV.fetch('IMIS_USERNAME')
13
+ config.filter_sensitive_data('<USERNAME>') { value }
14
+ config.filter_sensitive_data('<USERNAME>') { CGI.escape(value) }
15
+ config.filter_sensitive_data('<USERNAME>') { value.upcase }
16
+ config.filter_sensitive_data('<USERNAME>') { CGI.escape(value).upcase }
17
+ end
18
+
19
+ def password(config)
20
+ value = ENV.fetch('IMIS_PASSWORD')
21
+ config.filter_sensitive_data('<PASSWORD>') { value }
22
+ config.filter_sensitive_data('<PASSWORD>') { CGI.escape(value) }
23
+ end
24
+
25
+ def access_token(config)
26
+ filter_json_field(config, 'access_token', '<ACCESS_TOKEN>')
27
+ end
28
+
29
+ def bearer_token(config)
30
+ config.filter_sensitive_data('<BEARER_TOKEN>') do |interaction|
31
+ if interaction.request.headers['Authorization']
32
+ authorization = interaction.request.headers['Authorization'].first
33
+ if (match = authorization.match(/^Bearer\s+([^,\s]+)/))
34
+ match.captures.first
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def ignore_response_headers(config)
41
+ config.before_record do |interaction|
42
+ interaction.response.headers.delete('Report-To')
43
+ interaction.response.headers.delete('Content-Security-Policy-Report-Only')
44
+ end
45
+ end
46
+
47
+ def cf_ray(config)
48
+ config.filter_sensitive_data('<CF_RAY>') do |interaction|
49
+ interaction.response.headers['Cf-Ray']&.first
50
+ end
51
+ end
52
+
53
+ def cookie(config)
54
+ config.filter_sensitive_data('<COOKIE>') do |interaction|
55
+ interaction.response.headers['Set-Cookie']&.first
56
+ end
57
+ end
58
+
59
+ def date(config)
60
+ config.filter_sensitive_data('<DATE>') do |interaction|
61
+ interaction.response.headers['Date']&.first
62
+ end
63
+ end
64
+
65
+ def issued(config)
66
+ filter_json_field(config, '.issued', '<ISSUED>')
67
+ end
68
+
69
+ def expires(config)
70
+ filter_json_field(config, '.expires', '<EXPIRES>')
71
+ end
72
+
73
+ private
74
+
75
+ def filter_json_field(config, field_name, placeholder)
76
+ config.filter_sensitive_data(placeholder) do |interaction|
77
+ if interaction.response.headers['Content-Type']&.first&.include?('application/json')
78
+ begin
79
+ JSON.parse(interaction.response.body)[field_name]
80
+ rescue JSON::ParserError
81
+ nil
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vcr'
4
+ require 'webmock/rspec'
5
+
6
+ require_relative 'vcr/filters'
7
+ require_relative 'vcr/config'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-imis-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.9.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -55,6 +55,9 @@ files:
55
55
  - lib/usps/imis/query.rb
56
56
  - lib/usps/imis/requests.rb
57
57
  - lib/usps/imis/version.rb
58
+ - spec/support/usps/vcr.rb
59
+ - spec/support/usps/vcr/config.rb
60
+ - spec/support/usps/vcr/filters.rb
58
61
  homepage: https://github.com/unitedstatespowersquadrons/imis-api-ruby
59
62
  licenses: []
60
63
  metadata:
@@ -62,6 +65,7 @@ metadata:
62
65
  rdoc_options: []
63
66
  require_paths:
64
67
  - lib
68
+ - spec/support
65
69
  required_ruby_version: !ruby/object:Gem::Requirement
66
70
  requirements:
67
71
  - - ">="