easypost 2.0.15 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +13 -5
- data/.gitignore +1 -2
- data/CHANGELOG +0 -17
- data/README.md +0 -3
- data/VERSION +1 -1
- data/lib/easypost.rb +1 -4
- data/lib/easypost/address.rb +3 -10
- data/lib/easypost/object.rb +2 -2
- data/lib/easypost/util.rb +2 -6
- data/spec/address_spec.rb +7 -7
- data/spec/batch_spec.rb +33 -20
- data/spec/container_spec.rb +11 -0
- data/spec/fedex/domestic_spec.rb +180 -0
- data/spec/fedex/international_spec.rb +64 -0
- data/spec/order_spec.rb +70 -2
- data/spec/pickup_spec.rb +14 -13
- data/spec/shipment_spec.rb +23 -38
- data/spec/spec_helper.rb +92 -6
- data/spec/ups/domestic_spec.rb +79 -0
- data/spec/ups/international_spec.rb +64 -0
- data/spec/usps/domestic_spec.rb +66 -0
- data/spec/usps/electronic_merchandise_returns.rb +94 -0
- data/spec/usps/merchant_returns.rb +0 -0
- metadata +31 -27
- data/lib/easypost/carrier_account.rb +0 -21
- data/lib/easypost/user.rb +0 -42
- data/spec/carrier_account_spec.rb +0 -83
- data/spec/support/constant.rb +0 -87
- data/spec/tracker_spec.rb +0 -20
- data/spec/user_spec.rb +0 -72
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,15 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
             | 
| 2 | 
            +
            !binary "U0hBMQ==":
         | 
| 3 | 
            +
              metadata.gz: !binary |-
         | 
| 4 | 
            +
                ZDRiZmUzZDYxMmEzNmNlNWRhNjMxNzZkYjdhMzQ4MGZjZTMxOTM5Mw==
         | 
| 5 | 
            +
              data.tar.gz: !binary |-
         | 
| 6 | 
            +
                ZTcxNzNjN2ZhMzYxODA3NmFhMGY5NzQ4NTg2ZTk5NmNjOTAwODI5ZA==
         | 
| 5 7 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
             | 
| 8 | 
            +
              metadata.gz: !binary |-
         | 
| 9 | 
            +
                MzlmYzQ1YjZkMjQ0YWMzYTVjMzU5ZDI4NzJhYzAzODcxYmQ0MDBiMDVjYTAw
         | 
| 10 | 
            +
                OTQ2NjE0YjQwMzcyZmY4ZTkyMzcwYjMxODBjM2I3Y2ZhMmQ0NzAzMThhOWNm
         | 
| 11 | 
            +
                OTEzYjVkNzMzNmFmZTMyNmMyODBjNjJiYzRkZmM3N2Q0NDcxNjU=
         | 
| 12 | 
            +
              data.tar.gz: !binary |-
         | 
| 13 | 
            +
                NjNlMmY0ZmI5MDdjNWI1ODM0MDBkZTBhMjQ0OTk3NDhkMjIxNTNlMTZhOWQ0
         | 
| 14 | 
            +
                OGVlYjVlYjRkMjhkMThiMDZlMmRhZmM4NTIxMWJmMWI4NTc1ODRmMDNjMzk1
         | 
| 15 | 
            +
                ODExMzE1MmE0OWMxOTY4ZWRmMTg3YThiOWE4NGE2NWY1Mzk5ZGU=
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/CHANGELOG
    CHANGED
    
    | @@ -1,20 +1,3 @@ | |
| 1 | 
            -
            === 2.0.15 2015-04-15
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            * Added tracker to shipment buy response
         | 
| 4 | 
            -
            * Updated tracker tests
         | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
            === 2.0.14 2015-04-15
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            * Added User and CarrierAccount models with CRUD functionality
         | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
            === 2.0.13 2014-10-30
         | 
| 13 | 
            -
             | 
| 14 | 
            -
            * Added Pickup, PickupRate resources.
         | 
