Giter Club home page Giter Club logo

ups-ruby's Introduction

Gem Version

UPS

UPS Gem for accessing the UPS API from Ruby. Using the gem you can:

  • Return quotes from the UPS API
  • Book shipments
  • Return labels and tracking numbers for a shipment

This gem is currently used in production at Veeqo

Installation

gem install ups-ruby

...or add it to your project's Gemfile.

Documentation

Yard documentation can be found at RubyDoc.

Sample Usage

Return rates

require 'ups'
server = UPS::Connection.new(test_mode: true)
response = server.rates do |rate_builder|
  rate_builder.add_access_request 'API_KEY', 'USERNAME', 'PASSWORD'
  rate_builder.add_shipper company_name: 'Veeqo Limited',
    phone_number: '01792 123456',
    address_line_1: '11 Wind Street',
    city: 'Swansea',
    state: 'Wales',
    postal_code: 'SA1 1DA',
    country: 'GB',
    shipper_number: 'ACCOUNT_NUMBER'
  rate_builder.add_ship_from company_name: 'Veeqo Limited',
    phone_number: '01792 123456',
    address_line_1: '11 Wind Street',
    city: 'Swansea',
    state: 'Wales',
    postal_code: 'SA1 1DA',
    country: 'GB',
    shipper_number: 'ACCOUNT_NUMBER'
  rate_builder.add_ship_to company_name: 'Google Inc.',
    phone_number: '0207 031 3000',
    address_line_1: '1 St Giles High Street',
    city: 'London',
    state: 'England',
    postal_code: 'WC2H 8AG',
    country: 'GB'
  rate_builder.add_package weight: '0.5',
    unit: 'KGS'
end

Create domestic shipment

require 'ups-ruby'
server = UPS::Connection.new(test_mode: true)
response = server.ship do |shipment_builder|
  shipment_builder.add_access_request 'API_KEY', 'USERNAME', 'PASSWORD'
  shipment_builder.add_shipper company_name: 'Veeqo Limited',
    phone_number: '01792 123456',
    attention_name: 'John Doe',
    address_line_1: '11 Wind Street',
    city: 'Swansea',
    state: 'Wales',
    postal_code: 'SA1 1DA',
    country: 'GB',
    shipper_number: 'ACCOUNT_NUMBER'
  shipment_builder.add_ship_from company_name: 'Veeqo Limited',
    phone_number: '01792 123456',
    address_line_1: '11 Wind Street',
    attention_name: 'John Doe',
    city: 'Swansea',
    state: 'Wales',
    postal_code: 'SA1 1DA',
    country: 'GB',
    shipper_number: 'ACCOUNT_NUMBER'
  shipment_builder.add_ship_to company_name: 'Google Inc.',
    phone_number: '0207 031 3000',
    address_line_1: '1 St Giles High Street',
    attention_name: 'John Doe',
    city: 'London',
    state: 'England',
    postal_code: 'WC2H 8AG',
    country: 'GB'
  shipment_builder.add_package weight: '0.5',
    unit: 'KGS'
  shipment_builder.add_description 'White coffee mug'
  shipment_builder.add_payment_information 'ACCOUNT_NUMBER'
  shipment_builder.add_service '65' # returned in rates response
end
# Then use...
response.success?
response.label_graphic_image
response.label_html_image
response.label_graphic_extension
response.tracking_number

Create international shipment with customs documentation request

require 'ups-ruby'
server = UPS::Connection.new(test_mode: true)
response = server.ship do |shipment_builder|
  shipment_builder.add_access_request 'API_KEY', 'USERNAME', 'PASSWORD'
  shipment_builder.add_shipper company_name: 'Veeqo Limited',
    phone_number: '01792 123456',
    attention_name: 'John Doe',
    address_line_1: '11 Wind Street',
    city: 'Swansea',
    state: 'Wales',
    postal_code: 'SA1 1DA',
    country: 'GB',
    shipper_number: 'ACCOUNT_NUMBER'
  shipment_builder.add_ship_from company_name: 'Veeqo Limited',
    phone_number: '01792 123456',
    address_line_1: '11 Wind Street',
    attention_name: 'John Doe',
    city: 'Swansea',
    state: 'Wales',
    postal_code: 'SA1 1DA',
    country: 'GB',
    shipper_number: 'ACCOUNT_NUMBER'
  shipment_builder.add_ship_to company_name: 'Google Inc.',
    phone_number: '0207 031 3000',
    address_line_1: '389 Townsend Street',
    attention_name: 'John Doe',
    address_line_2: 'Apt 21',
    city: 'San Francisco',
    state: 'CA',
    postal_code: '94107',
    country: 'US'
  shipment_builder.add_sold_to company_name: 'Google Inc.',
    phone_number: '0207 031 3000',
    address_line_1: '389 Townsend Street',
    attention_name: 'John Doe',
    address_line_2: 'Apt 21',
    city: 'San Francisco',
    state: 'CA',
    postal_code: '94107',
    country: 'US'
  shipment_builder.add_package weight: '0.5',
    unit: 'KGS'
  shipment_builder.add_description 'White coffee mug'
  shipment_builder.add_payment_information 'ACCOUNT_NUMBER'
  shipment_builder.add_service '65' # returned in rates response
  shipment_builder.add_international_invoice invoice_number: '#P-1234',
    invoice_date: '20170816',
    reason_for_export: 'SALE',
    currency_code: 'USD',
    products: [
      {
        description: 'White coffee mug',
        number: '1',
        value: '14.02',
        dimensions_unit: 'CM',
        part_number: 'MUG-01-WHITE',
        commodity_code: '123488',
        origin_country_code: 'US'
      },
      {
        description: 'Red coffee mug',
        number: '1',
        value: '14.05',
        dimensions_unit: 'CM',
        part_number: 'MUG-01-RED',
        commodity_code: '567876',
        origin_country_code: 'US'
      }
    ]
end
# Then use...
response.success?
response.form_graphic_image
response.form_graphic_extension

Running the tests

After installing dependencies with bundle install, you can run the unit tests using rake.

Contributers

Thanks to the following contributers to this project.

  • CJ - Method to generate labels in available other formats [EPL, ZPL], Constant for packaging type.

ups-ruby's People

Contributors

721p avatar tehpeh avatar calvinhughes avatar chirag7jain avatar landonmarder avatar lefarmer avatar matt423 avatar

Watchers

Walter Mottinelli avatar James Cloos avatar

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.