Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated to the current version of the API (v12 for the ship service a…

…nd v13 for the rate service)
  • Loading branch information...
commit 69eb43a299a01d70d78cc125ba7ca6479459fd50 1 parent e8f80f2
@brewski authored
View
45 README.md
@@ -1,10 +1,10 @@
# fedex-web-services
## Description
-This gem provies an interface to the FedEx web services API (version 10). It interfaces with the FedEx web services SOAP API to look up shipping rates, generate labels, and cancel shipments (tracking coming soon).
+This gem provies an interface to the FedEx web services API. It supports version 12 of the ship service and version 13 of the rate service (the current versions as of November 2012). It interfaces with the FedEx web services SOAP API to look up shipping rates, generate labels, and cancel shipments (tracking coming soon).
## Setup
### Overview
-This gem requires a large number of classes to communicate with FedEx. These classes are defined by the WSDL files for the FedEx web services API. For copyright reasons this gem does not include the files. You will need to create a FedEx developer account to download these files (this gem works with ShipService_v10.wsdl and RateService_v10.wsdl). I recommend putting them under your project's lib/ directory in lib/fedex/web_services/wsdl.
+This gem requires a large number of classes to communicate with FedEx. These classes are defined by the WSDL files for the FedEx web services API. For copyright reasons this gem does not include the files. You will need to create a FedEx developer account to download these files (this gem works with ShipService_v12.wsdl and RateService_v13.wsdl). I recommend putting them under your project's lib/ directory in lib/fedex/web_services/wsdl.
### Creating the class definitions
Once you have the WSDL files, you will need to create the ruby classes used in the SOAP requests. This is a one time process that can be handled by the gem.
@@ -31,7 +31,7 @@ You can also manually generate the class files. To to this, run the following c
```ruby
require 'fedex'
-Fedex::WebServices::Definitions.generate_definitions('lib', *Dir.glob('lib/fedex/web_services/wsdl*.wsdl'))
+Fedex::WebServices::Definitions.generate_definitions('lib', *Dir.glob('lib/fedex/web_services/wsdl/*.wsdl'))
```
This will create the directory lib/fedex/web_services/definitions/ with the FedEx web services class definitions in it. After you have created the classes, simply include the following lines in your application to load them:
@@ -56,7 +56,8 @@ credentials = Service::Base::Credentials.new(
"ACCOUNT#",
"METER#",
"AUTH_KEY",
- "SECURITY_CODE"
+ "SECURITY_CODE",
+ :test
)
# prod_credentials = Service::Base::Credentials.new(
@@ -154,15 +155,39 @@ tracking_numbers = responses.map do |(tracking_number, label, charge)|
File.open("#{tracking_number}.pdf", "w") { |f| f << label }
tracking_number
end
+
+tracking_numbers.each do |tracking_number|
+ ship_service.delete_shipment(
+ TrackingId.new.tap do |tracking_id|
+ tracking_id.trackingNumber = tracking_number
+ tracking_id.trackingIdType = TrackingIdType::EXPRESS
+ end
+ )
+end
```
### Canceling a shipment
```ruby
-ship_service.delete_shipment(
- TrackingId.new.tap do |tracking_id|
- tracking_id.trackingNumber = tracking_numbers.first
- tracking_id.trackingIdType = TrackingIdType::EXPRESS
- end
-)
+tracking_numbers.each do |tracking_number|
+ ship_service.delete_shipment(
+ TrackingId.new.tap do |tracking_id|
+ tracking_id.trackingNumber = tracking_number
+ tracking_id.trackingIdType = TrackingIdType::EXPRESS
+ end
+ )
+end
```
+
+### Debugging
+You can see the SOAP wiredump by accessing Service::Base#wiredump after issuing a request.
+```ruby
+begin
+ rate, response = rate_service.get_rates(
+ ServiceType::FEDEX_2_DAY, RateRequestType::LIST, from, to, weight
+ )
+rescue
+ puts rate_service.wiredump
+ raise $!
+end
+```
View
2  lib/fedex/version.rb
@@ -1,3 +1,3 @@
module Fedex
- VERSION = "1.1.51"
+ VERSION = "1.1.6"
end
View
2  lib/fedex/web_services/request/base.rb
@@ -33,7 +33,7 @@ def client_detail
def version
VersionId.new.tap do |o|
o.serviceId = @service.service_id
- o.major = 10
+ o.major = @service.service_version
o.intermediate = 0
o.minor = 0
end
View
4 lib/fedex/web_services/request/get_rates.rb
@@ -45,7 +45,9 @@ def contents
o.shippingChargesPayment = Payment.new.tap do |o|
o.paymentType = PaymentType::SENDER
o.payor = Payor.new.tap do |o|
- o.accountNumber = @service.credentials.account_number
+ o.responsibleParty = Party.new.tap do |o|
+ o.accountNumber = @service.credentials.account_number
+ end
end
end
View
4 lib/fedex/web_services/request/process_shipment.rb
@@ -58,7 +58,9 @@ def contents
o.shippingChargesPayment = Payment.new.tap do |o|
o.paymentType = PaymentType::SENDER
o.payor = Payor.new.tap do |o|
- o.accountNumber = @service.credentials.account_number
+ o.responsibleParty = @shipper.clone.tap do |o|
+ o.accountNumber = @service.credentials.account_number
+ end
end
end
View
4 lib/fedex/web_services/service/base.rb
@@ -25,6 +25,10 @@ def service_id
raise "service_id must be implemented by subclasses of Service"
end
+ def service_version
+ raise "service_version must be implemented by subclasses of Service"
+ end
+
def service_url
(@credentials.environment.to_sym == :production) ?
'https://ws.fedex.com:443/web-services' :
View
4 lib/fedex/web_services/service/rate.rb
@@ -21,6 +21,10 @@ def service_id
:crs
end
+ def service_version
+ 13
+ end
+
def self.rate_for(response, rate_request_type)
details = response.rateReplyDetails.first.ratedShipmentDetails.select do |detail|
detail.shipmentRateDetail.rateType == "PAYOR_#{rate_request_type}_PACKAGE"
View
4 lib/fedex/web_services/service/ship.rb
@@ -9,6 +9,10 @@ def service_id
:ship
end
+ def service_version
+ 12
+ end
+
def process_shipment(service_type, shipper, recipient,
label_specification, package_weights, &process_contents)
Please sign in to comment.
Something went wrong with that request. Please try again.