easypost 3.5.1 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +9 -0
- data/.github/CODEOWNERS +2 -0
- data/.github/ISSUE_TEMPLATE/bug_report.yml +81 -0
- data/.github/ISSUE_TEMPLATE/feature_request.yml +37 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
- data/.github/workflows/ci.yml +54 -5
- data/.gitignore +27 -17
- data/.gitmodules +3 -0
- data/CHANGELOG.md +295 -119
- data/Gemfile +2 -0
- data/Makefile +70 -0
- data/README.md +184 -72
- data/Rakefile +2 -1
- data/UPGRADE_GUIDE.md +181 -0
- data/VERSION +1 -1
- data/bin/easypost-irb +5 -3
- data/easypost.gemspec +27 -20
- data/lib/easypost/client.rb +179 -0
- data/lib/easypost/connection.rb +64 -0
- data/lib/easypost/constants.rb +15 -0
- data/lib/easypost/errors/api/api_error.rb +108 -0
- data/lib/easypost/errors/api/bad_request_error.rb +6 -0
- data/lib/easypost/errors/api/connection_error.rb +6 -0
- data/lib/easypost/errors/api/external_api_error.rb +18 -0
- data/lib/easypost/errors/api/forbidden_error.rb +6 -0
- data/lib/easypost/errors/api/gateway_timeout_error.rb +6 -0
- data/lib/easypost/errors/api/internal_server_error.rb +6 -0
- data/lib/easypost/errors/api/invalid_request_error.rb +6 -0
- data/lib/easypost/errors/api/method_not_allowed_error.rb +6 -0
- data/lib/easypost/errors/api/not_found_error.rb +6 -0
- data/lib/easypost/errors/api/payment_error.rb +6 -0
- data/lib/easypost/errors/api/proxy_error.rb +6 -0
- data/lib/easypost/errors/api/rate_limit_error.rb +6 -0
- data/lib/easypost/errors/api/redirect_error.rb +6 -0
- data/lib/easypost/errors/api/retry_error.rb +6 -0
- data/lib/easypost/errors/api/service_unavailable_error.rb +6 -0
- data/lib/easypost/errors/api/ssl_error.rb +6 -0
- data/lib/easypost/errors/api/timeout_error.rb +6 -0
- data/lib/easypost/errors/api/unauthorized_error.rb +6 -0
- data/lib/easypost/errors/api/unknown_api_error.rb +6 -0
- data/lib/easypost/errors/easy_post_error.rb +7 -0
- data/lib/easypost/errors/end_of_pagination_error.rb +7 -0
- data/lib/easypost/errors/filtering_error.rb +4 -0
- data/lib/easypost/errors/invalid_object_error.rb +4 -0
- data/lib/easypost/errors/invalid_parameter_error.rb +11 -0
- data/lib/easypost/errors/missing_parameter_error.rb +9 -0
- data/lib/easypost/errors/signature_verification_error.rb +4 -0
- data/lib/easypost/errors.rb +32 -0
- data/lib/easypost/hooks/request_context.rb +16 -0
- data/lib/easypost/hooks/response_context.rb +23 -0
- data/lib/easypost/hooks.rb +34 -0
- data/lib/easypost/http_client.rb +117 -0
- data/lib/easypost/internal_utilities.rb +66 -0
- data/lib/easypost/models/address.rb +5 -0
- data/lib/easypost/models/api_key.rb +5 -0
- data/lib/easypost/models/base.rb +58 -0
- data/lib/easypost/models/batch.rb +5 -0
- data/lib/easypost/models/brand.rb +5 -0
- data/lib/easypost/models/carbon_offset.rb +5 -0
- data/lib/easypost/models/carrier_account.rb +5 -0
- data/lib/easypost/models/carrier_type.rb +5 -0
- data/lib/easypost/models/customs_info.rb +5 -0
- data/lib/easypost/models/customs_item.rb +5 -0
- data/lib/easypost/models/end_shipper.rb +5 -0
- data/lib/easypost/models/error.rb +21 -0
- data/lib/easypost/models/event.rb +5 -0
- data/lib/easypost/models/insurance.rb +6 -0
- data/lib/easypost/models/order.rb +9 -0
- data/lib/easypost/models/parcel.rb +5 -0
- data/lib/easypost/models/payload.rb +5 -0
- data/lib/easypost/models/payment_method.rb +5 -0
- data/lib/easypost/models/pickup.rb +9 -0
- data/lib/easypost/models/pickup_rate.rb +5 -0
- data/lib/easypost/models/postage_label.rb +5 -0
- data/lib/easypost/models/rate.rb +5 -0
- data/lib/easypost/models/referral.rb +5 -0
- data/lib/easypost/models/refund.rb +5 -0
- data/lib/easypost/models/report.rb +5 -0
- data/lib/easypost/models/scan_form.rb +6 -0
- data/lib/easypost/models/shipment.rb +10 -0
- data/lib/easypost/models/tax_identifier.rb +6 -0
- data/lib/easypost/models/tracker.rb +5 -0
- data/lib/easypost/models/user.rb +5 -0
- data/lib/easypost/models/webhook.rb +6 -0
- data/lib/easypost/models.rb +36 -0
- data/lib/easypost/services/address.rb +50 -0
- data/lib/easypost/services/api_key.rb +8 -0
- data/lib/easypost/services/base.rb +27 -0
- data/lib/easypost/services/batch.rb +53 -0
- data/lib/easypost/services/beta_rate.rb +12 -0
- data/lib/easypost/services/beta_referral_customer.rb +40 -0
- data/lib/easypost/services/billing.rb +75 -0
- data/lib/easypost/services/carrier_account.rb +44 -0
- data/lib/easypost/services/carrier_metadata.rb +22 -0
- data/lib/easypost/services/carrier_type.rb +10 -0
- data/lib/easypost/services/customs_info.rb +17 -0
- data/lib/easypost/services/customs_item.rb +15 -0
- data/lib/easypost/services/end_shipper.rb +31 -0
- data/lib/easypost/services/event.rb +32 -0
- data/lib/easypost/services/insurance.rb +26 -0
- data/lib/easypost/services/order.rb +30 -0
- data/lib/easypost/services/parcel.rb +16 -0
- data/lib/easypost/services/pickup.rb +40 -0
- data/lib/easypost/services/rate.rb +8 -0
- data/lib/easypost/services/referral_customer.rb +103 -0
- data/lib/easypost/services/refund.rb +26 -0
- data/lib/easypost/services/report.rb +42 -0
- data/lib/easypost/services/scan_form.rb +25 -0
- data/lib/easypost/services/shipment.rb +106 -0
- data/lib/easypost/services/tracker.rb +38 -0
- data/lib/easypost/services/user.rb +66 -0
- data/lib/easypost/services/webhook.rb +34 -0
- data/lib/easypost/services.rb +33 -0
- data/lib/easypost/util.rb +160 -116
- data/lib/easypost/utilities/constants.rb +5 -0
- data/lib/easypost/utilities/json.rb +23 -0
- data/lib/easypost/utilities/static_mapper.rb +73 -0
- data/lib/easypost/utilities/system.rb +36 -0
- data/lib/easypost/version.rb +3 -1
- data/lib/easypost.rb +20 -143
- metadata +249 -46
- data/lib/easypost/address.rb +0 -58
- data/lib/easypost/api_key.rb +0 -2
- data/lib/easypost/batch.rb +0 -49
- data/lib/easypost/brand.rb +0 -9
- data/lib/easypost/carrier_account.rb +0 -5
- data/lib/easypost/carrier_type.rb +0 -2
- data/lib/easypost/customs_info.rb +0 -5
- data/lib/easypost/customs_item.rb +0 -5
- data/lib/easypost/error.rb +0 -31
- data/lib/easypost/event.rb +0 -7
- data/lib/easypost/insurance.rb +0 -2
- data/lib/easypost/object.rb +0 -151
- data/lib/easypost/order.rb +0 -28
- data/lib/easypost/parcel.rb +0 -2
- data/lib/easypost/pickup.rb +0 -26
- data/lib/easypost/pickup_rate.rb +0 -3
- data/lib/easypost/postage_label.rb +0 -2
- data/lib/easypost/print_job.rb +0 -2
- data/lib/easypost/printer.rb +0 -24
- data/lib/easypost/rate.rb +0 -2
- data/lib/easypost/refund.rb +0 -2
- data/lib/easypost/report.rb +0 -29
- data/lib/easypost/resource.rb +0 -75
- data/lib/easypost/scan_form.rb +0 -6
- data/lib/easypost/shipment.rb +0 -129
- data/lib/easypost/tax_identifier.rb +0 -2
- data/lib/easypost/tracker.rb +0 -7
- data/lib/easypost/user.rb +0 -56
- data/lib/easypost/webhook.rb +0 -29
data/lib/easypost/address.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
class EasyPost::Address < EasyPost::Resource
|
2
|
-
attr_accessor :message # Backwards compatibility
|
3
|
-
|
4
|
-
def self.create(params={}, api_key=nil)
|
5
|
-
url = self.url
|
6
|
-
|
7
|
-
address = params.reject { |k,_| k == :verify || k == :verify_strict }
|
8
|
-
|
9
|
-
if params[:verify] || params[:verify_strict]
|
10
|
-
verify = params[:verify] || []
|
11
|
-
verify_strict = params[:verify_strict] || []
|
12
|
-
|
13
|
-
url += "?"
|
14
|
-
verify.each do |verification|
|
15
|
-
url += "verify[]=#{verification}&"
|
16
|
-
end
|
17
|
-
verify_strict.each do |verification|
|
18
|
-
url += "verify_strict[]=#{verification}&"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
response = EasyPost.make_request(:post, url, api_key, {address: address})
|
23
|
-
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.create_and_verify(params={}, carrier=nil, api_key=nil)
|
27
|
-
wrapped_params = {}
|
28
|
-
wrapped_params[self.class_name().to_sym] = params
|
29
|
-
wrapped_params[:carrier] = carrier
|
30
|
-
response = EasyPost.make_request(:post, url + '/create_and_verify', api_key, wrapped_params)
|
31
|
-
|
32
|
-
if response.has_key?("address")
|
33
|
-
if response.has_key?("message")
|
34
|
-
response["address"]["message"] = response["message"]
|
35
|
-
end
|
36
|
-
verified_address = EasyPost::Util::convert_to_easypost_object(response["address"], api_key)
|
37
|
-
return verified_address
|
38
|
-
else
|
39
|
-
raise EasyPost::Error.new("Unable to verify address.")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def verify(params={}, carrier=nil)
|
44
|
-
begin
|
45
|
-
response = EasyPost.make_request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
|
46
|
-
rescue
|
47
|
-
raise EasyPost::Error.new("Unable to verify address.")
|
48
|
-
end
|
49
|
-
|
50
|
-
if response.has_key?("address")
|
51
|
-
return EasyPost::Util::convert_to_easypost_object(response["address"], api_key)
|
52
|
-
else
|
53
|
-
raise EasyPost::Error.new("Unable to verify address.")
|
54
|
-
end
|
55
|
-
|
56
|
-
return self
|
57
|
-
end
|
58
|
-
end
|
data/lib/easypost/api_key.rb
DELETED
data/lib/easypost/batch.rb
DELETED
@@ -1,49 +0,0 @@
|
|
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)
|
6
|
-
|
7
|
-
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
8
|
-
end
|
9
|
-
|
10
|
-
def buy(params={})
|
11
|
-
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
12
|
-
self.refresh_from(response, @api_key, true)
|
13
|
-
|
14
|
-
return self
|
15
|
-
end
|
16
|
-
|
17
|
-
def label(params={})
|
18
|
-
response = EasyPost.make_request(:post, url + '/label', @api_key, params)
|
19
|
-
self.refresh_from(response, @api_key, true)
|
20
|
-
|
21
|
-
return self
|
22
|
-
end
|
23
|
-
|
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)
|
27
|
-
|
28
|
-
return self
|
29
|
-
end
|
30
|
-
|
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)
|
34
|
-
|
35
|
-
return self
|
36
|
-
end
|
37
|
-
|
38
|
-
def stamp_and_barcode_by_reference(params={})
|
39
|
-
response = EasyPost.make_request(:get, url + '/stamp_and_barcode_by_reference', @api_key, params)
|
40
|
-
|
41
|
-
return response
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_scan_form(params={})
|
45
|
-
response = EasyPost.make_request(:post, url + '/scan_form', @api_key, params)
|
46
|
-
|
47
|
-
return response
|
48
|
-
end
|
49
|
-
end
|
data/lib/easypost/brand.rb
DELETED
data/lib/easypost/error.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
8
|
-
|
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
|
-
|
17
|
-
super(message)
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
"#{code} (#{status}): #{message} #{errors}".strip
|
22
|
-
end
|
23
|
-
|
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
|
30
|
-
end
|
31
|
-
end
|
data/lib/easypost/event.rb
DELETED
data/lib/easypost/insurance.rb
DELETED
data/lib/easypost/object.rb
DELETED
@@ -1,151 +0,0 @@
|
|
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
|
18
|
-
|
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
|
24
|
-
|
25
|
-
def to_s(*args)
|
26
|
-
JSON.dump(@values)
|
27
|
-
end
|
28
|
-
|
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
|
33
|
-
|
34
|
-
def refresh_from(values, api_key, partial=false)
|
35
|
-
@api_key = api_key
|
36
|
-
|
37
|
-
added = Set.new(values.keys - @values.keys)
|
38
|
-
|
39
|
-
instance_eval do
|
40
|
-
add_accessors(added)
|
41
|
-
end
|
42
|
-
|
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)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def [](k)
|
51
|
-
@values[k.to_s]
|
52
|
-
end
|
53
|
-
|
54
|
-
def []=(k, v)
|
55
|
-
send(:"#{k}=", v)
|
56
|
-
end
|
57
|
-
|
58
|
-
def keys
|
59
|
-
@values.keys
|
60
|
-
end
|
61
|
-
|
62
|
-
def values
|
63
|
-
@values.values
|
64
|
-
end
|
65
|
-
|
66
|
-
def to_json(options = {})
|
67
|
-
JSON.dump(@values)
|
68
|
-
end
|
69
|
-
|
70
|
-
def as_json(options = {})
|
71
|
-
@values.as_json
|
72
|
-
end
|
73
|
-
|
74
|
-
def to_hash
|
75
|
-
@values
|
76
|
-
end
|
77
|
-
|
78
|
-
def deconstruct_keys(_keys)
|
79
|
-
@values.transform_keys(&:to_sym)
|
80
|
-
end
|
81
|
-
|
82
|
-
def each(&blk)
|
83
|
-
@values.each(&blk)
|
84
|
-
end
|
85
|
-
|
86
|
-
def id=(id)
|
87
|
-
@values[:id] = id
|
88
|
-
end
|
89
|
-
|
90
|
-
def id
|
91
|
-
@values[:id]
|
92
|
-
end
|
93
|
-
|
94
|
-
protected
|
95
|
-
|
96
|
-
def flatten_unsaved
|
97
|
-
values = {}
|
98
|
-
for key in @unsaved_values
|
99
|
-
value = @values[key]
|
100
|
-
|
101
|
-
values[key] = value
|
102
|
-
|
103
|
-
if value.is_a?(EasyPost::EasyPostObject)
|
104
|
-
values[key] = flatten_unsaved(value)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
return values
|
109
|
-
end
|
110
|
-
|
111
|
-
def metaclass
|
112
|
-
class << self; self; end
|
113
|
-
end
|
114
|
-
|
115
|
-
def remove_accessors(keys)
|
116
|
-
metaclass.instance_eval do
|
117
|
-
keys.each do |k|
|
118
|
-
next if @@immutable_values.include?(k)
|
119
|
-
k_eq = :"#{k}="
|
120
|
-
remove_method(k) if method_defined?(k)
|
121
|
-
remove_method(k_eq) if method_defined?(k_eq)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def add_accessors(keys)
|
127
|
-
metaclass.instance_eval do
|
128
|
-
keys.each do |k|
|
129
|
-
next if @@immutable_values.include?(k)
|
130
|
-
k = k.to_s
|
131
|
-
k_eq = :"#{k}="
|
132
|
-
define_method(k) { @values[k] }
|
133
|
-
define_method(k_eq) do |v|
|
134
|
-
@values[k] = v
|
135
|
-
@unsaved_values.add(k)
|
136
|
-
|
137
|
-
cur = self
|
138
|
-
cur_parent = self.parent
|
139
|
-
while cur_parent
|
140
|
-
if cur.name
|
141
|
-
cur_parent.unsaved_values.add(cur.name)
|
142
|
-
end
|
143
|
-
|
144
|
-
cur = cur_parent
|
145
|
-
cur_parent = cur.parent
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
data/lib/easypost/order.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
class EasyPost::Order < EasyPost::Resource
|
2
|
-
|
3
|
-
def get_rates(params={})
|
4
|
-
response = EasyPost.make_request(:get, url + '/rates', @api_key, params)
|
5
|
-
self.refresh_from(response, @api_key, true)
|
6
|
-
|
7
|
-
return self
|
8
|
-
end
|
9
|
-
|
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
|
17
|
-
|
18
|
-
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
19
|
-
self.refresh_from(response, @api_key, true)
|
20
|
-
|
21
|
-
return self
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.all(filters={}, api_key=nil)
|
25
|
-
raise NotImplementedError.new('Order.all not implemented.')
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/lib/easypost/parcel.rb
DELETED
data/lib/easypost/pickup.rb
DELETED
@@ -1,26 +0,0 @@
|
|
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
|
9
|
-
|
10
|
-
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
11
|
-
self.refresh_from(response, @api_key, true)
|
12
|
-
|
13
|
-
return self
|
14
|
-
end
|
15
|
-
|
16
|
-
def cancel(params={})
|
17
|
-
response = EasyPost.make_request(:post, url + '/cancel', @api_key, params)
|
18
|
-
self.refresh_from(response, @api_key, true)
|
19
|
-
|
20
|
-
return self
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.all(filters={}, api_key=nil)
|
24
|
-
raise NotImplementedError.new('Pickup.all not implemented.')
|
25
|
-
end
|
26
|
-
end
|
data/lib/easypost/pickup_rate.rb
DELETED
data/lib/easypost/print_job.rb
DELETED
data/lib/easypost/printer.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
class EasyPost::Printer < EasyPost::Resource
|
2
|
-
|
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
|
9
|
-
|
10
|
-
def print(params={})
|
11
|
-
if params.instance_of?(EasyPost::PostageLabel)
|
12
|
-
temp = params.clone
|
13
|
-
params = {}
|
14
|
-
params[:postage_label] = temp
|
15
|
-
end
|
16
|
-
|
17
|
-
response = EasyPost.make_request(
|
18
|
-
:post, url + '/print_postage_label', @api_key, params
|
19
|
-
)
|
20
|
-
true
|
21
|
-
rescue
|
22
|
-
false
|
23
|
-
end
|
24
|
-
end
|
data/lib/easypost/rate.rb
DELETED
data/lib/easypost/refund.rb
DELETED
data/lib/easypost/report.rb
DELETED
@@ -1,29 +0,0 @@
|
|
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
|
6
|
-
|
7
|
-
response = EasyPost.make_request(:post, url, api_key, params)
|
8
|
-
return EasyPost::Util.convert_to_easypost_object(response, api_key)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.retrieve(params, api_key=nil)
|
12
|
-
id = if params.is_a?(String)
|
13
|
-
params
|
14
|
-
else
|
15
|
-
params[:id]
|
16
|
-
end
|
17
|
-
|
18
|
-
instance = self.new(id, api_key)
|
19
|
-
instance.refresh
|
20
|
-
return instance
|
21
|
-
end
|
22
|
-
|
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
|
28
|
-
end
|
29
|
-
end
|
data/lib/easypost/resource.rb
DELETED
@@ -1,75 +0,0 @@
|
|
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
|
7
|
-
|
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.)')
|
11
|
-
end
|
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"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
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}")
|
22
|
-
end
|
23
|
-
return "#{self.class.url}/#{CGI.escape(id)}"
|
24
|
-
end
|
25
|
-
|
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
|
31
|
-
|
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
|
36
|
-
|
37
|
-
def self.retrieve(id, api_key=nil)
|
38
|
-
instance = self.new(id, api_key)
|
39
|
-
instance.refresh
|
40
|
-
return instance
|
41
|
-
end
|
42
|
-
|
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
|
49
|
-
|
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] }
|
60
|
-
|
61
|
-
for key in @unsaved_values
|
62
|
-
value = values[key]
|
63
|
-
if value.is_a?(EasyPost::EasyPostObject)
|
64
|
-
values[key] = value.flatten_unsaved
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
wrapped_params = {self.class.class_name => values}
|
69
|
-
|
70
|
-
response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
|
71
|
-
refresh_from(response, api_key)
|
72
|
-
end
|
73
|
-
return self
|
74
|
-
end
|
75
|
-
end
|
data/lib/easypost/scan_form.rb
DELETED
data/lib/easypost/shipment.rb
DELETED
@@ -1,129 +0,0 @@
|
|
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)
|
5
|
-
|
6
|
-
return self
|
7
|
-
end
|
8
|
-
|
9
|
-
def regenerate_rates(params={})
|
10
|
-
response = EasyPost.make_request(:post, url + '/rerate', @api_key, params)
|
11
|
-
self.refresh_from(response, @api_key, true)
|
12
|
-
|
13
|
-
return self
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_smartrates
|
17
|
-
response = EasyPost.make_request(:get, url + '/smartrate', @api_key)
|
18
|
-
|
19
|
-
return response.fetch('result', [])
|
20
|
-
end
|
21
|
-
|
22
|
-
def buy(params={})
|
23
|
-
if params.instance_of?(EasyPost::Rate)
|
24
|
-
temp = params.clone
|
25
|
-
params = {}
|
26
|
-
params[:rate] = temp
|
27
|
-
end
|
28
|
-
|
29
|
-
response = EasyPost.make_request(:post, url + '/buy', @api_key, params)
|
30
|
-
self.refresh_from(response, @api_key, true)
|
31
|
-
|
32
|
-
return self
|
33
|
-
end
|
34
|
-
|
35
|
-
def insure(params={})
|
36
|
-
if params.is_a?(Integer) || params.is_a?(Float)
|
37
|
-
temp = params.clone
|
38
|
-
params = {}
|
39
|
-
params[:amount] = temp
|
40
|
-
end
|
41
|
-
|
42
|
-
response = EasyPost.make_request(:post, url + '/insure', @api_key, params)
|
43
|
-
self.refresh_from(response, @api_key, true)
|
44
|
-
|
45
|
-
return self
|
46
|
-
end
|
47
|
-
|
48
|
-
def refund(params={})
|
49
|
-
response = EasyPost.make_request(:get, url + '/refund', @api_key, params)
|
50
|
-
self.refresh_from(response, @api_key, true)
|
51
|
-
|
52
|
-
return self
|
53
|
-
end
|
54
|
-
|
55
|
-
def print(params={})
|
56
|
-
if params.instance_of?(EasyPost::Printer)
|
57
|
-
return params.print(self.postage_label)
|
58
|
-
end
|
59
|
-
return false
|
60
|
-
end
|
61
|
-
|
62
|
-
def label(params={})
|
63
|
-
if params.is_a?(String)
|
64
|
-
temp = params.clone
|
65
|
-
params = {}
|
66
|
-
params[:file_format] = temp
|
67
|
-
end
|
68
|
-
|
69
|
-
response = EasyPost.make_request(:get, url + '/label', @api_key, params)
|
70
|
-
self.refresh_from(response, @api_key, true)
|
71
|
-
|
72
|
-
return self
|
73
|
-
end
|
74
|
-
|
75
|
-
def lowest_rate(carriers=[], services=[])
|
76
|
-
lowest = nil
|
77
|
-
|
78
|
-
self.get_rates unless self.rates
|
79
|
-
|
80
|
-
carriers = EasyPost::Util.normalize_string_list(carriers)
|
81
|
-
|
82
|
-
negative_carriers = []
|
83
|
-
carriers_copy = carriers.clone
|
84
|
-
carriers_copy.each do |carrier|
|
85
|
-
if carrier[0,1] == '!'
|
86
|
-
negative_carriers << carrier[1..-1]
|
87
|
-
carriers.delete(carrier)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
services = EasyPost::Util.normalize_string_list(services)
|
92
|
-
|
93
|
-
negative_services = []
|
94
|
-
services_copy = services.clone
|
95
|
-
services_copy.each do |service|
|
96
|
-
if service[0,1] == '!'
|
97
|
-
negative_services << service[1..-1]
|
98
|
-
services.delete(service)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
self.rates.each do |k|
|
103
|
-
|
104
|
-
rate_carrier = k.carrier.downcase
|
105
|
-
if carriers.size() > 0 && !carriers.include?(rate_carrier)
|
106
|
-
next
|
107
|
-
end
|
108
|
-
if negative_carriers.size() > 0 && negative_carriers.include?(rate_carrier)
|
109
|
-
next
|
110
|
-
end
|
111
|
-
|
112
|
-
rate_service = k.service.downcase
|
113
|
-
if services.size() > 0 && !services.include?(rate_service)
|
114
|
-
next
|
115
|
-
end
|
116
|
-
if negative_services.size() > 0 && negative_services.include?(rate_service)
|
117
|
-
next
|
118
|
-
end
|
119
|
-
|
120
|
-
if lowest == nil || k.rate.to_f < lowest.rate.to_f
|
121
|
-
lowest = k
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
raise EasyPost::Error.new('No rates found.') if lowest == nil
|
126
|
-
|
127
|
-
return lowest
|
128
|
-
end
|
129
|
-
end
|