Class: FriendlyShipping::Services::UspsInternational
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::UspsInternational
- Includes:
- Dry::Monads::Result::Mixin
- Defined in:
- lib/friendly_shipping/services/usps_international/rate_estimate_options.rb,
lib/friendly_shipping/services/usps_international.rb,
lib/friendly_shipping/services/usps_international/shipping_methods.rb,
lib/friendly_shipping/services/usps_international/parse_package_rate.rb,
lib/friendly_shipping/services/usps_international/parse_rate_response.rb,
lib/friendly_shipping/services/usps_international/serialize_rate_request.rb,
lib/friendly_shipping/services/usps_international/rate_estimate_package_options.rb
Overview
Options for one package when rating
Defined Under Namespace
Classes: ParsePackageRate, ParseRateResponse, RateEstimateOptions, RateEstimatePackageOptions, SerializeRateRequest
Constant Summary collapse
- CONTAINERS =
{ rectanglular: 'RECTANGULAR', roll: 'ROLL', variable: 'VARIABLE' }.freeze
- MAIL_TYPES =
{ all: 'ALL', airmail: 'AIRMAIL MBAG', envelope: 'ENVELOPE', flat_rate: 'FLATRATE', letter: 'LETTER', large_envelope: 'LARGEENVELOPE', package: 'PACKAGE', post_cards: 'POSTCARDS' }.freeze
- TEST_URL =
'https://stg-secure.shippingapis.com/ShippingAPI.dll'
- LIVE_URL =
'https://secure.shippingapis.com/ShippingAPI.dll'
- RESOURCES =
{ rates: 'IntlRateV2', }.freeze
- SHIPPING_METHODS =
[ ["1", "Priority Mail Express International"], ["2", "Priority Mail International"], ["4", "Global Express Guaranteed; (GXG)"], ["5", "Global Express Guaranteed; Document"], ["6", "Global Express Guarantee; Non-Document Rectangular"], ["7", "Global Express Guaranteed; Non-Document Non-Rectangular"], ["8", "Priority Mail International; Flat Rate Envelope"], ["9", "Priority Mail International; Medium Flat Rate Box"], ["10", "Priority Mail Express International; Flat Rate Envelope"], ["11", "Priority Mail International; Large Flat Rate Box"], ["12", "USPS GXG; Envelopes"], ["13", "First-Class Mail; International Letter"], ["14", "First-Class Mail; International Large Envelope"], ["15", "First-Class Package International Service"], ["16", "Priority Mail International; Small Flat Rate Box"], ["17", "Priority Mail Express International; Legal Flat Rate Envelope"], ["18", "Priority Mail International; Gift Card Flat Rate Envelope"], ["19", "Priority Mail International; Window Flat Rate Envelope"], ["20", "Priority Mail International; Small Flat Rate Envelope"], ["28", "Airmail M-Bag"] ].map do |code, name| FriendlyShipping::ShippingMethod.new( origin_countries: [Carmen::Country.coded('US')], name: name, service_code: code, domestic: false, international: true, ) end.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Instance Method Summary collapse
-
#initialize(login:, test: true, client: HttpClient.new) ⇒ UspsInternational
constructor
A new instance of UspsInternational.
-
#rate_estimates(shipment, options: RateEstimateOptions.new, debug: false) ⇒ Result<Array<FriendlyShipping::Rate>>
Get rate estimates from USPS International.
Constructor Details
#initialize(login:, test: true, client: HttpClient.new) ⇒ UspsInternational
Returns a new instance of UspsInternational.
36 37 38 39 40 |
# File 'lib/friendly_shipping/services/usps_international.rb', line 36 def initialize(login:, test: true, client: HttpClient.new) @login = login @test = test @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/friendly_shipping/services/usps_international.rb', line 10 def client @client end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
10 11 12 |
# File 'lib/friendly_shipping/services/usps_international.rb', line 10 def login @login end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
10 11 12 |
# File 'lib/friendly_shipping/services/usps_international.rb', line 10 def test @test end |
Instance Method Details
#rate_estimates(shipment, options: RateEstimateOptions.new, debug: false) ⇒ Result<Array<FriendlyShipping::Rate>>
Get rate estimates from USPS International
51 52 53 54 55 56 57 |
# File 'lib/friendly_shipping/services/usps_international.rb', line 51 def rate_estimates(shipment, options: RateEstimateOptions.new, debug: false) rate_request_xml = SerializeRateRequest.call(shipment: shipment, login: login, options: ) request = build_request(api: :rates, xml: rate_request_xml, debug: debug) client.post(request).bind do |response| ParseRateResponse.call(response: response, request: request, shipment: shipment, options: ) end end |