Class: Fedex::UpsInfo
- Inherits:
-
Object
- Object
- Fedex::UpsInfo
- Defined in:
- lib/ups/UpsInfo.rb
Overview
Provides a simple api to to ups’s time in transit service.
Constant Summary collapse
- TEST_URL =
"https://wwwcie.ups.com/ups.app/xml"
- PRODUCTION_URL =
UPS Production URL
"https://onlinetools.ups.com/ups.app/xml"
- XPCI_VERSION =
'1.0002'
- DEFAULT_CUTOFF_TIME =
14
- DEFAULT_TIMEOUT =
30
- DEFAULT_RETRY_COUNT =
3
- DEFAULT_COUNTRY_CODE =
'US'
- DEFAULT_UNIT_OF_MEASUREMENT =
'LBS'
Instance Method Summary collapse
- #getPrice(options) ⇒ Object
- #getTransitTime(options) ⇒ Object
-
#initialize(access_options) ⇒ UpsInfo
constructor
A new instance of UpsInfo.
Constructor Details
#initialize(access_options) ⇒ UpsInfo
Returns a new instance of UpsInfo.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ups/UpsInfo.rb', line 25 def initialize() @order_cutoff_time = [:order_cutoff_time] || DEFAULT_CUTOFF_TIME @timeout = [:timeout] || DEFAULT_TIMEOUT @retry_count = [:retry_count] || DEFAULT_CUTOFF_TIME @access_xml = generate_xml({ :AccessRequest => { :AccessLicenseNumber => [:access_license_number], :UserId => [:user_id], :Password => [:password] } }) @transit_from_attributes = { :AddressArtifactFormat => { :PoliticalDivision2 => [:sender_city], :PoliticalDivision1 => [:sender_state], :CountryCode => [:sender_country_code] || DEFAULT_COUNTRY_CODE, :PostcodePrimaryLow => [:sender_zip] } } @rate_from_attributes = { :Address => { :City => [:sender_city], :StateProvinceCode => [:sender_state], :CountryCode => [:sender_country_code] || DEFAULT_COUNTRY_CODE, :PostalCode => [:sender_zip] } } end |
Instance Method Details
#getPrice(options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ups/UpsInfo.rb', line 58 def getPrice () @url = [:mode] == "production" ? PRODUCTION_URL : TEST_URL + '/Rate' #@url = options[:url] + '/Rate' # build our request xml xml = @access_xml + generate_xml(build_price_attributes()) #puts xml # attempt the request in a timeout delivery_price = 0 begin Timeout.timeout(@timeout) do response = send_request(@url, xml) delivery_price = response_to_price(response) end delivery_price end end |
#getTransitTime(options) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ups/UpsInfo.rb', line 79 def getTransitTime() @url = [:mode] == "production" ? PRODUCTION_URL : TEST_URL + '/TimeInTransit' #@url = options[:url] + '/TimeInTransit' # build our request xml pickup_date = calculate_pickup_date [:pickup_date] = pickup_date.strftime('%Y%m%d') xml = @access_xml + generate_xml(build_transit_attributes()) # attempt the request in a timeout delivery_dates = {} attempts = 0 begin Timeout.timeout(@timeout) do response = send_request(@url, xml) delivery_dates = response_to_map(response) end # We can only attempt to recover from Timeout errors, all other errors # should be raised back to the user rescue Timeout::Error => error if(attempts < @retry_count) attempts += 1 retry else raise error end end delivery_dates end |