usps-imis-api 0.9.11 → 0.9.13
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 +4 -4
- data/Readme.md +35 -0
- data/lib/usps/imis/version.rb +1 -1
- data/spec/support/usps/vcr/config.rb +47 -0
- data/spec/support/usps/vcr/filters.rb +89 -0
- data/spec/support/usps/vcr.rb +7 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53c6da160ddc5b59bd09e067311d706ca8b6bf97f1f96b82b9213f5617cd518e
|
|
4
|
+
data.tar.gz: 95454c52fcdf4f17a7a81009c863d0ef7691dc3e5346f094df9340c39c25185a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 138797b4b4593c275e540e3c5eb2960cd948ba3653bb3d8ac8349ab3f808038c2aa1059dd45e569cd801e6c268232f5844dbf918a0fc9b7107d67b9064c5c1bd
|
|
7
|
+
data.tar.gz: c4817cf8e7ba625e6ed89cb36dc6cff7ac3a7bf630b710e9f7b4de825c30b8251b5e31565a2f1272cb52696d141ec1868b299e8632f27bbe12a4ae9599541c12
|
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`.
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -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', '<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', '<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
|
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.
|
|
4
|
+
version: 0.9.13
|
|
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
|
- - ">="
|