| 15 | 
            -
            * Added ability to pass api_key to a few resources that were missing it.
         | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 1 | 
             
            === 2.0.12 2014-07-07
         | 
| 19 2 |  | 
| 20 3 | 
             
            * Added Item, Container, and Order resources.
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,5 @@ | |
| 1 1 | 
             
            # EasyPost Ruby Client Library
         | 
| 2 2 |  | 
| 3 | 
            -
            [<img src="https://circleci.com/gh/EasyPost/easypost-ruby.png?circle-token=80adb5236ed1fdce20810b055af79c63c3d5796b">](https://circleci.com/gh/EasyPost/easypost-ruby)
         | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 3 | 
             
            EasyPost is a simple shipping API. You can sign up for an account at https://easypost.com
         | 
| 7 4 |  | 
| 8 5 | 
             
            Installation
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            2.0 | 
| 1 | 
            +
            2.1.0
         | 
    
        data/lib/easypost.rb
    CHANGED
    
    | @@ -26,8 +26,6 @@ require 'easypost/container' | |
| 26 26 | 
             
            require 'easypost/order'
         | 
| 27 27 | 
             
            require 'easypost/pickup'
         | 
| 28 28 | 
             
            require 'easypost/pickup_rate'
         | 
| 29 | 
            -
            require 'easypost/carrier_account'
         | 
| 30 | 
            -
            require 'easypost/user'
         | 
| 31 29 |  | 
| 32 30 | 
             
            require 'easypost/error'
         | 
| 33 31 |  | 
| @@ -70,8 +68,7 @@ module EasyPost | |
| 70 68 | 
             
                @@http_config ||= {
         | 
| 71 69 | 
             
                  timeout: 60,
         | 
| 72 70 | 
             
                  open_timeout: 30,
         | 
| 73 | 
            -
                  verify_ssl: false | 
| 74 | 
            -
                  ssl_version: "TLSv1",
         | 
| 71 | 
            +
                  verify_ssl: false
         | 
| 75 72 | 
             
                }
         | 
| 76 73 | 
             
              end
         | 
| 77 74 |  | 
    
        data/lib/easypost/address.rb
    CHANGED
    
    | @@ -14,16 +14,12 @@ module EasyPost | |
| 14 14 | 
             
                    verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
         | 
| 15 15 | 
             
                    return verified_address
         | 
| 16 16 | 
             
                  else
         | 
| 17 | 
            -
                     | 
| 17 | 
            +
                    raise Error.new("Unable to verify address.")
         | 
| 18 18 | 
             
                  end
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                def verify(params={}, carrier=nil)
         | 
| 22 | 
            -
                   | 
| 23 | 
            -
                    response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
         | 
| 24 | 
            -
                  rescue
         | 
| 25 | 
            -
                    raise_verification_failure
         | 
| 26 | 
            -
                  end
         | 
| 22 | 
            +
                  response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
         | 
| 27 23 |  | 
| 28 24 | 
             
                  if response.has_key?(:address)
         | 
| 29 25 | 
             
                    if response.has_key?(:message)
         | 
| @@ -32,14 +28,11 @@ module EasyPost | |
| 32 28 | 
             
                    verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
         | 
| 33 29 | 
             
                    return verified_address
         | 
| 34 30 | 
             
                  else
         | 
| 35 | 
            -
                     | 
| 31 | 
            +
                    raise Error.new("Unable to verify address.")
         | 
| 36 32 | 
             
                  end
         | 
| 37 33 |  | 
| 38 34 | 
             
                  return self
         | 
| 39 35 | 
             
                end
         | 
| 40 36 |  | 
| 41 | 
            -
                def raise_verification_failure
         | 
| 42 | 
            -
                  raise Error.new("Unable to verify address.")
         | 
| 43 | 
            -
                end
         | 
| 44 37 | 
             
              end
         | 
| 45 38 | 
             
            end
         | 
    
        data/lib/easypost/object.rb
    CHANGED
    
    | @@ -32,11 +32,11 @@ module EasyPost | |
| 32 32 | 
             
                  @api_key = api_key
         | 
| 33 33 |  | 
| 34 34 | 
             
                  added = Set.new(values.keys - @values.keys)
         | 
| 35 | 
            -
             | 
| 35 | 
            +
                  
         | 
| 36 36 | 
             
                  instance_eval do
         | 
| 37 37 | 
             
                    add_accessors(added)
         | 
| 38 38 | 
             
                  end
         | 
| 39 | 
            -
             | 
| 39 | 
            +
                  
         | 
| 40 40 | 
             
                  values.each do |k, v|
         | 
| 41 41 | 
             
                    @values[k] = Util.convert_to_easypost_object(v, api_key)
         | 
| 42 42 | 
             
                    @transient_values.delete(k)
         | 
    
        data/lib/easypost/util.rb
    CHANGED
    
    | @@ -32,9 +32,7 @@ module EasyPost | |
| 32 32 | 
             
                    'Order' => Order,
         | 
| 33 33 | 
             
                    'Pickup' => Pickup,
         | 
| 34 34 | 
             
                    'PickupRate' => PickupRate,
         | 
| 35 | 
            -
                    'PostageLabel' => PostageLabel | 
| 36 | 
            -
                    'CarrierAccount' => CarrierAccount,
         | 
| 37 | 
            -
                    'User' => User }
         | 
