usps-imis-api 0.14.0 → 0.15.0

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: b8075b08c9527b8309ac2e784db46c2e9dc6d922b5a4ee7392fbb493ece0bdb8
4
- data.tar.gz: 1f37a85470c68ee132e42e10f26cf3d6be97700d160fbd7479d14bdcd3f23474
3
+ metadata.gz: 3b20172987ecd5b1bd13b0f142b616d71704e906aed312d71dca5e9b63c8432c
4
+ data.tar.gz: aab0fa56ded131c2a116203ea292c15ab024d408309a03144aeb5e795df77820
5
5
  SHA512:
6
- metadata.gz: 158b6e90ec01dc5b1d8f3f9ddad0d91434ba86facfe05b1547aaa4ba3a16679092f6e4c4a83d6c96d3ff1e02724bd1c8d8e4aa42eb45782019f18989036842ba
7
- data.tar.gz: 298cf14dee964a5c6c1029a68a629b3e0cd921ec7f3ff396947919269686c3233a160fe48d36eb7058431f7e8d5be8b9bd174c911c23f4cdf5bed836ea11b8b2
6
+ metadata.gz: 108e95c1487b42e6cf8508705e286094b1b79f7c2b3a10feb5bbf818d926837c1f5ca0f35e1f1bfc08b3a9a3a00e8e09f1b734dcde32e7995aa012ffceb78841
7
+ data.tar.gz: b42d7b63f8a0131003d8bb86cd4b2abc25e28842b6d79f9af01d426cd5dedbe64f81afa727b13658349b618a18203c5d60e88989528b3dc2cd1fb761a6ccebae
data/lib/usps/imis/api.rb CHANGED
@@ -264,13 +264,14 @@ module Usps
264
264
  def http_connection
265
265
  return @http_connection if @http_connection&.started?
266
266
 
267
- hostname = URI(Imis.configuration.hostname)
267
+ config = Imis.configuration
268
+ hostname = URI(config.hostname)
268
269
  @http_connection = Net::HTTP.new(hostname.host, hostname.port).tap do |http|
269
270
  http.use_ssl = true
270
271
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
271
- http.open_timeout = 10
272
- http.read_timeout = 30
273
- http.write_timeout = 30
272
+ http.open_timeout = config.open_timeout
273
+ http.read_timeout = config.read_timeout
274
+ http.write_timeout = config.write_timeout
274
275
  http.keep_alive_timeout = 30
275
276
  http.start
276
277
  end
@@ -45,6 +45,11 @@ module Usps
45
45
  @options = input_options.merge(**)
46
46
  options[:version] = true if default_options?
47
47
 
48
+ # Skip model loading, unless we explicitly need it, because the CLI
49
+ # generally only works with raw response data
50
+ #
51
+ Usps::Imis::Models.skip! unless options[:business_objects]
52
+
48
53
  configure!
49
54
  logging!
50
55
  @logger = Imis.logger('CommandLine')
@@ -10,8 +10,19 @@ module Usps
10
10
  IMIS_ROOT_URL_PROD = 'https://portal.americasboatingclub.org'
11
11
  IMIS_ROOT_URL_DEV = 'https://abcdev.imiscloud.com'
12
12
  DEFAULT_GLOBAL_LOG_PATH = '/var/log/imis/imis.log'
13
+
14
+ # Net::HTTP timeouts for the API connection (seconds). open_timeout governs connection
15
+ # establishment (TCP connect + TLS handshake) — the phase that stalls when iMIS is unreachable,
16
+ # so it defaults low to fail fast rather than pin the caller.
17
+ DEFAULT_OPEN_TIMEOUT = 3
18
+ DEFAULT_READ_TIMEOUT = 30
19
+ DEFAULT_WRITE_TIMEOUT = 30
20
+
13
21
  REQUIRED = %w[username password].freeze
14
- OPTIONAL = %w[environment logger_file global_log_path pretty_print_api].freeze
22
+ OPTIONAL = %w[
23
+ environment logger_file global_log_path pretty_print_api
24
+ open_timeout read_timeout write_timeout
25
+ ].freeze
15
26
  SETTABLE = (REQUIRED + OPTIONAL).freeze
16
27
 
17
28
  class << self
@@ -24,13 +35,16 @@ module Usps
24
35
  end
25
36
  end
26
37
 
27
- attr_accessor :username, :password, :pretty_print_api
38
+ attr_accessor :username, :password, :pretty_print_api, :open_timeout, :read_timeout, :write_timeout
28
39
  attr_reader :environment, :logger, :logger_level, :logger_file
