Class: Shipping::UPS

Inherits:
Base show all
Defined in:
lib/shipping/ups.rb

Constant Summary collapse

API_VERSION =
"1.0001"

Instance Attribute Summary

Attributes inherited from Base

#address, #address2, #city, #company, #country, #currency_code, #data, #declared_value, #description, #dropoff_type, #email, #fedex_account, #fedex_meter, #fedex_url, #image_type, #insured_value, #label_type, #name, #package_total, #packaging_type, #pay_type, #phone, #plain_response, #required, #response, #sender_address, #sender_city, #sender_country, #sender_email, #sender_name, #sender_phone, #sender_state, #sender_zip, #service_type, #ship_date, #state, #transaction_type, #ups_account, #ups_password, #ups_user, #weight, #weight_units, #zip

Instance Method Summary collapse

Methods inherited from Base

#fedex, #initialize, plain, state_from_zip, #ups

Constructor Details

This class inherits a constructor from Shipping::Base

Instance Method Details

#priceObject

For current implementation docs, see www.ec.ups.com/ecommerce/techdocs/pdf/RatesandServiceHTML.pdf For upcoming XML implementation docs, see www.ups.com/gec/techdocs/pdf/dtk_RateXML_V1.zip



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shipping/ups.rb', line 29

def price
	@required = [:zip, :country, :sender_zip, :weight]
	
     @insured_value ||= 0
     @country ||= 'US'
     @sender_country ||= 'US'
     @transaction_type ||= 'GND' # default to UPS ground
     
	@data = "AppVersion=1.2&AcceptUPSLicenseAgreement=yes&ResponseType=application/x-ups-rss&ActionCode=3&RateChart=Customer+Counter&DCISInd=0&SNDestinationInd1=0&SNDestinationInd2=0&ResidentialInd=$r&PackagingType=00&ServiceLevelCode=#{@transaction_type}&ShipperPostalCode=#{@sender_zip}&ShipperCountry=#{@sender_country}&ConsigneePostalCode=#{@zip}&ConsigneeCountry=#{@country}&PackageActualWeight=#{@weight}&DeclaredValueInsurance=#{@insured_value}"

	get_response "http://www.ups.com/using/services/rave/qcost_dss.cgi"
	
	price = @response.split("%")
	price = price[price.size-2]
	
	return price.to_f
end

#valid_address?(delta = 1.0) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/shipping/ups.rb', line 49

def valid_address?( delta = 1.0 )
   @required = [:ups_account, :ups_user, :ups_password]
   
   state = STATES.has_value?(@state.downcase) ? STATES.index(@state.downcase) : @state
   
   @data = String.new
   b = Builder::XmlMarkup.new :target => @data
   
   b.instruct!
   b.AccessRequest {|b|
      b.AccessLicenseNumber @ups_account
      b.UserId @ups_user
      b.Password @ups_password
   }
   b.instruct!
   b.AddressValidationRequest {|b|
      b.Request {|b|
         b.RequestAction "AV"
         b.TransactionReference {|b|
            b.CustomerContext "#{@city}, #{state} #{@zip}"
            b.XpciVersion API_VERSION
         }
      }
      b.Address {|b|
         b.City @city
         b.StateProvinceCode state
         b.PostalCode @zip
      }
   }
   
 get_response "https://wwwcie.ups.com/ups.app/xml/AV"
   
   		if REXML::XPath.first(@response, "//AddressValidationResponse/Response/ResponseStatusCode").text == "1" && REXML::XPath.first(@response, "//AddressValidationResponse/AddressValidationResult/Quality").text.to_f >= delta
  return true
   		else
  return false
   		end
end