| 35 | 
            +
                    'PostageLabel' => PostageLabel }
         | 
| 38 36 |  | 
| 39 37 | 
             
                  prefixes = { 'adr' => Address,
         | 
| 40 38 | 
             
                    'sf' => ScanForm,
         | 
| @@ -52,9 +50,7 @@ module EasyPost | |
| 52 50 | 
             
                    'order' => Order,
         | 
| 53 51 | 
             
                    'pickup' => Pickup,
         | 
| 54 52 | 
             
                    'pickuprate' => PickupRate,
         | 
| 55 | 
            -
                    'pl' => PostageLabel | 
| 56 | 
            -
                    'ca' => CarrierAccount,
         | 
| 57 | 
            -
                    'user' => User }
         | 
| 53 | 
            +
                    'pl' => PostageLabel }
         | 
| 58 54 |  | 
| 59 55 | 
             
                  case response
         | 
| 60 56 | 
             
                  when Array
         | 
    
        data/spec/address_spec.rb
    CHANGED
    
    | @@ -55,15 +55,15 @@ describe EasyPost::Address do | |
| 55 55 |  | 
| 56 56 | 
             
                it 'is not able to verify address' do
         | 
| 57 57 | 
             
                  address = EasyPost::Address.create(
         | 
| 58 | 
            -
                    company | 
| 59 | 
            -
                    street1 | 
| 60 | 
            -
                    street2 | 
| 61 | 
            -
                    city | 
| 62 | 
            -
                    state | 
| 63 | 
            -
                    zip | 
| 58 | 
            +
                    :company => 'Simpler Postage Inc',
         | 
| 59 | 
            +
                    :street1 => '388 Junk Teerts',
         | 
| 60 | 
            +
                    :street2 => 'Apt 20',
         | 
| 61 | 
            +
                    :city    => 'San Francisco',
         | 
| 62 | 
            +
                    :state   => 'CA',
         | 
| 63 | 
            +
                    :zip     => '941abc07'
         | 
| 64 64 | 
             
                  )
         | 
| 65 65 |  | 
| 66 | 
            -
                  expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Unable to verify  | 
| 66 | 
            +
                  expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Unable to verify address./)
         | 
| 67 67 | 
             
                end
         | 
| 68 68 | 
             
              end
         | 
| 69 69 | 
             
            end
         | 
    
        data/spec/batch_spec.rb
    CHANGED
    
    | @@ -1,48 +1,61 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe EasyPost::Batch do
         | 
| 4 | 
            +
             | 