29
40
 
30
41
  def initialize
31
42
  @environment = default_environment
32
43
  @username = ENV.fetch('IMIS_USERNAME', nil)
33
44
  @password = ENV.fetch('IMIS_PASSWORD', nil)
45
+ @open_timeout = Integer(ENV.fetch('IMIS_OPEN_TIMEOUT', DEFAULT_OPEN_TIMEOUT).to_s, 10)
46
+ @read_timeout = Integer(ENV.fetch('IMIS_READ_TIMEOUT', DEFAULT_READ_TIMEOUT).to_s, 10)
47
+ @write_timeout = Integer(ENV.fetch('IMIS_WRITE_TIMEOUT', DEFAULT_WRITE_TIMEOUT).to_s, 10)
34
48
  @base_logger = Logger.new($stdout, level: :info)
35
49
  @logger = ActiveSupport::TaggedLogging.new(@base_logger)
36
50
 
@@ -21,11 +21,17 @@ module Usps
21
21
  # Look up the registered Model class for an iMIS Business Object name.
22
22
  # Returns +nil+ if none is registered.
23
23
  #
24
- def for_entity(name) = @registry[name.to_s]
24
+ def for_entity(name)
25
+ load!
26
+ @registry[name.to_s]
27
+ end
25
28
 
26
29
  # All registered Business Object names, sorted.
27
30
  #
28
- def entity_names = @registry.keys.sort
31
+ def entity_names
32
+ load!
33
+ @registry.keys.sort
34
+ end
29
35
 
30
36
  # Register a Model subclass under its +business_object_name+. Called
31
37
  # from +Base.business_object+; tests can call +deregister+ for cleanup.
@@ -35,23 +41,52 @@ module Usps
35
41
  # Remove a Model subclass from the routing registry.
36
42
  #
37
43
  def deregister(name) = @registry.delete(name.to_s)
44
+
45
+ # Require all model files. Hand-written files at the top level go first
46
+ # (some — e.g. party.rb — require their own subdirectory). Auto-generated
47
+ # wrappers under generated/ are loaded next. Finally, files in associations/
48
+ # reopen previously-loaded classes to declare cross-model relationships;
49
+ # they're separated from generated/ so the generator doesn't clobber them.
50
+ #
51
+ # Deferred until first registry lookup so CLI startup (--help, --version)
52
+ # doesn't pay the cost of requiring several hundred model files.
53
+ #
54
+ # Trigger lazy load when callers reference a model constant directly
55
+ # (e.g. +Usps::Imis::Models::Party+) before any registry lookup has
56
+ # forced loading.
57
+ #
58
+ def const_missing(name)
59
+ return super if loaded? || skipped? || name == :Base
60
+
61
+ load!
62
+ const_get(name)
63
+ end
64
+
65
+ def load!
66
+ return if loaded? || skipped?
67
+
68
+ dir = File.expand_path('models', __dir__)
69
+ paths =
70
+ Dir[File.join(dir, '*.rb')] +
71
+ Dir[File.join(dir, 'generated', '*.rb')] +
72
+ Dir[File.join(dir, 'associations', '*.rb')]
73
+ paths
74
+ .reject { it.end_with?('models/base.rb') }
75
+ .map { it.sub(/\.rb$/, '') }
76
+ .each { require it }
77
+
78
+ @loaded = true
79
+ end
80
+
81
+ def skip!
82
+ @skipped = true
83
+ end
84
+
85
+ def loaded? = @loaded
86
+ def skipped? = @skipped
38
87
  end
39
88
  end
40
89
  end
41
90
  end
42
91
 
43
92
  require_relative 'models/base'
44
-
45
- # Require all other model files. Hand-written files at the top level go first
46
- # (some — e.g. party.rb — require their own subdirectory). Auto-generated
47
- # wrappers under generated/ are loaded next. Finally, files in associations/
48
- # reopen previously-loaded classes to declare cross-model relationships;
49
- # they're separated from generated/ so the generator doesn't clobber them.
50
- paths =
51
- Dir[File.join(__dir__, 'models', '*.rb')] +
52
- Dir[File.join(__dir__, 'models', 'generated', '*.rb')] +
53
- Dir[File.join(__dir__, 'models', 'associations', '*.rb')]
54
- paths
55
- .reject { it.end_with?('models/base.rb') }
56
- .map { it.sub(/\.rb$/, '') }
57
- .each { require it }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.14.0'
5
+ VERSION = '0.15.0'
6
6
  end
7
7
  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.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander