Skip to content

Commit

Permalink
added order & pickup (#106)
Browse files Browse the repository at this point in the history
* added order & pickup

* version change

* CircleCi Integration

* Changelog update

* Update date

Co-authored-by: Chris <[email protected]>
  • Loading branch information
ZarlengoToptal and Chris authored Jan 19, 2022
1 parent f9b2adf commit d239915
Show file tree
Hide file tree
Showing 34 changed files with 479 additions and 10,029 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2.1
orbs:
ruby: circleci/[email protected]

jobs:
build:
docker:
- image: cimg/ruby:2.6.5-node
steps:
- checkout
- run: gem install bundler
- run: bundle install
- run: rspec
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
example-shipment.json
example-*.json
doc/
*.gem
*.rbc
Expand All @@ -13,6 +13,7 @@ lib/bundler/man
pkg
rdoc
spec/reports
spec/fixtures/*/*.yml
test/tmp
test/version_tmp
tmp
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### 4.1.0 release, Jan 18th, 2022
- Added Orders
- Added Pickups
- Added CirclCi

#### 4.0.0 release, Sep 5th, 2019
- [Allow multiple accounts in a single service/application](https://github.com/goshippo/shippo-ruby-client/pull/74)
- [Updated rest client depndency](https://github.com/goshippo/shippo-ruby-client/pull/91)
Expand Down
2 changes: 1 addition & 1 deletion bin/address_validation_example
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ begin
address = ExampleHelper.log_operation 'Creating address... ' do
Shippo::Address.create(address)
end
raise Shippo::Exceptions::UnsuccessfulResponseError.new(address.object.inspect) unless address.valid?
raise Shippo::Exceptions::UnsuccessfulResponseError.new(address.object.inspect) unless address.is_complete?
File.open('example-address.json', 'w') do |file|
file.puts JSON.dump(address.to_hash)
end
Expand Down
10 changes: 6 additions & 4 deletions bin/basic_shipment_example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require 'shippo/api/category'
require 'shippo/exceptions/api_error'
require 'awesome_print'
require 'json'
require 'date'

# Simple wrapper class to help us print objects to the STDOUT
class ExampleHelper
Expand Down Expand Up @@ -65,7 +66,7 @@ address_from = {

# Create address_to object
address_to = {
:name => 'Mrs Hippo"',
:name => 'Mrs Hippo',
:company => 'San Diego Zoo',
:street1 => '2920 Zoo Drive',
:city => 'San Diego',
Expand All @@ -84,9 +85,10 @@ parcel = {
:weight => 2,
:mass_unit => :lb }

hash = { :address_from => address_from,
hash = {
:address_from => address_from,
:address_to => address_to,
:parcels => parcel,
:parcels => [parcel],
:async => false }

begin
Expand Down Expand Up @@ -122,7 +124,7 @@ ExampleHelper.dump_object(rate, 'First rate returned')

transaction = ExampleHelper.log_operation 'Creating a label with the first rate in the list... ' do
# Purchase the desired rate (create a Transaction object)
Shippo::Transaction.create(rate: rate.id, async: false)
Shippo::Transaction.create({rate: rate[:object_id], async: false})
end
ExampleHelper.dump_object(transaction, 'Transaction object received')

Expand Down
70 changes: 41 additions & 29 deletions bin/batch_example
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,49 @@ address_to = {
:email => '[email protected]' }

# Create parcel object
parcel = {
parcel1 = {
:length => 5,
:width => 2,
:height => 5,
:distance_unit => :in,
:weight => 2,
:mass_unit => :lb }
parcel2 = {
:length => 4,
:width => 8,
:height => 4,
:distance_unit => :in,
:weight => 6,
:mass_unit => :lb }


hash = { :default_carrier_account => DEFAULT_CARRIER_ACCOUNT,
:default_servicelevel_token => 'usps_priority',
:label_filetype => 'ZPLII',
:metadata => 'BATCH #170',
:batch_shipments => [
{
:shipment => {
:address_from => address_from,
:address_to => address_to,
:parcel => parcel,
:async => false
}
}
]
}

shipment_params = { :address_from => address_from,
:address_to => address_to,
:parcel => parcel,
:async => false }
shipment1 = { :address_from => address_from,
:address_to => address_to,
:parcels => [parcel1],
:async => false }

shipment2 = { :address_from => address_from,
:address_to => address_to,
:parcels => [parcel2],
:async => false }

begin
batch = ExampleHelper.log_operation 'Making first API call to create a batch...' do
shipment_1 = ExampleHelper.log_operation 'Making API call for shipment... ' do
Shippo::Shipment.create(shipment1)
end
# **** NOTE: Known issue with TEST API KEY and BATCH, must create shipment first
hash = { :default_carrier_account => DEFAULT_CARRIER_ACCOUNT,
:default_servicelevel_token => 'usps_priority',
:label_filetype => 'ZPLII',
:metadata => 'BATCH #170',
:batch_shipments => [
{
:shipment => shipment_1[:object_id]
}
]
}

batch = ExampleHelper.log_operation 'Making API call to create a batch...' do
Shippo::Batch.create(hash)
end

Expand All @@ -131,26 +143,26 @@ begin
puts "Batch shipment count = #{retrieve[:batch_shipments][:count]}"
puts

shipment = ExampleHelper.log_operation 'Making API call to create a shipment... ' do
Shippo::Shipment.create(shipment_params)
shipment_2 = ExampleHelper.log_operation 'Making API call to create a shipment... ' do
Shippo::Shipment.create(shipment2)
end
raise Shippo::Exceptions::UnsuccessfulResponseError.new(shipment.object.inspect) unless shipment.success?
raise Shippo::Exceptions::UnsuccessfulResponseError.new(shipment_2.object.inspect) unless shipment_2.success?
File.open('example-shipment.json', 'w') do |file|
file.puts JSON.dump(shipment.to_hash)
file.puts JSON.dump(shipment_2.to_hash)
end

# Adding shipments
shipments = Array.new
shipments.push({"shipment" => shipment[:object_id]})
shipments.push({"shipment" => shipment_2[:object_id]})
added = ExampleHelper.log_operation 'Making API call to add a new shipment to batch...' do
Shippo::Batch::add_shipment(retrieve[:object_id], shipments)
end
puts "Batch shipment count = #{added[:batch_shipments][:count]}"
puts

# Removing shipments
shipments_to_remove = Array.new
shipments_to_remove.push(added.batch_shipments.results[0][:object_id])
shipments_to_remove.push(added.batch_shipments.results.last[:object_id])
removed = ExampleHelper.log_operation 'Making API call to remove the new shipment from batch...' do
Shippo::Batch::remove_shipment(retrieve[:object_id], shipments_to_remove)
end
Expand Down
14 changes: 12 additions & 2 deletions bin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@

Hashie.logger = Logger.new(nil)

Shippo::API.token = 'shippo_test_09e74f332aa839940e6c241bb008157c19428339'
DEFAULT_CARRIER_ACCOUNT = '903074429eab4954b72df8a70defdfe3'
Shippo::API.version = '2018-02-08'

if ENV["SHIPPO_TOKEN"]
Shippo::API.token = ENV["SHIPPO_TOKEN"]
else
puts 'API Token is missing, run: export SHIPPO_TOKEN="<your token here>"'
end
if ENV["DEFAULT_CARRIER_ACCOUNT"]
DEFAULT_CARRIER_ACCOUNT = ENV["DEFAULT_CARRIER_ACCOUNT"]
else
puts 'Default Carrier is missing, run: export DEFAULT_CARRIER_ACCOUNT="<your usps account object id>"'
end
Loading

0 comments on commit d239915

Please sign in to comment.