| 4 5 | 
             
              describe '#create' do
         | 
| 5 6 | 
             
                it 'creates a batch object' do
         | 
| 6 7 | 
             
                  batch = EasyPost::Batch.create({
         | 
| 7 | 
            -
                    shipment | 
| 8 | 
            -
                      from_address | 
| 9 | 
            -
                      to_address | 
| 10 | 
            -
                      parcel | 
| 8 | 
            +
                    :shipment => [{
         | 
| 9 | 
            +
                      :from_address => ADDRESS[:california],
         | 
| 10 | 
            +
                      :to_address   => ADDRESS[:missouri],
         | 
| 11 | 
            +
                      :parcel       => PARCEL[:dimensions]
         | 
| 11 12 | 
             
                    }, {
         | 
| 12 | 
            -
                      from_address | 
| 13 | 
            -
                      to_address | 
| 14 | 
            -
                      parcel | 
| 13 | 
            +
                      :from_address => ADDRESS[:california],
         | 
| 14 | 
            +
                      :to_address   => ADDRESS[:canada],
         | 
| 15 | 
            +
                      :parcel       => PARCEL[:dimensions],
         | 
| 15 16 | 
             
                    }],
         | 
| 16 | 
            -
                    reference | 
| 17 | 
            +
                    :reference => "batch123456789"
         | 
| 17 18 | 
             
                  })
         | 
| 18 19 | 
             
                  expect(batch).to be_an_instance_of(EasyPost::Batch)
         | 
| 19 20 | 
             
                  expect(batch.num_shipments).to eq(2)
         | 
| 20 21 | 
             
                  expect(batch.reference).to eq("batch123456789")
         | 
| 21 22 | 
             
                  expect(batch.state).to eq("creating")
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  # sleeps_left = 10
         | 
| 25 | 
            +
                  # while (batch.state == "creating" && sleeps_left > 0) do
         | 
| 26 | 
            +
                  #   sleep(3)
         | 
| 27 | 
            +
                  #   batch.refresh
         | 
| 28 | 
            +
                  #   sleeps_left -= 1
         | 
| 29 | 
            +
                  # end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  # expect(batch.state).to equal("created")
         | 
| 32 | 
            +
                  # expect(batch.status[:created]).to equal(2)
         | 
| 33 | 
            +
             | 
| 22 34 | 
             
                end
         | 
| 23 35 | 
             
              end
         | 
| 24 36 |  | 
| 25 37 | 
             
              describe '#create_and_buy' do
         | 
| 26 38 | 
             
                it 'creates a batch object and delayed jobs for purchasing the postage_labels' do
         | 
| 27 39 | 
             
                  batch = EasyPost::Batch.create({
         | 
| 28 | 
            -
                    shipment | 
| 29 | 
            -
                      from_address | 
| 30 | 
            -
                      to_address | 
| 31 | 
            -
                      parcel | 
| 32 | 
            -
                      carrier | 
| 33 | 
            -
                      service | 
| 40 | 
            +
                    :shipment => [{
         | 
| 41 | 
            +
                      :from_address => ADDRESS[:california],
         | 
| 42 | 
            +
                      :to_address   => ADDRESS[:missouri],
         | 
| 43 | 
            +
                      :parcel       => PARCEL[:dimensions],
         | 
| 44 | 
            +
                      :carrier      => "usps",
         | 
| 45 | 
            +
                      :service      => "priority"
         | 
| 34 46 | 
             
                    }, {
         | 
| 35 | 
            -
                      from_address | 
| 36 | 
            -
                      to_address | 
| 37 | 
            -
                      parcel | 
| 38 | 
            -
                      carrier | 
| 39 | 
            -
                      service | 
| 47 | 
            +
                      :from_address => ADDRESS[:california],
         | 
| 48 | 
            +
                      :to_address   => ADDRESS[:canada],
         | 
| 49 | 
            +
                      :parcel       => PARCEL[:dimensions],
         | 
| 50 | 
            +
                      :carrier      => "usps",
         | 
| 51 | 
            +
                      :service      => "prioritymailinternational"
         | 
| 40 52 | 
             
                    }],
         | 
| 41 | 
            -
                    reference | 
| 53 | 
            +
                    :reference => "batch123456789"
         | 
| 42 54 | 
             
                  })
         | 
