easypost 3.1.4 → 3.1.5
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 +4 -4
- data/CHANGELOG +6 -0
- data/README.md +1 -0
- data/VERSION +1 -1
- data/lib/easypost.rb +2 -2
- data/lib/easypost/address.rb +47 -49
- data/lib/easypost/batch.rb +34 -38
- data/lib/easypost/carrier_account.rb +4 -6
- data/lib/easypost/customs_info.rb +3 -7
- data/lib/easypost/customs_item.rb +3 -7
- data/lib/easypost/error.rb +25 -27
- data/lib/easypost/event.rb +3 -6
- data/lib/easypost/insurance.rb +1 -3
- data/lib/easypost/item.rb +4 -8
- data/lib/easypost/object.rb +109 -111
- data/lib/easypost/order.rb +20 -22
- data/lib/easypost/parcel.rb +1 -3
- data/lib/easypost/pickup.rb +19 -23
- data/lib/easypost/pickup_rate.rb +1 -3
- data/lib/easypost/postage_label.rb +1 -3
- data/lib/easypost/print_job.rb +1 -5
- data/lib/easypost/printer.rb +18 -22
- data/lib/easypost/rate.rb +1 -3
- data/lib/easypost/refund.rb +1 -3
- data/lib/easypost/report.rb +22 -24
- data/lib/easypost/resource.rb +58 -60
- data/lib/easypost/scan_form.rb +4 -6
- data/lib/easypost/shipment.rb +83 -87
- data/lib/easypost/tracker.rb +10 -12
- data/lib/easypost/user.rb +33 -35
- data/lib/easypost/util.rb +100 -102
- data/lib/easypost/webhook.rb +22 -24
- metadata +2 -2
data/lib/easypost/tracker.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
class EasyPost::Tracker < EasyPost::Resource
|
2
|
+
def self.create_list(params={}, api_key=nil)
|
3
|
+
url = self.url + '/create_list'
|
4
|
+
response = EasyPost.make_request(:post, url, api_key, params)
|
5
|
+
return true
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
8
|
+
def self.all_updated(params={}, api_key=nil)
|
9
|
+
url = self.url + '/all_updated'
|
10
|
+
response = EasyPost.make_request(:get, url, api_key, params)
|
11
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
14
12
|
end
|
15
13
|
end
|
data/lib/easypost/user.rb
CHANGED
@@ -1,47 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
class EasyPost::User < EasyPost::Resource
|
2
|
+
def self.create(params={}, api_key=nil)
|
3
|
+
response = EasyPost.make_request(:post, self.url, api_key, {self.class_name.to_sym => params})
|
4
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def save
|
8
|
+
if @unsaved_values.length > 0
|
9
|
+
values = {}
|
10
|
+
@unsaved_values.each { |k| values[k] = @values[k] }
|
12
11
|
|
13
|
-
|
12
|
+
wrapped_params = {user: values}
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
return self
|
14
|
+
response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
|
15
|
+
refresh_from(response, api_key)
|
19
16
|
end
|
17
|
+
return self
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def self.retrieve_me
|
21
|
+
self.all
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def self.all_api_keys
|
25
|
+
response = EasyPost.make_request(:get, "/api_keys", @api_key)
|
26
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def api_keys
|
30
|
+
api_keys = EasyPost::User.all_api_keys
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if child.id == self.id
|
38
|
-
my_api_keys = child.keys
|
39
|
-
break
|
40
|
-
end
|
32
|
+
if api_keys.id == self.id
|
33
|
+
my_api_keys = api_keys.keys
|
34
|
+
else
|
35
|
+
for child in api_keys.children
|
36
|
+
if child.id == self.id
|
37
|
+
my_api_keys = child.keys
|
38
|
+
break
|
41
39
|
end
|
42
40
|
end
|
43
|
-
|
44
|
-
my_api_keys
|
45
41
|
end
|
42
|
+
|
43
|
+
my_api_keys
|
46
44
|
end
|
47
45
|
end
|
data/lib/easypost/util.rb
CHANGED
@@ -1,112 +1,110 @@
|
|
1
|
-
module EasyPost
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return obj
|
15
|
-
end
|
1
|
+
module EasyPost::Util
|
2
|
+
def self.objects_to_ids(obj)
|
3
|
+
case obj
|
4
|
+
when EasyPost::Resource
|
5
|
+
return {:id => obj.id}
|
6
|
+
when Hash
|
7
|
+
result = {}
|
8
|
+
obj.each { |k, v| result[k] = objects_to_ids(v) unless v.nil? }
|
9
|
+
return result
|
10
|
+
when Array
|
11
|
+
return obj.map { |v| objects_to_ids(v) }
|
12
|
+
else
|
13
|
+
return obj
|
16
14
|
end
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def self.normalize_string_list(lst)
|
18
|
+
lst = lst.is_a?(String) ? lst.split(',') : Array(lst)
|
19
|
+
lst.map(&:to_s).map(&:downcase).map(&:strip)
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
22
|
+
def self.convert_to_easypost_object(response, api_key, parent=nil, name=nil)
|
23
|
+
types = {
|
24
|
+
'Address' => EasyPost::Address,
|
25
|
+
'ScanForm' => EasyPost::ScanForm,
|
26
|
+
'CustomsItem' => EasyPost::CustomsItem,
|
27
|
+
'CustomsInfo' => EasyPost::CustomsInfo,
|
28
|
+
'Parcel' => EasyPost::Parcel,
|
29
|
+
'Shipment' => EasyPost::Shipment,
|
30
|
+
'Rate' => EasyPost::Rate,
|
31
|
+
'Refund' => EasyPost::Refund,
|
32
|
+
'Event' => EasyPost::Event,
|
33
|
+
'Batch' => EasyPost::Batch,
|
34
|
+
'Tracker' => EasyPost::Tracker,
|
35
|
+
'Item' => EasyPost::Item,
|
36
|
+
'Insurance' => EasyPost::Insurance,
|
37
|
+
'Order' => EasyPost::Order,
|
38
|
+
'Pickup' => EasyPost::Pickup,
|
39
|
+
'PickupRate' => EasyPost::PickupRate,
|
40
|
+
'PostageLabel' => EasyPost::PostageLabel,
|
41
|
+
'Printer' => EasyPost::Printer,
|
42
|
+
'PrintJob' => EasyPost::PrintJob,
|
43
|
+
'CarrierAccount' => EasyPost::CarrierAccount,
|
44
|
+
'User' => EasyPost::User,
|
45
|
+
'Report' => EasyPost::Report,
|
46
|
+
'ShipmentReport' => EasyPost::Report,
|
47
|
+
'PaymentLogReport' => EasyPost::Report,
|
48
|
+
'TrackerReport' => EasyPost::Report,
|
49
|
+
'RefundReport' => EasyPost::Report,
|
50
|
+
'ShipmentInvoiceReport' => EasyPost::Report,
|
51
|
+
'Webhook' => EasyPost::Webhook
|
52
|
+
}
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
54
|
+
prefixes = {
|
55
|
+
'adr' => EasyPost::Address,
|
56
|
+
'sf' => EasyPost::ScanForm,
|
57
|
+
'cstitem' => EasyPost::CustomsItem,
|
58
|
+
'cstinfo' => EasyPost::CustomsInfo,
|
59
|
+
'prcl' => EasyPost::Parcel,
|
60
|
+
'shp' => EasyPost::Shipment,
|
61
|
+
'rate' => EasyPost::Rate,
|
62
|
+
'rfnd' => EasyPost::Refund,
|
63
|
+
'evt' => EasyPost::Event,
|
64
|
+
'batch' => EasyPost::Batch,
|
65
|
+
'trk' => EasyPost::Tracker,
|
66
|
+
'item' => EasyPost::Item,
|
67
|
+
'ins' => EasyPost::Insurance,
|
68
|
+
'order' => EasyPost::Order,
|
69
|
+
'pickup' => EasyPost::Pickup,
|
70
|
+
'pickuprate' => EasyPost::PickupRate,
|
71
|
+
'pl' => EasyPost::PostageLabel,
|
72
|
+
'printer' => EasyPost::Printer,
|
73
|
+
'printjob' => EasyPost::PrintJob,
|
74
|
+
'ca' => EasyPost::CarrierAccount,
|
75
|
+
'user' => EasyPost::User,
|
76
|
+
'shprep' => EasyPost::Report,
|
77
|
+
'plrep' => EasyPost::Report,
|
78
|
+
'trkrep' => EasyPost::Report,
|
79
|
+
'refrep' => EasyPost::Report,
|
80
|
+
'shpinvrep' => EasyPost::Report,
|
81
|
+
'hook' => EasyPost::Webhook
|
82
|
+
}
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
84
|
+
case response
|
85
|
+
when Array
|
86
|
+
return response.map { |i| convert_to_easypost_object(i, api_key, parent) }
|
87
|
+
when Hash
|
88
|
+
if cls_name = response[:object]
|
89
|
+
cls = types[cls_name]
|
90
|
+
elsif response[:id]
|
91
|
+
if response[:id].index('_').nil?
|
92
|
+
cls = EasyPost::EasyPostObject
|
93
|
+
elsif cls_prefix = response[:id][0..response[:id].index('_')]
|
94
|
+
cls = prefixes[cls_prefix[0..-2]]
|
95
|
+
end
|
96
|
+
elsif response['id']
|
97
|
+
if response['id'].index('_').nil?
|
98
|
+
cls = EasyPost::EasyPostObject
|
99
|
+
elsif cls_prefix = response['id'][0..response['id'].index('_')]
|
100
|
+
cls = prefixes[cls_prefix[0..-2]]
|
103
101
|
end
|
104
|
-
|
105
|
-
cls ||= EasyPostObject
|
106
|
-
return cls.construct_from(response, api_key, parent, name)
|
107
|
-
else
|
108
|
-
return response
|
109
102
|
end
|
103
|
+
|
104
|
+
cls ||= EasyPost::EasyPostObject
|
105
|
+
return cls.construct_from(response, api_key, parent, name)
|
106
|
+
else
|
107
|
+
return response
|
110
108
|
end
|
111
109
|
end
|
112
110
|
end
|
data/lib/easypost/webhook.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
|
8
|
-
end
|
9
|
-
instance_url = "#{self.class.url}/#{CGI.escape(id)}"
|
10
|
-
|
11
|
-
response = EasyPost.make_request(:put, instance_url, @api_key, params)
|
12
|
-
self.refresh_from(response, api_key, true)
|
13
|
-
|
14
|
-
return self
|
1
|
+
class EasyPost::Webhook < EasyPost::Resource
|
2
|
+
def update(params={})
|
3
|
+
# NOTE: This method is redefined here since the "url" method conflicts
|
4
|
+
# with the objects field
|
5
|
+
unless self.id
|
6
|
+
raise EasyPost::Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
|
15
7
|
end
|
8
|
+
instance_url = "#{self.class.url}/#{CGI.escape(id)}"
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
# with the objects field
|
20
|
-
unless self.id
|
21
|
-
raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
|
22
|
-
end
|
23
|
-
instance_url = "#{self.class.url}/#{CGI.escape(id)}"
|
10
|
+
response = EasyPost.make_request(:put, instance_url, @api_key, params)
|
11
|
+
self.refresh_from(response, api_key, true)
|
24
12
|
|
25
|
-
|
26
|
-
|
13
|
+
return self
|
14
|
+
end
|
27
15
|
|
28
|
-
|
16
|
+
def delete
|
17
|
+
# NOTE: This method is redefined here since the "url" method conflicts
|
18
|
+
# with the objects field
|
19
|
+
unless self.id
|
20
|
+
raise EasyPost::Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
|
29
21
|
end
|
22
|
+
instance_url = "#{self.class.url}/#{CGI.escape(id)}"
|
23
|
+
|
24
|
+
response = EasyPost.make_request(:delete, instance_url, @api_key)
|
25
|
+
refresh_from(response, api_key)
|
26
|
+
|
27
|
+
return self
|
30
28
|
end
|
31
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easypost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Epstein
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pry
|