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/batch.rb
CHANGED
@@ -1,53 +1,49 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class EasyPost::Batch < EasyPost::Resource
|
2
|
+
def self.create_and_buy(params={}, api_key=nil)
|
3
|
+
wrapped_params = {}
|
4
|
+
wrapped_params[self.class_name().to_sym] = params
|
5
|
+
response = EasyPost.make_request(:post, url + '/create_and_buy', api_key, wrapped_params)
|
3
6
|
|
4
|
-
|
5
|
-
|
6
|
-
wrapped_params[self.class_name().to_sym] = params
|
7
|
-
response, api_key = EasyPost.request(:post, url + '/create_and_buy', api_key, wrapped_params)
|
8
|
-
|
9
|
-
return Util.convert_to_easypost_object(response, api_key)
|
10
|
-
end
|
11
|
-
|
12
|
-
def buy(params={})
|
13
|
-
response, api_key = EasyPost.request(:post, url + '/buy', @api_key, params)
|
14
|
-
self.refresh_from(response, @api_key, true)
|
7
|
+
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
8
|
+
end
|
15
9
|
|
16
|
-
|
17
|
-
|
10
|
+
def buy(params={})
|
11
|
+
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
12
|
+
self.refresh_from(response, @api_key, true)
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
self.refresh_from(response, @api_key, true)
|
14
|
+
return self
|
15
|
+
end
|
22
16
|
|
23
|
-
|
24
|
-
|
17
|
+
def label(params={})
|
18
|
+
response = EasyPost.make_request(:post, url + '/label', @api_key, params)
|
19
|
+
self.refresh_from(response, @api_key, true)
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
self.refresh_from(response, @api_key, true)
|
21
|
+
return self
|
22
|
+
end
|
29
23
|
|
30
|
-
|
31
|
-
|
24
|
+
def remove_shipments(params={})
|
25
|
+
response = EasyPost.make_request(:post, url + '/remove_shipments', @api_key, params)
|
26
|
+
self.refresh_from(response, @api_key, true)
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
self.refresh_from(response, @api_key, true)
|
28
|
+
return self
|
29
|
+
end
|
36
30
|
|
37
|
-
|
38
|
-
|
31
|
+
def add_shipments(params={})
|
32
|
+
response = EasyPost.make_request(:post, url + '/add_shipments', @api_key, params)
|
33
|
+
self.refresh_from(response, @api_key, true)
|
39
34
|
|
40
|
-
|
41
|
-
|
35
|
+
return self
|
36
|
+
end
|
42
37
|
|
43
|
-
|
44
|
-
|
38
|
+
def stamp_and_barcode_by_reference(params={})
|
39
|
+
response = EasyPost.make_request(:get, url + '/stamp_and_barcode_by_reference', @api_key, params)
|
45
40
|
|
46
|
-
|
47
|
-
|
41
|
+
return response
|
42
|
+
end
|
48
43
|
|
49
|
-
|
50
|
-
|
44
|
+
def create_scan_form(params={})
|
45
|
+
response = EasyPost.make_request(:post, url + '/scan_form', @api_key, params)
|
51
46
|
|
47
|
+
return response
|
52
48
|
end
|
53
49
|
end
|
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
response, api_key = EasyPost.request(:get, "/carrier_types", @api_key)
|
5
|
-
return Util.convert_to_easypost_object(response, api_key)
|
6
|
-
end
|
1
|
+
class EasyPost::CarrierAccount < EasyPost::Resource
|
2
|
+
def self.types
|
3
|
+
EasyPost::CarrierType.all
|
7
4
|
end
|
8
5
|
end
|
data/lib/easypost/error.rb
CHANGED
@@ -1,39 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
attr_reader :code
|
9
|
-
attr_reader :errors
|
1
|
+
class EasyPost::Error < StandardError
|
2
|
+
attr_reader :message
|
3
|
+
attr_reader :status
|
4
|
+
attr_reader :http_status # deprecated
|
5
|
+
attr_reader :http_body
|
6
|
+
attr_reader :code
|
7
|
+
attr_reader :errors
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def initialize(message = nil, status = nil, code = nil, errors = nil, http_body = nil)
|
10
|
+
@message = message
|
11
|
+
@status = status
|
12
|
+
@http_status = status # deprecated
|
13
|
+
@code = code
|
14
|
+
@errors = errors
|
15
|
+
@http_body = http_body
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
@errors = @json_body.fetch(:error, {}).fetch(:errors, nil)
|
17
|
+
super(message)
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
20
|
+
def to_s
|
21
|
+
"#{code} (#{status}): #{message} #{errors}".strip
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
s += " #{k}: #{v}\n"
|
31
|
-
end
|
32
|
-
s += "\n"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
s
|
36
|
-
end
|
24
|
+
def ==(other)
|
25
|
+
other.is_a?(EasyPost::Error) &&
|
26
|
+
message == other.message &&
|
27
|
+
status == other.status &&
|
28
|
+
code == other.code &&
|
29
|
+
errors == other.errors
|
37
30
|
end
|
38
31
|
end
|
39
|
-
|
data/lib/easypost/event.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def self.receive(values)
|
7
|
-
return EasyPost::Util::convert_to_easypost_object(JSON.parse(values), nil)
|
8
|
-
end
|
3
|
+
class EasyPost::Event < EasyPost::Resource
|
4
|
+
def self.receive(values)
|
5
|
+
return EasyPost::Util::convert_to_easypost_object(JSON.parse(values), nil)
|
9
6
|
end
|
10
7
|
end
|
data/lib/easypost/insurance.rb
CHANGED
data/lib/easypost/item.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
response, api_key = EasyPost.request(:get, url + '/retrieve_reference', api_key, params)
|
6
|
-
return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
|
7
|
-
end
|
8
|
-
|
1
|
+
class EasyPost::Item < EasyPost::Resource
|
2
|
+
def self.retrieve_reference(params={}, api_key=nil)
|
3
|
+
response = EasyPost.make_request(:get, url + '/retrieve_reference', api_key, params)
|
4
|
+
return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
|
9
5
|
end
|
10
6
|
end
|
data/lib/easypost/object.rb
CHANGED
@@ -1,149 +1,147 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def self.construct_from(values, api_key=nil, parent=nil, name=nil)
|
19
|
-
obj = self.new(values[:id], api_key, parent, name)
|
20
|
-
obj.refresh_from(values, api_key)
|
21
|
-
obj
|
22
|
-
end
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
class EasyPost::EasyPostObject
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
attr_accessor :parent, :name, :api_key, :unsaved_values
|
7
|
+
@@immutable_values = Set.new([:api_key, :id])
|
8
|
+
|
9
|
+
def initialize(id=nil, api_key=nil, parent=nil, name=nil)
|
10
|
+
@api_key = api_key
|
11
|
+
@values = {}
|
12
|
+
@unsaved_values = Set.new
|
13
|
+
@transient_values = Set.new
|
14
|
+
@parent = parent
|
15
|
+
@name = name
|
16
|
+
self.id = id if id
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
def self.construct_from(values, api_key=nil, parent=nil, name=nil)
|
20
|
+
obj = self.new(values[:id], api_key, parent, name)
|
21
|
+
obj.refresh_from(values, api_key)
|
22
|
+
obj
|
23
|
+
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
25
|
+
def to_s(*args)
|
26
|
+
JSON.dump(@values)
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
|
29
|
+
def inspect
|
30
|
+
id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : ""
|
31
|
+
"#<#{self.class}:#{id_string}> JSON: " + to_json
|
32
|
+
end
|
35
33
|
|
36
|
-
|
34
|
+
def refresh_from(values, api_key, partial=false)
|
35
|
+
@api_key = api_key
|
37
36
|
|
38
|
-
|
39
|
-
add_accessors(added)
|
40
|
-
end
|
37
|
+
added = Set.new(values.keys - @values.keys)
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
@transient_values.delete(k)
|
45
|
-
@unsaved_values.delete(k)
|
46
|
-
end
|
39
|
+
instance_eval do
|
40
|
+
add_accessors(added)
|
47
41
|
end
|
48
42
|
|
49
|
-
|
50
|
-
k =
|
51
|
-
@
|
43
|
+
values.each do |k, v|
|
44
|
+
@values[k.to_s] = EasyPost::Util.convert_to_easypost_object(v, api_key, self, k)
|
45
|
+
@transient_values.delete(k)
|
46
|
+
@unsaved_values.delete(k)
|
52
47
|
end
|
48
|
+
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
def [](k)
|
51
|
+
@values[k.to_s]
|
52
|
+
end
|
57
53
|
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
def []=(k, v)
|
55
|
+
send(:"#{k}=", v)
|
56
|
+
end
|
61
57
|
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
def keys
|
59
|
+
@values.keys
|
60
|
+
end
|
65
61
|
|
66
|
-
|
67
|
-
|
68
|
-
|
62
|
+
def values
|
63
|
+
@values.values
|
64
|
+
end
|
69
65
|
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
def to_json(options = {})
|
67
|
+
JSON.dump(@values)
|
68
|
+
end
|
73
69
|
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
def as_json(options = {})
|
71
|
+
@values.as_json
|
72
|
+
end
|
77
73
|
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
def to_hash
|
75
|
+
@values
|
76
|
+
end
|
81
77
|
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
def each(&blk)
|
79
|
+
@values.each(&blk)
|
80
|
+
end
|
85
81
|
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
def id=(id)
|
83
|
+
@values[:id] = id
|
84
|
+
end
|
89
85
|
|
90
|
-
|
86
|
+
def id
|
87
|
+
@values[:id]
|
88
|
+
end
|
91
89
|
|
92
|
-
|
93
|
-
values = {}
|
94
|
-
for key in @unsaved_values
|
95
|
-
value = @values[key]
|
90
|
+
protected
|
96
91
|
|
97
|
-
|
92
|
+
def flatten_unsaved
|
93
|
+
values = {}
|
94
|
+
for key in @unsaved_values
|
95
|
+
value = @values[key]
|
98
96
|
|
99
|
-
|
100
|
-
values[key] = flatten_unsaved(value)
|
101
|
-
end
|
102
|
-
end
|
97
|
+
values[key] = value
|
103
98
|
|
104
|
-
|
99
|
+
if value.is_a?(EasyPost::EasyPostObject)
|
100
|
+
values[key] = flatten_unsaved(value)
|
101
|
+
end
|
105
102
|
end
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
end
|
104
|
+
return values
|
105
|
+
end
|
110
106
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
107
|
+
def metaclass
|
108
|
+
class << self; self; end
|
109
|
+
end
|
110
|
+
|
111
|
+
def remove_accessors(keys)
|
112
|
+
metaclass.instance_eval do
|
113
|
+
keys.each do |k|
|
114
|
+
next if @@immutable_values.include?(k)
|
115
|
+
k_eq = :"#{k}="
|
116
|
+
remove_method(k) if method_defined?(k)
|
117
|
+
remove_method(k_eq) if method_defined?(k_eq)
|
119
118
|
end
|
120
119
|
end
|
120
|
+
end
|
121
121
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
cur = cur_parent
|
141
|
-
cur_parent = cur.parent
|
122
|
+
def add_accessors(keys)
|
123
|
+
metaclass.instance_eval do
|
124
|
+
keys.each do |k|
|
125
|
+
next if @@immutable_values.include?(k)
|
126
|
+
k = k.to_s
|
127
|
+
k_eq = :"#{k}="
|
128
|
+
define_method(k) { @values[k] }
|
129
|
+
define_method(k_eq) do |v|
|
130
|
+
@values[k] = v
|
131
|
+
@unsaved_values.add(k)
|
132
|
+
|
133
|
+
cur = self
|
134
|
+
cur_parent = self.parent
|
135
|
+
while cur_parent
|
136
|
+
if cur.name
|
137
|
+
cur_parent.unsaved_values.add(cur.name)
|
142
138
|
end
|
139
|
+
|
140
|
+
cur = cur_parent
|
141
|
+
cur_parent = cur.parent
|
143
142
|
end
|
144
143
|
end
|
145
144
|
end
|
146
145
|
end
|
147
|
-
|
148
146
|
end
|
149
147
|
end
|