| 43 55 | 
             
                  expect(batch).to be_an_instance_of(EasyPost::Batch)
         | 
| 44 56 | 
             
                  expect(batch.state).to eq("creating")
         | 
| 45 57 | 
             
                  expect(batch.num_shipments).to eq(2)
         | 
| 46 58 | 
             
                end
         | 
| 47 59 | 
             
              end
         | 
| 60 | 
            +
             | 
| 48 61 | 
             
            end
         | 
    
        data/spec/container_spec.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe EasyPost::Container do
         | 
| 4 | 
            +
             | 
| 4 5 | 
             
              describe '#create' do
         | 
| 5 6 | 
             
                it 'creates a container object' do
         | 
| 6 7 | 
             
                  container = EasyPost::Container.create(
         | 
| @@ -72,5 +73,15 @@ describe EasyPost::Container do | |
| 72 73 | 
             
                  expect(container_2.height).to eq(container_1.height)
         | 
| 73 74 | 
             
                  expect(container_1.type).to eq("BOX")
         | 
| 74 75 | 
             
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                it 'retrieves global containers' do
         | 
| 78 | 
            +
                  container_1 = EasyPost::Container.retrieve("container_USPSFR03")
         | 
| 79 | 
            +
                  container_2 = EasyPost::Container.retrieve("container_USPSFR02")
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  expect(container_1).to be_an_instance_of(EasyPost::Container)
         | 
| 82 | 
            +
                  expect(container_2).to be_an_instance_of(EasyPost::Container)
         | 
| 83 | 
            +
                  expect(container_1.reference).to eq(container_2.reference)
         | 
| 84 | 
            +
                end
         | 
| 75 85 | 
             
              end
         | 
| 86 | 
            +
             | 
| 76 87 | 
             
            end
         | 
| @@ -0,0 +1,180 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe 'fedex domestic' do
         | 
| 4 | 
            +
              before(:all) do
         | 
| 5 | 
            +
                @rates = {}
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              it 'buys a commercial ground label' do
         | 
| 9 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 10 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 11 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 12 | 
            +
                  :parcel       => PARCEL[:dimensions]
         | 
| 13 | 
            +
                )
         | 
| 14 | 
            +
                shipment.buy(:rate => shipment.lowest_rate("fedex", "FEDEX_GROUND"))
         | 
| 15 | 
            +
                label = open(shipment.postage_label.label_url)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                expect(shipment).to be_an_instance_of(EasyPost::Shipment)
         | 
| 18 | 
            +
                expect(shipment.selected_rate).to be_an_instance_of(EasyPost::Rate)
         | 
| 19 | 
            +
                expect(shipment.selected_rate.service).to eq("FEDEX_GROUND")
         | 
| 20 | 
            +
                expect(shipment.postage_label.label_url).to end_with(".png")
         | 
| 21 | 
            +
                expect(shipment.tracking_code).to start_with("8000")
         | 
| 22 | 
            +
                expect(label.size).to be > 5000
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                @rates[:commercial] = shipment.selected_rate
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
               it 'buys a residential ground label' do
         | 
| 28 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 29 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 30 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 31 | 
            +
                  :parcel       => PARCEL[:dimensions],
         | 
| 32 | 
            +
                  :options      => {:residential_to_address => true}
         | 
| 33 | 
            +
                )
         | 
| 34 | 
            +
                shipment.buy(:rate => shipment.lowest_rate("fedex", "GROUND_HOME_DELIVERY"))
         | 
| 35 | 
            +
                label = open(shipment.postage_label.label_url)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                expect(shipment.selected_rate.service).to eq("GROUND_HOME_DELIVERY")
         | 
