Class: UPS::Connection Abstract
- Inherits:
-
Object
- Object
- UPS::Connection
- Defined in:
- lib/ups/connection.rb
Overview
This class is abstract.
The Connection class acts as the main entry point to performing rate and ship operations against the UPS API.
Constant Summary collapse
- TEST_URL =
'https://wwwcie.ups.com'
- LIVE_URL =
'https://onlinetools.ups.com'
- RATE_PATH =
'/ups.app/xml/Rate'
- SHIP_CONFIRM_PATH =
'/ups.app/xml/ShipConfirm'
- SHIP_ACCEPT_PATH =
'/ups.app/xml/ShipAccept'
- ADDRESS_PATH =
'/ups.app/xml/XAV'
- DEFAULT_PARAMS =
{ test_mode: false }
Instance Attribute Summary collapse
-
#url ⇒ String
The base url to use either TEST_URL or LIVE_URL.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Connection
constructor
Initializes a new Connection object.
-
#rates(rate_builder = nil) {|rate_builder| ... } ⇒ Object
Makes a request to fetch Rates for a shipment.
-
#ship(confirm_builder = nil) {|ship_confirm_builder| ... } ⇒ Object
Makes a request to ship a package.
Constructor Details
#initialize(params = {}) ⇒ Connection
Initializes a new UPS::Connection object
34 35 36 37 |
# File 'lib/ups/connection.rb', line 34 def initialize(params = {}) params = DEFAULT_PARAMS.merge(params) self.url = (params[:test_mode]) ? TEST_URL : LIVE_URL end |
Instance Attribute Details
#url ⇒ String
The base url to use either TEST_URL or LIVE_URL
14 15 16 |
# File 'lib/ups/connection.rb', line 14 def url @url end |
Instance Method Details
#rates(rate_builder = nil) {|rate_builder| ... } ⇒ Object
Makes a request to fetch Rates for a shipment.
A pre-configured Builders::RateBuilder object can be passed as the first option or a block yielded to configure a new Builders::RateBuilder object.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ups/connection.rb', line 49 def rates(rate_builder = nil) if rate_builder.nil? && block_given? rate_builder = UPS::Builders::RateBuilder.new yield rate_builder end response = get_response_stream RATE_PATH, rate_builder.to_xml UPS::Parsers::RatesParser.new.tap do |parser| Ox.sax_parse(parser, response) end end |
#ship(confirm_builder = nil) {|ship_confirm_builder| ... } ⇒ Object
Makes a request to ship a package
A pre-configured Builders::ShipConfirmBuilder object can be passed as the first option or a block yielded to configure a new Builders::ShipConfirmBuilder object.
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ups/connection.rb', line 71 def ship(confirm_builder = nil) if confirm_builder.nil? && block_given? confirm_builder = Builders::ShipConfirmBuilder.new yield confirm_builder end confirm_response = make_confirm_request(confirm_builder) return confirm_response unless confirm_response.success? accept_builder = build_accept_request_from_confirm(confirm_builder, confirm_response) make_accept_request accept_builder end |