Giter Site home page Giter Site logo

keeruline / fedex-web-services Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brewski/fedex-web-services

0.0 1.0 0.0 293 KB

A Ruby Gem that provies an interface to the FedEx web services API (version 10)

License: MIT License

Ruby 100.00%

fedex-web-services's Introduction

fedex-web-services

Description

This gem provides an interface to the FedEx web services API. It supports version 12 of the ship service and version 4 of the close service.

Testing

This gem includes a small integration test suite to test several of the API methods in the FedEx sandbox environment. You can run the tests from the source of this gem, or from within a rails application that includes this gem:

export FEDEX_ACCOUNT=account FEDEX_METER=meter FEDEX_AUTH_KEY=authkey FEDEX_SECURITY_CODE=code
bundle exec rake fedex_web_services:test

Examples

Creating a shipment with multiple packages

require 'fedex_web_services'

include FedexWebServices
include FedexWebServices::Soap

credentials = Api::Credentials.new(
  ENV.fetch('FEDEX_ACCOUNT'),
  ENV.fetch('FEDEX_METER'),
  ENV.fetch('FEDEX_AUTH_KEY'),
  ENV.fetch('FEDEX_SECURITY_CODE'),
  :test # or :production
)
api = Api.new(credentials)

service = 'FEDEX_2_DAY'

from = Ship::Party.new.tap do |shipper|
  shipper.contact = Ship::Contact.new.tap do |contact|
    contact.personName  = "Joe Shmoe"
    contact.phoneNumber = "(123) 456 789"
  end

  shipper.address = Ship::Address.new.tap do |address|
    address.streetLines         = [ "123 4th St" ]
    address.city                = "San Luis Obispo"
    address.stateOrProvinceCode = "CA"
    address.postalCode          = "93401"
    address.countryCode         = "US"
    address.residential         = true
  end
end

to = Ship::Party.new.tap do |recipient|
  recipient.contact = Ship::Contact.new.tap do |contact|
    contact.personName  = "Ahwahnee Hotel"
    contact.phoneNumber = "(801) 559-5000"
  end
  recipient.address = Ship::Address.new.tap do |address|
    address.streetLines         = [ "9006 Yosemite Lodge Drive" ]
    address.city                = "Yosemite National Park"
    address.stateOrProvinceCode = "CA"
    address.postalCode          = "95389"
    address.countryCode         = "US"
    address.residential         = true
  end
end

label_spec = Ship::LabelSpecification.new
label_spec.labelFormatType = Ship::LabelFormatType::COMMON2D
label_spec.imageType       = Ship::ShippingDocumentImageType::PDF
label_spec.labelStockType  = Ship::ShippingDocumentStockType::PAPER_LETTER

weights = [ 10, 55.34, 10.2 ].map do |weight|
  Ship::Weight.new.tap do |w|
    w.units = "LB"
    w.value = weight
  end
end

requests = ProcessShipmentRequest.shipment_requests(service, from, to, label_spec, weights)
requests.each do |request|
  request.sender_paid!(credentials.account_number)
  request.list_rate!
  request.regular_pickup!
  request.customer_reference!("01234")
  request.customer_invoice!("56789")
end

tracking_numbers = api.process_shipments(requests).map do |response|
  filename = "#{response.tracking_number}.pdf"
  File.write(filename, response.label)
  puts "Wrote #{filename}"
  response.tracking_number
end

Canceling a shipment

tracking_numbers.each do |tracking_number|
  delete_request = DeleteShipmentRequest.new
  delete_request.delete_all_packages!(tracking_number, Ship::TrackingIdType::EXPRESS)
  api.delete_shipment(delete_request)
  puts "Deleted shipment #{tracking_number}"
end

Debugging

You can see the SOAP wiredump by accessing Api#wiredump after issuing a request.

begin
  api.process_shipments(...)
rescue
  puts api.wiredump
  raise $!
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.