| 38 | 
            +
                expect(shipment.tracking_code).to start_with("8000")
         | 
| 39 | 
            +
                expect(label.size).to be > 5000
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                @rates[:residential] = shipment.selected_rate
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              it 'buys a ground evening delivery label' do
         | 
| 45 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 46 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 47 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 48 | 
            +
                  :parcel       => PARCEL[:dimensions],
         | 
| 49 | 
            +
                  :options      => {:residential_to_address => true,
         | 
| 50 | 
            +
                                    :delivery_time_preference => "evening"}
         | 
| 51 | 
            +
                )
         | 
| 52 | 
            +
                shipment.buy(:rate => shipment.lowest_rate("fedex", "GROUND_HOME_DELIVERY"))
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                expect(shipment.postage_label.label_url).to end_with(".png")
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                @rates[:residential_evening] = shipment.selected_rate
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
              it 'raises error without recipient phone number' do
         | 
| 60 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 61 | 
            +
                  :to_address   => ADDRESS[:california_no_phone],
         | 
| 62 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 63 | 
            +
                  :parcel       => PARCEL[:dimensions]
         | 
| 64 | 
            +
                )
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                expect { shipment.buy(rate: shipment.lowest_rate("fedex")) }.to raise_error(EasyPost::Error, /Unable to buy FedEx shipment without recipient phone number./)
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
              it 'buys a label for an alcoholic shipment with epl2 label' do
         | 
| 70 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 71 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 72 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 73 | 
            +
                  :parcel       => PARCEL[:dimensions],
         | 
| 74 | 
            +
                  :options      => {
         | 
| 75 | 
            +
                    :alcohol      => 1,
         | 
| 76 | 
            +
                    :label_format => "epl2"
         | 
| 77 | 
            +
                  }
         | 
| 78 | 
            +
                )
         | 
| 79 | 
            +
                shipment.buy(:rate => shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT"))
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                expect(shipment.postage_label.label_url).to end_with(".epl2")
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
              it 'buys a label for a ground cod shipment' do
         | 
| 85 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 86 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 87 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 88 | 
            +
                  :parcel       => PARCEL[:dimensions]
         | 
| 89 | 
            +
                )
         | 
| 90 | 
            +
                shipment_cod = EasyPost::Shipment.create(
         | 
| 91 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 92 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 93 | 
            +
                  :parcel       => PARCEL[:dimensions],
         | 
| 94 | 
            +
                  :options      => {cod_amount: 19.99}
         | 
| 95 | 
            +
                )
         | 
| 96 | 
            +
                shipment_cod.buy(rate: shipment_cod.lowest_rate("fedex", "FEDEX_GROUND"))
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                expect(shipment.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f)
         | 
| 99 | 
            +
                expect(shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f)
         | 
| 100 | 
            +
                expect(shipment_cod.postage_label.label_url).to be
         | 
| 101 | 
            +
              end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
              it 'buys a label for a ground multi-parcel cod shipment' do
         | 
| 104 | 
            +
                order = EasyPost::Order.create(
         | 
| 105 | 
            +
                  to_address: ADDRESS[:california],
         | 
| 106 | 
            +
                  from_address: ADDRESS[:missouri],
         | 
| 107 | 
            +
                  shipments: [{
         | 
| 108 | 
            +
                    parcel: {length: 8, width: 6, height: 4, weight: 12},
         | 
| 109 | 
            +
                    options: {cod_amount: 14.99}
         | 
| 110 | 
            +
                  },{
         | 
| 111 | 
            +
                    parcel: {length: 8, width: 6, height: 4, weight: 12},
         | 
| 112 | 
            +
                    options: {cod_amount: 18.75}
         | 
| 113 | 
            +
                  }]
         | 
| 114 | 
            +
                )
         | 
| 115 | 
            +
                order.buy(carrier: "fedex", service: "FEDEX_GROUND")
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                expect(order).to be_an_instance_of(EasyPost::Order)
         | 
