shippo 2.0.7 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +7 -3
- data/bin/batch_example +211 -0
- data/bin/track_example +131 -0
- data/lib/shippo/api/api_object.rb +1 -1
- data/lib/shippo/api/operations/batch.rb +38 -0
- data/lib/shippo/api/operations/track.rb +15 -0
- data/lib/shippo/api/resource.rb +3 -1
- data/lib/shippo/api/version.rb +1 -1
- data/lib/shippo/model/batch.rb +5 -0
- data/lib/shippo/model/track.rb +5 -0
- data/shippo.gemspec +2 -0
- metadata +43 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd31fa476553d97988451c18460953d23d7f5aa6
|
4
|
+
data.tar.gz: f02f1f23ba6177ecc8b7db13ae3fdfb696a5684e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be7319563465cddd71b074bd6562bbe5d34ea428d7ca027d48fec7798fd2019eab6798f2c08d4551129a00cb1dea26f669fd6a61a25e87a54379a9eafe340532
|
7
|
+
data.tar.gz: 308b45777bb9b65fb19b41cadab55883ac46689c0283525408212b03e4e04d0d57744b58b1fc86ed076aea1f8f5770d26bd311a34b1be1e4de476328d11af8cb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
### 2.0.8 release, Feb 15th, 2017
|
2
|
+
- Add Batch API with example code
|
3
|
+
- Creation
|
4
|
+
- Retrieval
|
5
|
+
- Adding shipments to Batch objects
|
6
|
+
- Removing shipments from Batch objects
|
7
|
+
- Purchasing
|
8
|
+
- Add Track API with example code
|
9
|
+
- Retrieving tracking status of a shipment
|
10
|
+
- Registering a tracking webhook
|
11
|
+
- Add mock tests using VCR (for Batch and Track API)
|
12
|
+
- https://github.com/vcr/vcr
|
13
|
+
|
1
14
|
### 2.0.7 release, Jan 2nd, 2017
|
2
15
|
- Fixed bug preventing address validation
|
3
16
|
- Removed trailing slash from base URL, added spec test to ensure this configuration
|
@@ -5,9 +18,11 @@
|
|
5
18
|
- Updated basic shipment example to include how to access the Shippo object id
|
6
19
|
### 2.0.6 release, Nov 22nd, 2016
|
7
20
|
- Fixed bug to send request with correct API version header
|
21
|
+
|
8
22
|
#### 2.0.5 release, Oct 24th, 2016
|
9
23
|
- Updated README.md
|
10
24
|
- now possible to send API version
|
25
|
+
|
11
26
|
#### 2.0.4 release, Oct 6th 2016
|
12
27
|
- Rails5 Compatibility via relaxed dependencies
|
13
28
|
- removing mime-types dependency
|
data/README.md
CHANGED
@@ -183,13 +183,17 @@ Shippo API returns several generalized fields for each valid resource, that bein
|
|
183
183
|
|
184
184
|
Unfortunately Shippo API also returns `object_id`, which in Ruby has a special meaning: it's the pointer address of any object. Overwriting this field causes all sorts of issues.
|
185
185
|
|
186
|
-
For this reason we are mapping `object_id` to `resource_id`, as soon as the hash is passed in to initialize `ApiObject`.
|
186
|
+
For this reason we are mapping `object_id` to `resource_id`, as soon as the hash is passed in to initialize `ApiObject`. This way `object_id` continues to be used as a ruby internal field, and can be accessed as expected:
|
187
187
|
|
188
|
-
|
188
|
+
> In the example below, `object_id` does not refer to any API field, and is a ruby internal field.
|
189
189
|
|
190
190
|
```ruby
|
191
191
|
@shipment.object_id # this is the Ruby object pointer
|
192
192
|
# ⤷ 70206221831520
|
193
|
+
```
|
194
|
+
To access the `"object_id"` field retrieved with the API, see the following session that highlights many ways of accessing `object_id` field:
|
195
|
+
|
196
|
+
```ruby
|
193
197
|
@shipment.resource_id # this is the API id (note: deprecated accessor)
|
194
198
|
# ⤷ 20f25e44b16b4051b6dd910cb66fd27b
|
195
199
|
@shipment.object.id # which is actually just this
|
@@ -198,7 +202,7 @@ The following console output demonstrates many ways of accessing `object_` field
|
|
198
202
|
# ⤷ 20f25e44b16b4051b6dd910cb66fd27b
|
199
203
|
```
|
200
204
|
|
201
|
-
|
205
|
+
Finally, here is how we access the rest of the `object_` fields:
|
202
206
|
|
203
207
|
``` ruby
|
204
208
|
@shipment.object.owner # this is whether 'object_owner' is stored
|
data/bin/batch_example
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# © 2016 Shippo, Inc.
|
4
|
+
#
|
5
|
+
# License: MIT
|
6
|
+
#
|
7
|
+
# This example demonstrates how to get the tracking status of a shipment
|
8
|
+
# Please set +SHIPPO_TOKEN+ in the environment before running it.
|
9
|
+
#
|
10
|
+
# You can also set +SHIPPO_DEBUG+ to see detailed printouts of objects returned.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
lib = File.expand_path('../../lib', __FILE__)
|
15
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
16
|
+
|
17
|
+
require 'bundler/setup'
|
18
|
+
require 'shippo'
|
19
|
+
require 'shippo/api/category'
|
20
|
+
require 'shippo/exceptions/api_error'
|
21
|
+
require 'awesome_print'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
Shippo::API.token = ENV['SHIPPO_TOKEN']
|
25
|
+
Hashie.logger = Logger.new(nil)
|
26
|
+
|
27
|
+
# Simple wrapper class to help us print objects to the STDOUT
|
28
|
+
class ExampleHelper
|
29
|
+
def self.log_operation(msg)
|
30
|
+
printf "%s", msg
|
31
|
+
result = yield
|
32
|
+
print "OK\n"
|
33
|
+
result
|
34
|
+
rescue Exception => e
|
35
|
+
raise(e)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.dump_object(instance, msg = nil)
|
39
|
+
return unless Shippo::API.debug?
|
40
|
+
sep
|
41
|
+
puts "#{msg.upcase}:" if msg
|
42
|
+
puts "\#<#{instance.class.inspect}:0x#{instance.object_id.to_s(16)}> ⇒ "
|
43
|
+
ap instance
|
44
|
+
sep
|
45
|
+
# See https://github.com/goshippo/shippo-ruby-client#resource-id-and-other-object-fields
|
46
|
+
puts "Shippo object id: #{instance.object.id}"
|
47
|
+
sep
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.sep
|
51
|
+
puts '—' * (ENV['COLUMNS'] || 80)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Retries up to 10 times to retrieve a valid
|
55
|
+
# Batch (which takes time to become 'VALID' from
|
56
|
+
# 'VALIDATING' after initially being created).
|
57
|
+
def self.retrieve_valid_batch(id)
|
58
|
+
retries = 10
|
59
|
+
retrieve = nil
|
60
|
+
until retries == 0 do
|
61
|
+
sleep 1
|
62
|
+
retrieve = Shippo::Batch::get(id)
|
63
|
+
break if retrieve[:object_status] == 'VALID'
|
64
|
+
retries -= 1
|
65
|
+
end
|
66
|
+
STDERR.puts 'Unable to retrieve VALID Batch object' unless retrieve
|
67
|
+
retrieve
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Create address_from object
|
72
|
+
address_from = {
|
73
|
+
:object_purpose => 'PURCHASE',
|
74
|
+
:name => 'Mr Hippo',
|
75
|
+
:company => 'Shippo',
|
76
|
+
:street1 => '215 Clayton St.',
|
77
|
+
:street2 => '',
|
78
|
+
:city => 'San Francisco',
|
79
|
+
:state => 'CA',
|
80
|
+
:zip => '94117',
|
81
|
+
:country => 'US',
|
82
|
+
:phone => '+1 555 341 9393',
|
83
|
+
:email => 'support@goshippo.com' }
|
84
|
+
|
85
|
+
# Create address_to object
|
86
|
+
address_to = {
|
87
|
+
:object_purpose => 'PURCHASE',
|
88
|
+
:name => 'Mrs Hippo"',
|
89
|
+
:company => 'San Diego Zoo',
|
90
|
+
:street1 => '2920 Zoo Drive',
|
91
|
+
:city => 'San Diego',
|
92
|
+
:state => 'CA',
|
93
|
+
:zip => '92101',
|
94
|
+
:country => 'US',
|
95
|
+
:phone => '+1 555 341 9393',
|
96
|
+
:email => 'hippo@goshippo.com' }
|
97
|
+
|
98
|
+
# Create parcel object
|
99
|
+
parcel = {
|
100
|
+
:length => 5,
|
101
|
+
:width => 2,
|
102
|
+
:height => 5,
|
103
|
+
:distance_unit => :in,
|
104
|
+
:weight => 2,
|
105
|
+
:mass_unit => :lb }
|
106
|
+
|
107
|
+
default_carrier_account = ENV['SHIPPO_TEST_CARRIER_ACCOUNT']
|
108
|
+
if !default_carrier_account
|
109
|
+
STDERR.puts 'Please set your SHIPPO_TEST_CARRIER_ACCOUNT environment variable.'
|
110
|
+
STDERR.puts
|
111
|
+
STDERR.puts 'You can do this by setting it to your USPS carrier account object ID:
|
112
|
+
|
113
|
+
Steps
|
114
|
+
--------------------------------------------------------------
|
115
|
+
1. curl https://api.goshippo.com/carrier_accounts/ \
|
116
|
+
-H "Authorization: ShippoToken <TEST_API_TOKEN>"
|
117
|
+
|
118
|
+
2. Look for {"carrier": "usps"} and find its "object_id"
|
119
|
+
|
120
|
+
3. export SHIPPO_TEST_CARRIER_ACCOUNT=<USPS_CARRIER_OBJECT_ID>
|
121
|
+
--------------------------------------------------------------
|
122
|
+
'
|
123
|
+
STDERR.puts
|
124
|
+
exit 1
|
125
|
+
end
|
126
|
+
hash = { :default_carrier_account => default_carrier_account,
|
127
|
+
:default_servicelevel_token => 'usps_priority',
|
128
|
+
:label_filetype => 'ZPLII',
|
129
|
+
:metadata => 'BATCH #170',
|
130
|
+
:batch_shipments => [
|
131
|
+
{
|
132
|
+
:shipment => {
|
133
|
+
:object_purpose => 'PURCHASE',
|
134
|
+
:address_from => address_from,
|
135
|
+
:address_to => address_to,
|
136
|
+
:parcel => parcel,
|
137
|
+
:async => false
|
138
|
+
}
|
139
|
+
}
|
140
|
+
]
|
141
|
+
}
|
142
|
+
|
143
|
+
shipment_params = { :object_purpose => 'PURCHASE',
|
144
|
+
:address_from => address_from,
|
145
|
+
:address_to => address_to,
|
146
|
+
:parcel => parcel,
|
147
|
+
:async => false }
|
148
|
+
|
149
|
+
begin
|
150
|
+
batch = ExampleHelper.log_operation 'Making first API call to create a batch...' do
|
151
|
+
Shippo::Batch.create(hash)
|
152
|
+
end
|
153
|
+
|
154
|
+
retrieve = ExampleHelper.log_operation 'Making API call to retrieve newly created batch...' do
|
155
|
+
ExampleHelper.retrieve_valid_batch(batch[:object_id])
|
156
|
+
end
|
157
|
+
puts "Batch status : #{retrieve[:object_status]}"
|
158
|
+
puts "metadata : #{retrieve[:metadata]}"
|
159
|
+
puts "Batch shipment count = #{retrieve[:batch_shipments][:count]}"
|
160
|
+
puts
|
161
|
+
|
162
|
+
shipment = ExampleHelper.log_operation 'Making API call to create a shipment... ' do
|
163
|
+
Shippo::Shipment.create(shipment_params)
|
164
|
+
end
|
165
|
+
raise Shippo::Exceptions::UnsuccessfulResponseError.new(shipment.object.inspect) unless shipment.success?
|
166
|
+
File.open('example-shipment.json', 'w') do |file|
|
167
|
+
file.puts JSON.dump(shipment.to_hash)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Adding shipments
|
171
|
+
shipments = Array.new
|
172
|
+
shipments.push({"shipment" => shipment[:object_id]})
|
173
|
+
added = ExampleHelper.log_operation 'Making API call to add a new shipment to batch...' do
|
174
|
+
Shippo::Batch::add_shipment(retrieve[:object_id], shipments)
|
175
|
+
end
|
176
|
+
puts "Batch shipment count = #{added[:batch_shipments][:count]}"
|
177
|
+
puts
|
178
|
+
|
179
|
+
# Removing shipments
|
180
|
+
shipments_to_remove = Array.new
|
181
|
+
shipments_to_remove.push(added.batch_shipments.results[0][:object_id])
|
182
|
+
removed = ExampleHelper.log_operation 'Making API call to remove the new shipment from batch...' do
|
183
|
+
Shippo::Batch::remove_shipment(retrieve[:object_id], shipments_to_remove)
|
184
|
+
end
|
185
|
+
puts "Batch shipment count = #{removed[:batch_shipments][:count]}"
|
186
|
+
puts
|
187
|
+
|
188
|
+
# Purchasing a batch
|
189
|
+
purchase = ExampleHelper.log_operation 'Making API call to purchase a batch...' do
|
190
|
+
Shippo::Batch::purchase(retrieve[:object_id])
|
191
|
+
end
|
192
|
+
puts "Batch status = #{purchase[:object_status]}"
|
193
|
+
puts
|
194
|
+
|
195
|
+
rescue Shippo::Exceptions::APIServerError => e
|
196
|
+
puts "Server returned an error:\n#{e}"
|
197
|
+
exit 3
|
198
|
+
rescue Shippo::Exceptions::ConnectionError
|
199
|
+
puts 'Error connecting to remote host. Is your Internet working?'
|
200
|
+
exit 2
|
201
|
+
rescue Shippo::Exceptions::AuthenticationError
|
202
|
+
if Shippo::API.token
|
203
|
+
puts "Token '#{Shippo::API.token}' does not appear to be valid."
|
204
|
+
puts 'Access denied.'
|
205
|
+
else
|
206
|
+
puts 'Please set authentication token in the environment:'
|
207
|
+
puts 'export SHIPPO_TOKEN="<your token here>"'
|
208
|
+
puts 'and re-run the example.'
|
209
|
+
end
|
210
|
+
exit 1
|
211
|
+
end
|
data/bin/track_example
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# © 2016 Shippo, Inc.
|
4
|
+
#
|
5
|
+
# License: MIT
|
6
|
+
#
|
7
|
+
# This example demonstrates how to get the tracking status of a shipment
|
8
|
+
# Please set +SHIPPO_TOKEN+ in the environment before running it.
|
9
|
+
#
|
10
|
+
# You can also set +SHIPPO_DEBUG+ to see detailed printouts of objects returned.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
lib = File.expand_path('../../lib', __FILE__)
|
15
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
16
|
+
|
17
|
+
require 'bundler/setup'
|
18
|
+
require 'shippo'
|
19
|
+
require 'shippo/api/category'
|
20
|
+
require 'shippo/exceptions/api_error'
|
21
|
+
require 'awesome_print'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
Shippo::API.token = ENV['SHIPPO_TOKEN']
|
25
|
+
Hashie.logger = Logger.new(nil)
|
26
|
+
|
27
|
+
# Simple wrapper class to help us print objects to the STDOUT
|
28
|
+
class ExampleHelper
|
29
|
+
def self.log_operation(msg)
|
30
|
+
printf '%s', msg
|
31
|
+
result = yield
|
32
|
+
printf "OK\n"
|
33
|
+
result
|
34
|
+
rescue Exception => e
|
35
|
+
raise(e)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.dump_object(instance, msg = nil)
|
39
|
+
return unless Shippo::API.debug?
|
40
|
+
sep
|
41
|
+
puts "#{msg.upcase}:" if msg
|
42
|
+
puts "\#<#{instance.class.inspect}:0x#{instance.object_id.to_s(16)}> ⇒ "
|
43
|
+
ap instance
|
44
|
+
sep
|
45
|
+
# See https://github.com/goshippo/shippo-ruby-client#resource-id-and-other-object-fields
|
46
|
+
puts "Shippo object id: #{instance.object.id}"
|
47
|
+
sep
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.sep
|
51
|
+
puts '—' * (ENV['COLUMNS'] || 80)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Create address_from object
|
56
|
+
address_from = {
|
57
|
+
:object_purpose => 'PURCHASE',
|
58
|
+
:name => 'Mr Hippo',
|
59
|
+
:company => 'Shippo',
|
60
|
+
:street1 => '215 Clayton St.',
|
61
|
+
:street2 => '',
|
62
|
+
:city => 'San Francisco',
|
63
|
+
:state => 'CA',
|
64
|
+
:zip => '94117',
|
65
|
+
:country => 'US',
|
66
|
+
:phone => '+1 555 341 9393',
|
67
|
+
:email => 'support@goshippo.com' }
|
68
|
+
|
69
|
+
# Create address_to object
|
70
|
+
address_to = {
|
71
|
+
:object_purpose => 'PURCHASE',
|
72
|
+
:name => 'Mrs Hippo"',
|
73
|
+
:company => 'San Diego Zoo',
|
74
|
+
:street1 => '2920 Zoo Drive',
|
75
|
+
:city => 'San Diego',
|
76
|
+
:state => 'CA',
|
77
|
+
:zip => '92101',
|
78
|
+
:country => 'US',
|
79
|
+
:phone => '+1 555 341 9393',
|
80
|
+
:email => 'hippo@goshippo.com' }
|
81
|
+
|
82
|
+
# Create parcel object
|
83
|
+
parcel = {
|
84
|
+
:length => 5,
|
85
|
+
:width => 2,
|
86
|
+
:height => 5,
|
87
|
+
:distance_unit => :in,
|
88
|
+
:weight => 2,
|
89
|
+
:mass_unit => :lb }
|
90
|
+
|
91
|
+
hash = { :object_purpose => 'PURCHASE',
|
92
|
+
:address_from => address_from,
|
93
|
+
:address_to => address_to,
|
94
|
+
:parcel => parcel,
|
95
|
+
:async => false }
|
96
|
+
|
97
|
+
begin
|
98
|
+
shipment = ExampleHelper.log_operation 'Making first API call for shipment rates...' do
|
99
|
+
Shippo::Shipment.create(hash)
|
100
|
+
end
|
101
|
+
track = ExampleHelper.log_operation 'Making API call to retrieve tracking status...' do
|
102
|
+
Shippo::Track.get(shipment[:object_id], 'usps')
|
103
|
+
end
|
104
|
+
raise Shippo::Exceptions::UnsuccessfulResponseError.new(shipment.object.inspect) unless shipment.success?
|
105
|
+
File.open('example-shipment.json', 'w') do |file|
|
106
|
+
file.puts JSON.dump(shipment.to_hash)
|
107
|
+
end
|
108
|
+
rescue Shippo::Exceptions::APIServerError => e
|
109
|
+
puts "Server returned an error:\n#{e}"
|
110
|
+
exit 3
|
111
|
+
rescue Shippo::Exceptions::ConnectionError
|
112
|
+
puts 'Error connecting to remote host. Is your Internet working?'
|
113
|
+
exit 2
|
114
|
+
rescue Shippo::Exceptions::AuthenticationError
|
115
|
+
if Shippo::API.token
|
116
|
+
puts "Token '#{Shippo::API.token}' does not appear to be valid."
|
117
|
+
puts 'Access denied.'
|
118
|
+
else
|
119
|
+
puts 'Please set authentication token in the environment:'
|
120
|
+
puts 'export SHIPPO_TOKEN="<your token here>"'
|
121
|
+
puts 'and re-run the example.'
|
122
|
+
end
|
123
|
+
exit 1
|
124
|
+
end
|
125
|
+
|
126
|
+
if track
|
127
|
+
puts "Carrier : #{track[:carrier]}"
|
128
|
+
puts "Tracking NO : #{track[:tracking_number]}"
|
129
|
+
else
|
130
|
+
puts 'Track ERROR'
|
131
|
+
end
|
@@ -78,7 +78,7 @@ module Shippo
|
|
78
78
|
|
79
79
|
# list of allowed properties, of a given type.
|
80
80
|
PROPS_ID = %i(id).freeze
|
81
|
-
PROPS_CATEG = %i(state purpose source status).freeze
|
81
|
+
PROPS_CATEG = %i(state purpose source status results).freeze
|
82
82
|
PROPS_EMAIL = %i(owner).freeze
|
83
83
|
PROPS_TIMED = %i(created updated).freeze
|
84
84
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Shippo
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
module Batch
|
5
|
+
# Retrieves a Batch by its ID
|
6
|
+
# @param [String] id The ID of the Batch object
|
7
|
+
# @param [Hash] params Optional params tacked onto the URL as URI parameters
|
8
|
+
def get(id, params={})
|
9
|
+
response = Shippo::API.get("#{url}/#{CGI.escape(id)}", params)
|
10
|
+
self.from(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Adds a new shipment to a batch object
|
14
|
+
# @param [String] id The ID of the Batch object
|
15
|
+
# @param [Array] shipments Array of shipment objects to be added
|
16
|
+
def add_shipment(id, shipments=[])
|
17
|
+
response = Shippo::API.post("#{url}/#{CGI.escape(id)}/add_shipments", shipments)
|
18
|
+
self.from(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Removes an existing shipment from a batch object
|
22
|
+
# @param [String] id The ID of the Batch object
|
23
|
+
# @param [Array] shipment_ids Array of shipment IDs to be removed
|
24
|
+
def remove_shipment(id, shipment_ids=[])
|
25
|
+
response = Shippo::API.post("#{url}/#{CGI.escape(id)}/remove_shipments", shipment_ids)
|
26
|
+
self.from(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Purchases an existing batch
|
30
|
+
# @param [String] id The ID of the Batch object
|
31
|
+
def purchase(id)
|
32
|
+
response = Shippo::API.post("#{url}/#{CGI.escape(id)}/purchase")
|
33
|
+
self.from(response)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Shippo
|
2
|
+
module API
|
3
|
+
module Operations
|
4
|
+
module Track
|
5
|
+
# Retrieves tracking status of a shipment
|
6
|
+
# @param [Fixnum] id Database ID of the shipment to be received
|
7
|
+
# @param [String] carrier The carrier of the item to be received
|
8
|
+
def get(id, carrier)
|
9
|
+
response = Shippo::API.get("#{url}/#{CGI.escape(carrier)}/#{CGI.escape(id)}/")
|
10
|
+
self.from(response)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/shippo/api/resource.rb
CHANGED
@@ -19,6 +19,8 @@ module Shippo
|
|
19
19
|
include Enumerable
|
20
20
|
extend Forwardable
|
21
21
|
|
22
|
+
disable_warnings
|
23
|
+
|
22
24
|
def self.object_properties
|
23
25
|
Shippo::API::ApiObject::PROPS
|
24
26
|
end
|
@@ -62,7 +64,7 @@ module Shippo
|
|
62
64
|
|
63
65
|
# As a Hashie::Mash subclass, Resource can initialize from another hash
|
64
66
|
def initialize(*args)
|
65
|
-
if args.first.is_a?(
|
67
|
+
if args.first.is_a?(Integer) or
|
66
68
|
(args.first.is_a?(String) && args.first =~ /^[0-9A-Fa-f]+$/)
|
67
69
|
self.id = args.first
|
68
70
|
elsif args.first.respond_to?(:keys)
|
data/lib/shippo/api/version.rb
CHANGED
data/shippo.gemspec
CHANGED
@@ -28,4 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'guard-rspec'
|
29
29
|
spec.add_development_dependency 'yard'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 2.1'
|
32
|
+
spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
31
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shippo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shippo & Contributors
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -165,6 +165,40 @@ dependencies:
|
|
165
165
|
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '3.4'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: webmock
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '2.1'
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '2.1'
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: vcr
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '3.0'
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: 3.0.3
|
192
|
+
type: :development
|
193
|
+
prerelease: false
|
194
|
+
version_requirements: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - "~>"
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '3.0'
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 3.0.3
|
168
202
|
description: A gem for connecting with over 20 shipping carriers and consolidators
|
169
203
|
via a single integration using Shippo API. Support for shipping rates, buying and
|
170
204
|
printing labels, tracking as well as some carrier specific functionality such as
|
@@ -190,7 +224,9 @@ files:
|
|
190
224
|
- Rakefile
|
191
225
|
- bin/address_validation_example
|
192
226
|
- bin/basic_shipment_example
|
227
|
+
- bin/batch_example
|
193
228
|
- bin/console
|
229
|
+
- bin/track_example
|
194
230
|
- lib/shippo.rb
|
195
231
|
- lib/shippo/api.rb
|
196
232
|
- lib/shippo/api/api_object.rb
|
@@ -204,9 +240,11 @@ files:
|
|
204
240
|
- lib/shippo/api/extend/transformers.rb
|
205
241
|
- lib/shippo/api/extend/url.rb
|
206
242
|
- lib/shippo/api/operations.rb
|
243
|
+
- lib/shippo/api/operations/batch.rb
|
207
244
|
- lib/shippo/api/operations/create.rb
|
208
245
|
- lib/shippo/api/operations/list.rb
|
209
246
|
- lib/shippo/api/operations/rates.rb
|
247
|
+
- lib/shippo/api/operations/track.rb
|
210
248
|
- lib/shippo/api/operations/update.rb
|
211
249
|
- lib/shippo/api/operations/validate.rb
|
212
250
|
- lib/shippo/api/request.rb
|
@@ -218,6 +256,7 @@ files:
|
|
218
256
|
- lib/shippo/exceptions/api_server_error.rb
|
219
257
|
- lib/shippo/exceptions/error.rb
|
220
258
|
- lib/shippo/model/address.rb
|
259
|
+
- lib/shippo/model/batch.rb
|
221
260
|
- lib/shippo/model/carrieraccount.rb
|
222
261
|
- lib/shippo/model/customs_declaration.rb
|
223
262
|
- lib/shippo/model/customs_item.rb
|
@@ -226,6 +265,7 @@ files:
|
|
226
265
|
- lib/shippo/model/rate.rb
|
227
266
|
- lib/shippo/model/refund.rb
|
228
267
|
- lib/shippo/model/shipment.rb
|
268
|
+
- lib/shippo/model/track.rb
|
229
269
|
- lib/shippo/model/transaction.rb
|
230
270
|
- lib/shippo/tasks/shippo.rb
|
231
271
|
- shippo.gemspec
|
@@ -250,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
250
290
|
version: '0'
|
251
291
|
requirements: []
|
252
292
|
rubyforge_project:
|
253
|
-
rubygems_version: 2.6.
|
293
|
+
rubygems_version: 2.6.8
|
254
294
|
signing_key:
|
255
295
|
specification_version: 4
|
256
296
|
summary: API client for Shippo® APIs. Shippo helps you connect with multiple carriers
|