shippo 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example.rb +25 -71
- data/lib/shippo/carrieraccount.rb +8 -0
- data/lib/shippo/update.rb +15 -0
- data/lib/shippo.rb +15 -8
- metadata +31 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c1afc5735ee9f3e356aaa45c48461d337518999
|
4
|
+
data.tar.gz: 5780d7dac4a8884eded0dd5431ea30ca2fcdd222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8143b0403147d512fb677178f6cab943094238313cea9155ccc489329d1fea6e04c5844f48f9107cdc0500bee9bf50a256c479c1c151167316676229f2e8fdd0
|
7
|
+
data.tar.gz: 989b5c42d4d68739e539bf315f0f8992a5628f989c4181420a2b45134bcbe9508f2c70f1e25d5892222704fe62f7686fb601895f43b124fd8de9a04d75a4129b
|
data/example.rb
CHANGED
@@ -1,110 +1,64 @@
|
|
1
|
-
# This example demonstrates how to purchase a label for
|
2
|
-
# Creating domestic shipment would follow a similiar proccess but would not require
|
3
|
-
# the creation of CustomsItems and CustomsDeclaration objects.
|
1
|
+
# This example demonstrates how to purchase a label for a domestic US shipment.
|
4
2
|
require 'shippo'
|
5
|
-
require 'timeout'
|
6
3
|
|
7
|
-
# replace <
|
8
|
-
Shippo::api_token = '
|
4
|
+
# replace <YOUR_PRIVATE_KEY> with your ShippoToken key
|
5
|
+
Shippo::api_token = '<YOUR_PRIVATE_KEY>'
|
9
6
|
|
10
7
|
# Create address_from object
|
11
8
|
address_from = {
|
12
9
|
:object_purpose => 'PURCHASE',
|
13
|
-
:name => '
|
10
|
+
:name => 'Mr Hippo',
|
14
11
|
:company => 'Shippo',
|
15
|
-
:street1 => 'Clayton St.',
|
16
|
-
:street_no => '215',
|
12
|
+
:street1 => '215 Clayton St.',
|
17
13
|
:street2 => '',
|
18
14
|
:city => 'San Francisco',
|
19
15
|
:state => 'CA',
|
20
16
|
:zip => '94117',
|
21
17
|
:country => 'US',
|
22
18
|
:phone => '+1 555 341 9393',
|
23
|
-
:email => '
|
19
|
+
:email => 'support@goshippo.com'}
|
24
20
|
|
25
21
|
# Create address_to object
|
26
22
|
address_to = {
|
27
23
|
:object_purpose => 'PURCHASE',
|
28
|
-
:name => '
|
29
|
-
:company => '
|
30
|
-
:street1 => '
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:country => 'GB',
|
24
|
+
:name => 'Mrs Hippo"',
|
25
|
+
:company => 'San Diego Zoo',
|
26
|
+
:street1 => '2920 Zoo Drive',
|
27
|
+
:city => 'San Diego',
|
28
|
+
:state => 'CA',
|
29
|
+
:zip => '92101',
|
30
|
+
:country => 'US',
|
36
31
|
:phone => '+1 555 341 9393',
|
37
|
-
:email => '
|
32
|
+
:email => 'hippo@goshippo.com'}
|
38
33
|
|
39
34
|
# Create parcel object
|
40
35
|
parcel = {
|
41
36
|
:length => 5,
|
42
|
-
:width =>
|
43
|
-
:height => 5
|
44
|
-
:distance_unit => :
|
37
|
+
:width => 2,
|
38
|
+
:height => 5,
|
39
|
+
:distance_unit => :in,
|
45
40
|
:weight => 2,
|
46
41
|
:mass_unit => :lb}
|
47
42
|
|
48
|
-
#
|
49
|
-
customs_item = {
|
50
|
-
:description => "T-Shirt",
|
51
|
-
:quantity => 2,
|
52
|
-
:net_weight => "400",
|
53
|
-
:mass_unit => "g",
|
54
|
-
:value_amount => "20",
|
55
|
-
:value_currency => "USD",
|
56
|
-
:origin_country => "US"}
|
57
|
-
|
58
|
-
#Creating the CustomsDeclaration
|
59
|
-
#(CustomsDeclarations are only required for international shipments)
|
60
|
-
customs_declaration = Shippo::Customs_Declaration.create(
|
61
|
-
:contents_type => "MERCHANDISE",
|
62
|
-
:contents_explanation => "T-Shirt purchase",
|
63
|
-
:non_delivery_option => "RETURN",
|
64
|
-
:certify => true,
|
65
|
-
:certify_signer => "Laura Behrens Wu",
|
66
|
-
:items => [customs_item])
|
67
|
-
|
68
|
-
# Creating the shipment object. In this example, the objects are directly passed to the
|
69
|
-
# Shipment.create method, Alternatively, the Address and Parcel objects could be created
|
70
|
-
# using Address.create(..) and Parcel.create(..) functions respectively
|
43
|
+
# Creating the shipment object
|
71
44
|
puts "Creating shipment object.."
|
72
45
|
shipment = Shippo::Shipment.create(
|
73
46
|
:object_purpose => 'PURCHASE',
|
74
|
-
:submission_type => 'DROPOFF',
|
75
47
|
:address_from => address_from,
|
76
48
|
:address_to => address_to,
|
77
49
|
:parcel => parcel,
|
78
|
-
:
|
79
|
-
|
80
|
-
puts "Shipment created. Waiting for rates to be generated.."
|
50
|
+
:async => false )
|
81
51
|
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
Timeout::timeout(timeout_rates_request) do
|
86
|
-
shipment = Shippo::Shipment.get(shipment["object_id"])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Get all rates for shipment.
|
91
|
-
rates = shipment.rates()
|
92
|
-
|
93
|
-
# Get the first rate in the rates results
|
94
|
-
rate = rates[0]
|
52
|
+
# Get the desired rate according to your business logic
|
53
|
+
# We select the first rate in this example
|
54
|
+
rate = shipment.rates()[0]
|
95
55
|
|
96
56
|
puts "Rates generated. Purchasing a #{rate.provider} #{rate.servicelevel_name} label"
|
97
57
|
|
98
58
|
# Purchase the desired rate (create a Transaction object)
|
99
|
-
transaction = Shippo::Transaction.create(
|
100
|
-
|
101
|
-
|
102
|
-
timeout_label_request = 10 # seconds
|
103
|
-
while ["QUEUED","WAITING"].include? transaction.object_status do
|
104
|
-
Timeout::timeout(timeout_label_request) do
|
105
|
-
transaction = Shippo::Transaction.get(transaction["object_id"])
|
106
|
-
end
|
107
|
-
end
|
59
|
+
transaction = Shippo::Transaction.create(
|
60
|
+
:rate => rate["object_id"],
|
61
|
+
:async => false )
|
108
62
|
|
109
63
|
# label_url and tracking_number
|
110
64
|
if transaction.object_status == "SUCCESS"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Shippo
|
2
|
+
module Operations
|
3
|
+
module Update
|
4
|
+
module ClassMethods
|
5
|
+
def update(object_id, params={})
|
6
|
+
response = Shippo.request(:put, "#{url}/#{CGI.escape(object_id)}/", params)
|
7
|
+
self.construct_from(response)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
def self.included(base)
|
11
|
+
base.extend(ClassMethods)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/shippo.rb
CHANGED
@@ -5,18 +5,25 @@ require 'set'
|
|
5
5
|
require_relative 'shippo/error.rb'
|
6
6
|
require_relative 'shippo/container_object.rb'
|
7
7
|
require_relative 'shippo/api_object.rb'
|
8
|
-
require_relative 'shippo/list.rb'
|
9
|
-
require_relative 'shippo/create.rb'
|
10
8
|
require_relative 'shippo/resource.rb'
|
9
|
+
|
10
|
+
# api operations
|
11
|
+
require_relative 'shippo/create.rb'
|
12
|
+
require_relative 'shippo/update.rb'
|
13
|
+
require_relative 'shippo/list.rb'
|
14
|
+
|
15
|
+
|
16
|
+
# api objects
|
11
17
|
require_relative 'shippo/address.rb'
|
12
|
-
require_relative 'shippo/
|
13
|
-
require_relative 'shippo/shipment.rb'
|
14
|
-
require_relative 'shippo/transaction.rb'
|
15
|
-
require_relative 'shippo/rate.rb'
|
16
|
-
require_relative 'shippo/manifest.rb'
|
18
|
+
require_relative 'shippo/carrieraccount.rb'
|
17
19
|
require_relative 'shippo/customs_item.rb'
|
18
20
|
require_relative 'shippo/customs_declaration.rb'
|
21
|
+
require_relative 'shippo/manifest.rb'
|
22
|
+
require_relative 'shippo/parcel.rb'
|
23
|
+
require_relative 'shippo/rate.rb'
|
19
24
|
require_relative 'shippo/refund.rb'
|
25
|
+
require_relative 'shippo/shipment.rb'
|
26
|
+
require_relative 'shippo/transaction.rb'
|
20
27
|
|
21
28
|
module Shippo
|
22
29
|
@api_base = 'https://api.goshippo.com/v1'
|
@@ -50,7 +57,7 @@ module Shippo
|
|
50
57
|
pairs.push "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
|
51
58
|
}
|
52
59
|
url += "?#{pairs.join('&')}" unless pairs.empty?
|
53
|
-
|
60
|
+
else
|
54
61
|
payload = params.to_json
|
55
62
|
end
|
56
63
|
opts = { :headers => headers,
|
metadata
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shippo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shippo & Contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mime-types
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.25'
|
34
|
-
- - <
|
34
|
+
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '3.0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '1.25'
|
44
|
-
- - <
|
44
|
+
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: json
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ~>
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: 1.8.1
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - ~>
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 1.8.1
|
61
61
|
description: Quick and easy access to the Shippo API
|
@@ -64,24 +64,26 @@ executables: []
|
|
64
64
|
extensions: []
|
65
65
|
extra_rdoc_files: []
|
66
66
|
files:
|
67
|
+
- "./lib/shippo/address.rb"
|
68
|
+
- "./lib/shippo/api_object.rb"
|
69
|
+
- "./lib/shippo/carrieraccount.rb"
|
70
|
+
- "./lib/shippo/container_object.rb"
|
71
|
+
- "./lib/shippo/create.rb"
|
72
|
+
- "./lib/shippo/customs_declaration.rb"
|
73
|
+
- "./lib/shippo/customs_item.rb"
|
74
|
+
- "./lib/shippo/error.rb"
|
75
|
+
- "./lib/shippo/list.rb"
|
76
|
+
- "./lib/shippo/manifest.rb"
|
77
|
+
- "./lib/shippo/parcel.rb"
|
78
|
+
- "./lib/shippo/rate.rb"
|
79
|
+
- "./lib/shippo/refund.rb"
|
80
|
+
- "./lib/shippo/resource.rb"
|
81
|
+
- "./lib/shippo/shipment.rb"
|
82
|
+
- "./lib/shippo/transaction.rb"
|
83
|
+
- "./lib/shippo/update.rb"
|
67
84
|
- example.rb
|
68
|
-
- test/test.rb
|
69
85
|
- lib/shippo.rb
|
70
|
-
-
|
71
|
-
- ./lib/shippo/api_object.rb
|
72
|
-
- ./lib/shippo/container_object.rb
|
73
|
-
- ./lib/shippo/create.rb
|
74
|
-
- ./lib/shippo/customs_declaration.rb
|
75
|
-
- ./lib/shippo/customs_item.rb
|
76
|
-
- ./lib/shippo/error.rb
|
77
|
-
- ./lib/shippo/list.rb
|
78
|
-
- ./lib/shippo/manifest.rb
|
79
|
-
- ./lib/shippo/parcel.rb
|
80
|
-
- ./lib/shippo/rate.rb
|
81
|
-
- ./lib/shippo/refund.rb
|
82
|
-
- ./lib/shippo/resource.rb
|
83
|
-
- ./lib/shippo/shipment.rb
|
84
|
-
- ./lib/shippo/transaction.rb
|
86
|
+
- test/test.rb
|
85
87
|
homepage: http://goshippo.com
|
86
88
|
licenses:
|
87
89
|
- MIT
|
@@ -92,17 +94,17 @@ require_paths:
|
|
92
94
|
- lib
|
93
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
96
|
requirements:
|
95
|
-
- -
|
97
|
+
- - ">="
|
96
98
|
- !ruby/object:Gem::Version
|
97
99
|
version: '0'
|
98
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
101
|
requirements:
|
100
|
-
- -
|
102
|
+
- - ">="
|
101
103
|
- !ruby/object:Gem::Version
|
102
104
|
version: '0'
|
103
105
|
requirements: []
|
104
106
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.4.5.1
|
106
108
|
signing_key:
|
107
109
|
specification_version: 4
|
108
110
|
summary: Shippo API
|