| 118 | 
            +
                expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
         | 
| 119 | 
            +
                expect(order.shipments[0].postage_label.label_url).to be
         | 
| 120 | 
            +
                expect(order.shipments[1].postage_label.label_url).to be
         | 
| 121 | 
            +
              end
         | 
| 122 | 
            +
             | 
| 123 | 
            +
              it 'buys a label for an express cod shipment' do
         | 
| 124 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 125 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 126 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 127 | 
            +
                  :parcel       => PARCEL[:dimensions]
         | 
| 128 | 
            +
                )
         | 
| 129 | 
            +
                shipment_cod = EasyPost::Shipment.create(
         | 
| 130 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 131 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 132 | 
            +
                  :parcel       => PARCEL[:dimensions],
         | 
| 133 | 
            +
                  :options      => {cod_amount: 19.99}
         | 
| 134 | 
            +
                )
         | 
| 135 | 
            +
                shipment_cod.buy(rate: shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT"))
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                expect(shipment.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f)
         | 
| 138 | 
            +
                expect(shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f)
         | 
| 139 | 
            +
                expect(shipment_cod.postage_label.label_url).to be
         | 
| 140 | 
            +
              end
         | 
| 141 | 
            +
             | 
| 142 | 
            +
              it 'buys a label for an express multi-parcel cod shipment' do
         | 
| 143 | 
            +
                order = EasyPost::Order.create(
         | 
| 144 | 
            +
                  to_address: ADDRESS[:california],
         | 
| 145 | 
            +
                  from_address: ADDRESS[:missouri],
         | 
| 146 | 
            +
                  shipments: [{
         | 
| 147 | 
            +
                    parcel: {length: 8, width: 6, height: 4, weight: 12},
         | 
| 148 | 
            +
                    options: {cod_amount: 14.99}
         | 
| 149 | 
            +
                  },{
         | 
| 150 | 
            +
                    parcel: {length: 8, width: 6, height: 4, weight: 12},
         | 
| 151 | 
            +
                    options: {cod_amount: 18.75}
         | 
| 152 | 
            +
                  }]
         | 
| 153 | 
            +
                )
         | 
| 154 | 
            +
                order.buy(carrier: "fedex", service: "PRIORITY_OVERNIGHT")
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                expect(order).to be_an_instance_of(EasyPost::Order)
         | 
| 157 | 
            +
                expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
         | 
| 158 | 
            +
                expect(order.shipments[0].postage_label.label_url).to be
         | 
| 159 | 
            +
                expect(order.shipments[1].postage_label.label_url).to be
         | 
| 160 | 
            +
              end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
              it 'buys a label using a thid party account number' do
         | 
| 163 | 
            +
                shipment = EasyPost::Shipment.create(
         | 
| 164 | 
            +
                  :to_address   => ADDRESS[:california],
         | 
| 165 | 
            +
                  :from_address => ADDRESS[:missouri],
         | 
| 166 | 
            +
                  :parcel       => PARCEL[:dimensions],
         | 
| 167 | 
            +
                  :options      => {:bill_third_party_account => "12345678"}
         | 
| 168 | 
            +
                )
         | 
| 169 | 
            +
                expect { shipment.buy(rate: shipment.lowest_rate("fedex")) }.to raise_error(EasyPost::Error, /ShippingChargesPayment Payor - The payor's account number is invalid/)
         | 
| 170 | 
            +
              end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
              after(:all) do
         | 
| 173 | 
            +
                begin
         | 
| 174 | 
            +
                  expect(@rates[:residential_evening].rate.to_i).to be > @rates[:residential].rate.to_i
         | 
| 175 | 
            +
                  expect(@rates[:residential].rate.to_i).to be > @rates[:commercial].rate.to_i
         | 
| 176 | 
            +
                rescue
         | 
| 177 | 
            +
                end
         | 
| 178 | 
            +
              end
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            end
         |