Skip to content

Commit d239915

Browse files
ZarlengoToptalChris
andauthored
added order & pickup (#106)
* added order & pickup * version change * CircleCi Integration * Changelog update * Update date Co-authored-by: Chris <chris_eng@goshippo.com>
1 parent f9b2adf commit d239915

34 files changed

Lines changed: 479 additions & 10029 deletions

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2.1
2+
orbs:
3+
ruby: circleci/ruby@1.2.0
4+
5+
jobs:
6+
build:
7+
docker:
8+
- image: cimg/ruby:2.6.5-node
9+
steps:
10+
- checkout
11+
- run: gem install bundler
12+
- run: bundle install
13+
- run: rspec

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
example-shipment.json
1+
example-*.json
22
doc/
33
*.gem
44
*.rbc
@@ -13,6 +13,7 @@ lib/bundler/man
1313
pkg
1414
rdoc
1515
spec/reports
16+
spec/fixtures/*/*.yml
1617
test/tmp
1718
test/version_tmp
1819
tmp

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#### 4.1.0 release, Jan 18th, 2022
2+
- Added Orders
3+
- Added Pickups
4+
- Added CirclCi
5+
16
#### 4.0.0 release, Sep 5th, 2019
27
- [Allow multiple accounts in a single service/application](https://github.com/goshippo/shippo-ruby-client/pull/74)
38
- [Updated rest client depndency](https://github.com/goshippo/shippo-ruby-client/pull/91)

bin/address_validation_example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ begin
7070
address = ExampleHelper.log_operation 'Creating address... ' do
7171
Shippo::Address.create(address)
7272
end
73-
raise Shippo::Exceptions::UnsuccessfulResponseError.new(address.object.inspect) unless address.valid?
73+
raise Shippo::Exceptions::UnsuccessfulResponseError.new(address.object.inspect) unless address.is_complete?
7474
File.open('example-address.json', 'w') do |file|
7575
file.puts JSON.dump(address.to_hash)
7676
end

bin/basic_shipment_example

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require 'shippo/api/category'
2121
require 'shippo/exceptions/api_error'
2222
require 'awesome_print'
2323
require 'json'
24+
require 'date'
2425

2526
# Simple wrapper class to help us print objects to the STDOUT
2627
class ExampleHelper
@@ -65,7 +66,7 @@ address_from = {
6566

6667
# Create address_to object
6768
address_to = {
68-
:name => 'Mrs Hippo"',
69+
:name => 'Mrs Hippo',
6970
:company => 'San Diego Zoo',
7071
:street1 => '2920 Zoo Drive',
7172
:city => 'San Diego',
@@ -84,9 +85,10 @@ parcel = {
8485
:weight => 2,
8586
:mass_unit => :lb }
8687

87-
hash = { :address_from => address_from,
88+
hash = {
89+
:address_from => address_from,
8890
:address_to => address_to,
89-
:parcels => parcel,
91+
:parcels => [parcel],
9092
:async => false }
9193

9294
begin
@@ -122,7 +124,7 @@ ExampleHelper.dump_object(rate, 'First rate returned')
122124

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

bin/batch_example

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,37 +89,49 @@ address_to = {
8989
:email => 'hippo@goshippo.com' }
9090

9191
# Create parcel object
92-
parcel = {
92+
parcel1 = {
9393
:length => 5,
9494
:width => 2,
9595
:height => 5,
9696
:distance_unit => :in,
9797
:weight => 2,
9898
:mass_unit => :lb }
99+
parcel2 = {
100+
:length => 4,
101+
:width => 8,
102+
:height => 4,
103+
:distance_unit => :in,
104+
:weight => 6,
105+
:mass_unit => :lb }
106+
99107

100-
hash = { :default_carrier_account => DEFAULT_CARRIER_ACCOUNT,
101-
:default_servicelevel_token => 'usps_priority',
102-
:label_filetype => 'ZPLII',
103-
:metadata => 'BATCH #170',
104-
:batch_shipments => [
105-
{
106-
:shipment => {
107-
:address_from => address_from,
108-
:address_to => address_to,
109-
:parcel => parcel,
110-
:async => false
111-
}
112-
}
113-
]
114-
}
115-
116-
shipment_params = { :address_from => address_from,
117-
:address_to => address_to,
118-
:parcel => parcel,
119-
:async => false }
108+
shipment1 = { :address_from => address_from,
109+
:address_to => address_to,
110+
:parcels => [parcel1],
111+
:async => false }
112+
113+
shipment2 = { :address_from => address_from,
114+
:address_to => address_to,
115+
:parcels => [parcel2],
116+
:async => false }
120117

121118
begin
122-
batch = ExampleHelper.log_operation 'Making first API call to create a batch...' do
119+
shipment_1 = ExampleHelper.log_operation 'Making API call for shipment... ' do
120+
Shippo::Shipment.create(shipment1)
121+
end
122+
# **** NOTE: Known issue with TEST API KEY and BATCH, must create shipment first
123+
hash = { :default_carrier_account => DEFAULT_CARRIER_ACCOUNT,
124+
:default_servicelevel_token => 'usps_priority',
125+
:label_filetype => 'ZPLII',
126+
:metadata => 'BATCH #170',
127+
:batch_shipments => [
128+
{
129+
:shipment => shipment_1[:object_id]
130+
}
131+
]
132+
}
133+
134+
batch = ExampleHelper.log_operation 'Making API call to create a batch...' do
123135
Shippo::Batch.create(hash)
124136
end
125137

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

134-
shipment = ExampleHelper.log_operation 'Making API call to create a shipment... ' do
135-
Shippo::Shipment.create(shipment_params)
146+
shipment_2 = ExampleHelper.log_operation 'Making API call to create a shipment... ' do
147+
Shippo::Shipment.create(shipment2)
136148
end
137-
raise Shippo::Exceptions::UnsuccessfulResponseError.new(shipment.object.inspect) unless shipment.success?
149+
raise Shippo::Exceptions::UnsuccessfulResponseError.new(shipment_2.object.inspect) unless shipment_2.success?
138150
File.open('example-shipment.json', 'w') do |file|
139-
file.puts JSON.dump(shipment.to_hash)
151+
file.puts JSON.dump(shipment_2.to_hash)
140152
end
141153

142154
# Adding shipments
143155
shipments = Array.new
144-
shipments.push({"shipment" => shipment[:object_id]})
156+
shipments.push({"shipment" => shipment_2[:object_id]})
145157
added = ExampleHelper.log_operation 'Making API call to add a new shipment to batch...' do
146158
Shippo::Batch::add_shipment(retrieve[:object_id], shipments)
147159
end
148160
puts "Batch shipment count = #{added[:batch_shipments][:count]}"
149161
puts
150-
162+
151163
# Removing shipments
152164
shipments_to_remove = Array.new
153-
shipments_to_remove.push(added.batch_shipments.results[0][:object_id])
165+
shipments_to_remove.push(added.batch_shipments.results.last[:object_id])
154166
removed = ExampleHelper.log_operation 'Making API call to remove the new shipment from batch...' do
155167
Shippo::Batch::remove_shipment(retrieve[:object_id], shipments_to_remove)
156168
end

bin/config.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@
55

66
Hashie.logger = Logger.new(nil)
77

8-
Shippo::API.token = 'shippo_test_09e74f332aa839940e6c241bb008157c19428339'
9-
DEFAULT_CARRIER_ACCOUNT = '903074429eab4954b72df8a70defdfe3'
8+
Shippo::API.version = '2018-02-08'
9+
10+
if ENV["SHIPPO_TOKEN"]
11+
Shippo::API.token = ENV["SHIPPO_TOKEN"]
12+
else
13+
puts 'API Token is missing, run: export SHIPPO_TOKEN="<your token here>"'
14+
end
15+
if ENV["DEFAULT_CARRIER_ACCOUNT"]
16+
DEFAULT_CARRIER_ACCOUNT = ENV["DEFAULT_CARRIER_ACCOUNT"]
17+
else
18+
puts 'Default Carrier is missing, run: export DEFAULT_CARRIER_ACCOUNT="<your usps account object id>"'
19+
end

0 commit comments

Comments
 (0)