easypost 3.0.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +22 -0
- data/CHANGELOG +44 -3
- data/README.md +2 -1
- data/VERSION +1 -1
- data/easypost.gemspec +24 -20
- data/lib/easypost.rb +109 -118
- data/lib/easypost/address.rb +47 -47
- data/lib/easypost/batch.rb +34 -38
- data/lib/easypost/carrier_account.rb +3 -6
- data/lib/easypost/carrier_type.rb +2 -0
- data/lib/easypost/customs_info.rb +3 -2
- data/lib/easypost/customs_item.rb +3 -2
- data/lib/easypost/error.rb +25 -33
- 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 +111 -113
- data/lib/easypost/order.rb +20 -18
- data/lib/easypost/parcel.rb +1 -3
- data/lib/easypost/pickup.rb +19 -18
- 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 +90 -92
- data/lib/easypost/tracker.rb +10 -12
- data/lib/easypost/user.rb +33 -37
- data/lib/easypost/util.rb +99 -136
- data/lib/easypost/webhook.rb +22 -21
- metadata +35 -62
- data/circle.yml +0 -3
- data/spec/address_spec.rb +0 -81
- data/spec/batch_spec.rb +0 -48
- data/spec/carrier_account_spec.rb +0 -121
- data/spec/insurance_spec.rb +0 -69
- data/spec/item_spec.rb +0 -105
- data/spec/order_spec.rb +0 -58
- data/spec/pickup_spec.rb +0 -83
- data/spec/report_spec.rb +0 -59
- data/spec/scan_form_spec.rb +0 -46
- data/spec/shipment_spec.rb +0 -144
- data/spec/spec_helper.rb +0 -10
- data/spec/support/constant.rb +0 -106
- data/spec/tracker_spec.rb +0 -94
- data/spec/user_spec.rb +0 -88
- data/spec/webhook_spec.rb +0 -75
data/lib/easypost/order.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
class Order < Resource
|
1
|
+
class EasyPost::Order < EasyPost::Resource
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def get_rates(params={})
|
4
|
+
response = EasyPost.make_request(:get, url + '/rates', @api_key, params)
|
5
|
+
self.refresh_from(response, @api_key, true)
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
return self
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
def buy(params={})
|
11
|
+
if params.instance_of?(EasyPost::Rate)
|
12
|
+
temp = params.clone
|
13
|
+
params = {}
|
14
|
+
params[:carrier] = temp.carrier
|
15
|
+
params[:service] = temp.service
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
19
|
+
self.refresh_from(response, @api_key, true)
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
return self
|
22
|
+
end
|
24
23
|
|
24
|
+
def self.all(filters={}, api_key=nil)
|
25
|
+
raise NotImplementedError.new('Order.all not implemented.')
|
25
26
|
end
|
27
|
+
|
26
28
|
end
|
data/lib/easypost/parcel.rb
CHANGED
data/lib/easypost/pickup.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class EasyPost::Pickup < EasyPost::Resource
|
2
|
+
def buy(params={})
|
3
|
+
if params.instance_of?(EasyPost::PickupRate)
|
4
|
+
temp = params.clone
|
5
|
+
params = {}
|
6
|
+
params[:carrier] = temp.carrier
|
7
|
+
params[:service] = temp.service
|
8
|
+
end
|
3
9
|
|
4
|
-
|
5
|
-
|
6
|
-
temp = params.clone
|
7
|
-
params = {}
|
8
|
-
params[:carrier] = temp.carrier
|
9
|
-
params[:service] = temp.service
|
10
|
-
end
|
10
|
+
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
11
|
+
self.refresh_from(response, @api_key, true)
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
return self
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def cancel(params={})
|
17
|
+
response = EasyPost.make_request(:post, url + '/cancel', @api_key, params)
|
18
|
+
self.refresh_from(response, @api_key, true)
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
self.refresh_from(response, @api_key, true)
|
20
|
+
return self
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
def self.all(filters={}, api_key=nil)
|
24
|
+
raise NotImplementedError.new('Pickup.all not implemented.')
|
24
25
|
end
|
25
26
|
end
|
data/lib/easypost/pickup_rate.rb
CHANGED
data/lib/easypost/print_job.rb
CHANGED
data/lib/easypost/printer.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
|
-
|
2
|
-
class Printer < Resource
|
1
|
+
class EasyPost::Printer < EasyPost::Resource
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def print(params={})
|
12
|
-
if params.instance_of?(EasyPost::PostageLabel)
|
13
|
-
temp = params.clone
|
14
|
-
params = {}
|
15
|
-
params[:postage_label] = temp
|
16
|
-
end
|
3
|
+
def job
|
4
|
+
response = EasyPost.make_request(
|
5
|
+
:get, url + '/jobs', @api_key
|
6
|
+
)
|
7
|
+
return EasyPost::Util::convert_to_easypost_object(response, api_key)
|
8
|
+
end
|
17
9
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
return false
|
10
|
+
def print(params={})
|
11
|
+
if params.instance_of?(EasyPost::PostageLabel)
|
12
|
+
temp = params.clone
|
13
|
+
params = {}
|
14
|
+
params[:postage_label] = temp
|
24
15
|
end
|
25
16
|
|
17
|
+
response = EasyPost.make_request(
|
18
|
+
:post, url + '/print_postage_label', @api_key, params
|
19
|
+
)
|
20
|
+
true
|
21
|
+
rescue
|
22
|
+
false
|
26
23
|
end
|
27
24
|
end
|
28
|
-
|
data/lib/easypost/rate.rb
CHANGED
data/lib/easypost/refund.rb
CHANGED
data/lib/easypost/report.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
wrapped_params[class_name.to_sym] = params
|
1
|
+
class EasyPost::Report < EasyPost::Resource
|
2
|
+
def self.create(params={}, api_key=nil)
|
3
|
+
url = "#{self.url}/#{params[:type]}"
|
4
|
+
wrapped_params = {}
|
5
|
+
wrapped_params[class_name.to_sym] = params
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def self.retrieve(params, api_key=nil)
|
13
|
-
id = if params.is_a?(String)
|
14
|
-
params
|
15
|
-
else
|
16
|
-
params[:id]
|
17
|
-
end
|
7
|
+
response = EasyPost.make_request(:post, url, api_key, params)
|
8
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
9
|
+
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
def self.retrieve(params, api_key=nil)
|
12
|
+
id = if params.is_a?(String)
|
13
|
+
params
|
14
|
+
else
|
15
|
+
params[:id]
|
22
16
|
end
|
23
17
|
|
24
|
-
|
25
|
-
|
18
|
+
instance = self.new(id, api_key)
|
19
|
+
instance.refresh
|
20
|
+
return instance
|
21
|
+
end
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
def self.all(filters={}, api_key=nil)
|
24
|
+
url = "#{self.url}/#{filters[:type]}"
|
25
|
+
|
26
|
+
response = EasyPost.make_request(:get, url, api_key, filters)
|
27
|
+
return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
|
30
28
|
end
|
31
29
|
end
|
data/lib/easypost/resource.rb
CHANGED
@@ -1,77 +1,75 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
class EasyPost::Resource < EasyPost::EasyPostObject
|
2
|
+
def self.class_name
|
3
|
+
camel = self.name.split('::')[-1]
|
4
|
+
snake = camel[0..0] + camel[1..-1].gsub(/([A-Z])/, '_\1')
|
5
|
+
return snake.downcase
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
if(self.class_name[-1..-1] == 's' || self.class_name[-1..-1] == 'h')
|
14
|
-
return "/#{CGI.escape(self.class_name.downcase)}es"
|
15
|
-
else
|
16
|
-
return "/#{CGI.escape(class_name.downcase)}s"
|
17
|
-
end
|
8
|
+
def self.url
|
9
|
+
if self.class_name == 'resource'
|
10
|
+
raise NotImplementedError.new('Resource is an abstract class. You should perform actions on its subclasses (Address, Shipment, etc.)')
|
18
11
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
return "#{self.class.url}/#{CGI.escape(id)}"
|
12
|
+
if(self.class_name[-1..-1] == 's' || self.class_name[-1..-1] == 'h')
|
13
|
+
return "/v2/#{CGI.escape(self.class_name.downcase)}es"
|
14
|
+
else
|
15
|
+
return "/v2/#{CGI.escape(class_name.downcase)}s"
|
25
16
|
end
|
17
|
+
end
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
return self
|
19
|
+
def url
|
20
|
+
unless self.id
|
21
|
+
raise EasyPost::Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
|
31
22
|
end
|
23
|
+
return "#{self.class.url}/#{CGI.escape(id)}"
|
24
|
+
end
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
def refresh
|
27
|
+
response = EasyPost.make_request(:get, url, @api_key, @retrieve_options)
|
28
|
+
refresh_from(response, api_key)
|
29
|
+
return self
|
30
|
+
end
|
37
31
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
32
|
+
def self.all(filters={}, api_key=nil)
|
33
|
+
response = EasyPost.make_request(:get, url, api_key, filters)
|
34
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
35
|
+
end
|
43
36
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
37
|
+
def self.retrieve(id, api_key=nil)
|
38
|
+
instance = self.new(id, api_key)
|
39
|
+
instance.refresh
|
40
|
+
return instance
|
41
|
+
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
43
|
+
def self.create(params={}, api_key=nil)
|
44
|
+
wrapped_params = {}
|
45
|
+
wrapped_params[self.class_name().to_sym] = params
|
46
|
+
response = EasyPost.make_request(:post, self.url, api_key, wrapped_params)
|
47
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
48
|
+
end
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
def delete
|
51
|
+
response = EasyPost.make_request(:delete, url, @api_key)
|
52
|
+
refresh_from(response, api_key)
|
53
|
+
return self
|
54
|
+
end
|
55
|
+
|
56
|
+
def save
|
57
|
+
if @unsaved_values.length > 0
|
58
|
+
values = {}
|
59
|
+
@unsaved_values.each { |k| values[k] = @values[k] }
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
61
|
+
for key in @unsaved_values
|
62
|
+
value = values[key]
|
63
|
+
if value.is_a?(EasyPost::EasyPostObject)
|
64
|
+
values[key] = value.flatten_unsaved
|
67
65
|
end
|
66
|
+
end
|
68
67
|
|
69
|
-
|
68
|
+
wrapped_params = {self.class.class_name => values}
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
return self
|
70
|
+
response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
|
71
|
+
refresh_from(response, api_key)
|
75
72
|
end
|
73
|
+
return self
|
76
74
|
end
|
77
75
|
end
|
data/lib/easypost/scan_form.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
return Util.convert_to_easypost_object(response, api_key)
|
6
|
-
end
|
1
|
+
class EasyPost::ScanForm < EasyPost::Resource
|
2
|
+
def self.create(params={}, api_key=nil)
|
3
|
+
response = EasyPost.make_request(:post, self.url, api_key, params)
|
4
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
7
5
|
end
|
8
6
|
end
|
data/lib/easypost/shipment.rb
CHANGED
@@ -1,124 +1,122 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class EasyPost::Shipment < EasyPost::Resource
|
2
|
+
def get_rates(params={})
|
3
|
+
response = EasyPost.make_request(:get, url + '/rates', @api_key, params)
|
4
|
+
self.refresh_from(response, @api_key, true)
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
return self
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_smartrates
|
10
|
+
response = EasyPost.make_request(:get, url + '/smartrate', @api_key)
|
11
|
+
|
12
|
+
return response.fetch('result', [])
|
13
|
+
end
|
7
14
|
|
8
|
-
|
15
|
+
def buy(params={})
|
16
|
+
if params.instance_of?(EasyPost::Rate)
|
17
|
+
temp = params.clone
|
18
|
+
params = {}
|
19
|
+
params[:rate] = temp
|
9
20
|
end
|
10
21
|
|
11
|
-
|
12
|
-
|
13
|
-
temp = params.clone
|
14
|
-
params = {}
|
15
|
-
params[:rate] = temp
|
16
|
-
end
|
22
|
+
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
23
|
+
self.refresh_from(response, @api_key, true)
|
17
24
|
|
18
|
-
|
19
|
-
|
25
|
+
return self
|
26
|
+
end
|
20
27
|
|
21
|
-
|
28
|
+
def insure(params={})
|
29
|
+
if params.is_a?(Integer) || params.is_a?(Float)
|
30
|
+
temp = params.clone
|
31
|
+
params = {}
|
32
|
+
params[:amount] = temp
|
22
33
|
end
|
23
34
|
|
24
|
-
|
25
|
-
|
26
|
-
temp = params.clone
|
27
|
-
params = {}
|
28
|
-
params[:amount] = temp
|
29
|
-
end
|
35
|
+
response = EasyPost.make_request(:post, url + '/insure', @api_key, params)
|
36
|
+
self.refresh_from(response, @api_key, true)
|
30
37
|
|
31
|
-
|
32
|
-
|
38
|
+
return self
|
39
|
+
end
|
33
40
|
|
34
|
-
|
35
|
-
|
41
|
+
def refund(params={})
|
42
|
+
response = EasyPost.make_request(:get, url + '/refund', @api_key, params)
|
43
|
+
self.refresh_from(response, @api_key, true)
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
self.refresh_from(response, @api_key, true)
|
45
|
+
return self
|
46
|
+
end
|
40
47
|
|
41
|
-
|
48
|
+
def print(params={})
|
49
|
+
if params.instance_of?(EasyPost::Printer)
|
50
|
+
return params.print(self.postage_label)
|
42
51
|
end
|
52
|
+
return false
|
53
|
+
end
|
43
54
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
55
|
+
def label(params={})
|
56
|
+
if params.is_a?(String)
|
57
|
+
temp = params.clone
|
58
|
+
params = {}
|
59
|
+
params[:file_format] = temp
|
49
60
|
end
|
50
61
|
|
51
|
-
|
52
|
-
|
53
|
-
temp = params.clone
|
54
|
-
params = {}
|
55
|
-
params[:file_format] = temp
|
56
|
-
end
|
62
|
+
response = EasyPost.make_request(:get, url + '/label', @api_key, params)
|
63
|
+
self.refresh_from(response, @api_key, true)
|
57
64
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
return self
|
62
|
-
end
|
65
|
+
return self
|
66
|
+
end
|
63
67
|
|
64
|
-
|
65
|
-
|
68
|
+
def lowest_rate(carriers=[], services=[])
|
69
|
+
lowest = nil
|
66
70
|
|
67
|
-
|
71
|
+
self.get_rates unless self.rates
|
68
72
|
|
69
|
-
|
70
|
-
carriers.map!(&:downcase)
|
71
|
-
carriers.map!(&:strip)
|
73
|
+
carriers = EasyPost::Util.normalize_string_list(carriers)
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
75
|
+
negative_carriers = []
|
76
|
+
carriers_copy = carriers.clone
|
77
|
+
carriers_copy.each do |carrier|
|
78
|
+
if carrier[0,1] == '!'
|
79
|
+
negative_carriers << carrier[1..-1]
|
80
|
+
carriers.delete(carrier)
|
80
81
|
end
|
82
|
+
end
|
83
|
+
|
84
|
+
services = EasyPost::Util.normalize_string_list(services)
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
services_copy.each do |service|
|
89
|
-
if service[0,1] == '!'
|
90
|
-
negative_services << service[1..-1]
|
91
|
-
services.delete(service)
|
92
|
-
end
|
86
|
+
negative_services = []
|
87
|
+
services_copy = services.clone
|
88
|
+
services_copy.each do |service|
|
89
|
+
if service[0,1] == '!'
|
90
|
+
negative_services << service[1..-1]
|
91
|
+
services.delete(service)
|
93
92
|
end
|
93
|
+
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
rate_service = k.service.downcase
|
106
|
-
if services.size() > 0 && !services.include?(rate_service)
|
107
|
-
next
|
108
|
-
end
|
109
|
-
if negative_services.size() > 0 && negative_services.include?(rate_service)
|
110
|
-
next
|
111
|
-
end
|
112
|
-
|
113
|
-
if lowest == nil || k.rate.to_f < lowest.rate.to_f
|
114
|
-
lowest = k
|
115
|
-
end
|
95
|
+
self.rates.each do |k|
|
96
|
+
|
97
|
+
rate_carrier = k.carrier.downcase
|
98
|
+
if carriers.size() > 0 && !carriers.include?(rate_carrier)
|
99
|
+
next
|
100
|
+
end
|
101
|
+
if negative_carriers.size() > 0 && negative_carriers.include?(rate_carrier)
|
102
|
+
next
|
116
103
|
end
|
117
104
|
|
118
|
-
|
105
|
+
rate_service = k.service.downcase
|
106
|
+
if services.size() > 0 && !services.include?(rate_service)
|
107
|
+
next
|
108
|
+
end
|
109
|
+
if negative_services.size() > 0 && negative_services.include?(rate_service)
|
110
|
+
next
|
111
|
+
end
|
119
112
|
|
120
|
-
|
113
|
+
if lowest == nil || k.rate.to_f < lowest.rate.to_f
|
114
|
+
lowest = k
|
115
|
+
end
|
121
116
|
end
|
122
117
|
|
118
|
+
raise EasyPost::Error.new('No rates found.') if lowest == nil
|
119
|
+
|
120
|
+
return lowest
|
123
121
|
end
|
124
122
|
end
|