Class: UPS::Connection Abstract
- Inherits:
-
Object
- Object
- UPS::Connection
- Defined in:
- lib/ups/connection.rb
Overview
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'
- TRACK_PATH =
'/ups.app/xml/Track'
- 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.
-
#track(track_builder = nil) {|track_builder| ... } ⇒ Object
Makes a request to Track the status for a shipment.
Constructor Details
#initialize(params = {}) ⇒ Connection
Initializes a new UPS::Connection object
35 36 37 38 |
# File 'lib/ups/connection.rb', line 35 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.
50 51 52 53 54 55 56 57 58 |
# File 'lib/ups/connection.rb', line 50 def rates(rate_builder = nil) if rate_builder.nil? && block_given? rate_builder = UPS::Builders::RateBuilder.new yield rate_builder end response = get_response(RATE_PATH, rate_builder.to_xml) UPS::Parsers::RatesParser.new(response.body) 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.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ups/connection.rb', line 70 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 |
#track(track_builder = nil) {|track_builder| ... } ⇒ Object
Makes a request to Track the status for a shipment.
A pre-configured Builders::TrackBuilder object can be passed as the first option or a block yielded to configure a new Builders::TrackBuilder object.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ups/connection.rb', line 93 def track(track_builder = nil) if track_builder.nil? && block_given? track_builder = UPS::Builders::TrackBuilder.new yield track_builder end response = get_response(TRACK_PATH, track_builder.to_xml) UPS::Parsers::TrackParser.new(response.body) end |