Class: FedexWebService
- Inherits:
-
Object
- Object
- FedexWebService
- Defined in:
- lib/fedex_web_service.rb,
lib/fedex_web_service/address_verification.rb
Direct Known Subclasses
Defined Under Namespace
Classes: AddressVerification, AddressVerificationResponse
Constant Summary collapse
- @@gem_default_options =
{ :drop_off_type => "REGULAR_PICKUP", :residential => true, :label => 'GROUND_HOME_DELIVERY', :drop_off_type => 'REGULAR_PICKUP', :packaging_type => 'YOUR_PACKAGING', :label_format_type => 'COMMON2D', :label_stock_type => 'PAPER_4X6', :image_type => "PNG", :dimensions => {:length => 5, :width => 5, :height => 5} }
Instance Attribute Summary collapse
-
#full_response ⇒ Object
Returns the value of attribute full_response.
-
#label ⇒ Object
Returns the value of attribute label.
-
#temp_image ⇒ Object
Returns the value of attribute temp_image.
-
#tracking_number ⇒ Object
Returns the value of attribute tracking_number.
Instance Method Summary collapse
- #future_shipment(address_info, options = {}) ⇒ Object
-
#initialize ⇒ FedexWebService
constructor
A new instance of FedexWebService.
Constructor Details
#initialize ⇒ FedexWebService
Returns a new instance of FedexWebService.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fedex_web_service.rb', line 33 def initialize raw_config = File.read(RAILS_ROOT + "/config/fedex_config.yml") @fedex_conf = YAML.load(raw_config)[RAILS_ENV].symbolize_keys @key = @fedex_conf[:key] @password = @fedex_conf[:password] @accountnumber = @fedex_conf[:accountnumber] @meternumber = @fedex_conf[:meternumber] @ss_wsdl = @fedex_conf[:ss_wsdl] @default_options= @@gem_default_options.merge( @fedex_conf[:defaults] ) end |
Instance Attribute Details
#full_response ⇒ Object
Returns the value of attribute full_response.
8 9 10 |
# File 'lib/fedex_web_service.rb', line 8 def full_response @full_response end |
#label ⇒ Object
Returns the value of attribute label.
8 9 10 |
# File 'lib/fedex_web_service.rb', line 8 def label @label end |
#temp_image ⇒ Object
Returns the value of attribute temp_image.
8 9 10 |
# File 'lib/fedex_web_service.rb', line 8 def temp_image @temp_image end |
#tracking_number ⇒ Object
Returns the value of attribute tracking_number.
8 9 10 |
# File 'lib/fedex_web_service.rb', line 8 def tracking_number @tracking_number end |
Instance Method Details
#future_shipment(address_info, options = {}) ⇒ Object
45 46 47 48 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fedex_web_service.rb', line 45 def future_shipment(address_info, = {}) # this method sends a request to Fedex to get the future shipment date, a tracking number and the image file of a label # the method returns the tracking number as a result to show that the request was done correctly, those class attributes # are set to include the tracking number, the label (img) and the full response (SOAP object ... yech) = @default_options.merge( ).symbolize_keys! wsdl = File.( RAILS_ROOT + '/lib/wsdl/' + @fedex_conf[:ss_wsdl] ) driver = build_wsdl_driver(wsdl) call = {:WebAuthenticationDetail => {:UserCredential => {:Key => @key, :Password => @password} }, :ClientDetail => {:AccountNumber => @accountnumber, :MeterNumber => @meternumber }, :TransactionDetail=> {:CustomerTransactionId => '*** Ground Domestic Shipping Request v7' }, :Version => {:ServiceId => 'ship', :Major => '7', :Intermediate => '0', :Minor => '0'}, :RequestedShipment => { :ShipTimestamp => "#{3.days.from_now.strftime("%Y-%m-%d")}T9:00:00-07:00", :DropoffType => [:drop_off_type], :ServiceType => [:label], # 'FEDEX_2_DAY' 'FEDEX_GROUND' 'GROUND_HOME_DELIVERY' :PackagingType => [:packaging_type], # valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ... :SpecialServicesRequested => {:SpecialServiceType => "FUTURE_DATE_SHIPMENT"}, :Recipient => { #should have same address as Origin per docs :Contact => { :PersonName => address_info.first_name + " " + address_info.last_name, :PhoneNumber => address_info.phone #params[:phone] }, :Address => { :CountryCode => 'US', :StreetLines => address_info.shipping_address_1, #params[:shipAddress], :City => address_info.shipping_city, #params[:shipCity], :StateOrProvinceCode => address_info.shipping_state, #params[:shipState], :PostalCode => address_info.shipping_zip, #params[:shipZip] :Residential => [:residential] } }, :Shipper => { :Contact => { :PersonName => [:person_name], :PhoneNumber => [:phone_number] }, :Address => { :CountryCode => 'US', :StreetLines => [:address], :City => [:city], :StateOrProvinceCode => [:state], :PostalCode => [:postal_code] #:Residential => TRUE } }, :ShippingChargesPayment => { :PaymentType => 'SENDER', :Payor => { :AccountNumber => @accountnumber, :CountryCode => 'US' } }, :LabelSpecification => { :LabelFormatType => [:label_format_type], :LabelStockType => [:label_stock_type], :ImageType => [:image_type], #// valid values DPL, EPL2, PDF, ZPLII and PNG :CustomerSpecifiedDetail => {:MaskedData => "SHIPPER_ACCOUNT_NUMBER"} }, :RateRequestTypes => 'ACCOUNT', #, // valid values ACCOUNT and LIST :PackageCount => 1, :PackageDetail => "INDIVIDUAL_PACKAGES", :RequestedPackageLineItems => [{ :SequenceNumber=>1, :Weight => { :Units => "LB", :Value => 1 }, :Dimensions => { :Length => [:dimensions][:length], :Width => [:dimensions][:width], :Height => [:dimensions][:height], :Units => "IN" }, :CustomerReferences => [{:CustomerReferenceType => "INVOICE_NUMBER", :Value => "#{[:invoice_number]}"} ], #in a string so if it's empty it's just an empty string }] } } result = driver.processShipment(call) begin self.label = Base64.decode64(result.completedShipmentDetail.completedPackageDetails.label.parts.image) self.full_response = result self.tracking_number = result.completedShipmentDetail.completedPackageDetails.trackingIds.trackingNumber rescue Exception => e #the FEDEX call returned an error self.label = "error" self.full_response = result self.tracking_number = "error" end end |