Class: UspsApi::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/usps_api/configuration.rb

Overview

An enum for SDK environments.

Constant Summary collapse

ENVIRONMENT =
[
  PRODUCTION = 'Production'.freeze,
  TESTING = 'Testing'.freeze
].freeze

Class Method Summary collapse

Class Method Details

.from_value(value, default_value = PRODUCTION) ⇒ Object

Converts a string or symbol into a valid Environment constant.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/usps_api/configuration.rb', line 15

def self.from_value(value, default_value = PRODUCTION)
  return default_value if value.nil?

  str = value.to_s.strip.downcase
  case str
  when 'production' then PRODUCTION
  when 'testing' then TESTING

  else
    warn "[Environment] Unknown environment '#{value}', falling back to #{default_value} "
    default_value
  end
end