easypost 4.13.1 → 5.0.1
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 +24 -1
- data/.gitignore +11 -11
- data/CHANGELOG.md +23 -2
- data/Makefile +15 -10
- data/README.md +49 -39
- data/UPGRADE_GUIDE.md +119 -0
- data/VERSION +1 -1
- data/easypost.gemspec +12 -10
- data/lib/easypost/client.rb +129 -0
- data/lib/easypost/connection.rb +2 -4
- data/lib/easypost/constants.rb +15 -0
- data/lib/easypost/errors/api/api_error.rb +106 -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 +31 -0
- data/lib/easypost/http_client.rb +65 -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/{carbon_offset.rb → models/carbon_offset.rb} +1 -1
- data/lib/easypost/models/carrier_account.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/{payload.rb → models/payload.rb} +1 -1
- data/lib/easypost/models/payment_method.rb +5 -0
- data/lib/easypost/models/pickup.rb +9 -0
- data/lib/easypost/{pickup_rate.rb → models/pickup_rate.rb} +1 -1
- data/lib/easypost/{postage_label.rb → models/postage_label.rb} +1 -1
- 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/{tax_identifier.rb → models/tax_identifier.rb} +1 -1
- 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 +35 -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/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 +32 -0
- data/lib/easypost/util.rb +80 -187
- 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.rb +12 -138
- metadata +147 -66
- data/.rubocop.yml +0 -11
- data/easycop.yml +0 -180
- data/lib/easypost/address.rb +0 -55
- data/lib/easypost/api_key.rb +0 -5
- data/lib/easypost/batch.rb +0 -52
- data/lib/easypost/beta/end_shipper.rb +0 -44
- data/lib/easypost/beta/payment_refund.rb +0 -5
- data/lib/easypost/beta/rate.rb +0 -14
- data/lib/easypost/beta/referral.rb +0 -158
- data/lib/easypost/beta.rb +0 -8
- data/lib/easypost/billing.rb +0 -72
- data/lib/easypost/brand.rb +0 -13
- data/lib/easypost/carrier_account.rb +0 -26
- data/lib/easypost/carrier_type.rb +0 -5
- data/lib/easypost/customs_info.rb +0 -9
- data/lib/easypost/customs_item.rb +0 -9
- data/lib/easypost/end_shipper.rb +0 -26
- data/lib/easypost/error.rb +0 -46
- data/lib/easypost/event.rb +0 -38
- data/lib/easypost/insurance.rb +0 -20
- data/lib/easypost/object.rb +0 -171
- data/lib/easypost/order.rb +0 -37
- data/lib/easypost/parcel.rb +0 -9
- data/lib/easypost/payment_method.rb +0 -12
- data/lib/easypost/pickup.rb +0 -47
- data/lib/easypost/rate.rb +0 -9
- data/lib/easypost/referral.rb +0 -117
- data/lib/easypost/refund.rb +0 -19
- data/lib/easypost/report.rb +0 -44
- data/lib/easypost/resource.rb +0 -124
- data/lib/easypost/scan_form.rb +0 -26
- data/lib/easypost/shipment.rb +0 -186
- data/lib/easypost/tracker.rb +0 -43
- data/lib/easypost/user.rb +0 -74
- data/lib/easypost/webhook.rb +0 -57
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# EndShipper objects are fully-qualified Address objects that require all parameters and get verified upon creation.
|
4
|
-
class EasyPost::Beta::EndShipper < EasyPost::Resource
|
5
|
-
# Create an EndShipper object.
|
6
|
-
# <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
|
7
|
-
def self.create(params = {}, api_key = nil)
|
8
|
-
warn '[DEPRECATION] Please use `EndShipper.create` in the main namespace instead.'
|
9
|
-
response = EasyPost.make_request(:post, '/beta/end_shippers', api_key, { address: params })
|
10
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Retrieves an EndShipper object.
|
14
|
-
# <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
|
15
|
-
def self.retrieve(id, params = {}, api_key = nil)
|
16
|
-
warn '[DEPRECATION] Please use `EndShipper.retrieve` in the main namespace instead.'
|
17
|
-
response = EasyPost.make_request(:get, "/beta/end_shippers/#{id}", api_key, params)
|
18
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Retrieves a list of EndShipper objects.
|
22
|
-
# <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
|
23
|
-
def self.all(params = {}, api_key = nil)
|
24
|
-
warn '[DEPRECATION] Please use `EndShipper.all` in the main namespace instead.'
|
25
|
-
response = EasyPost.make_request(:get, '/beta/end_shippers', api_key, params)
|
26
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Updates (saves) an EndShipper object. This requires all parameters to be set.
|
30
|
-
# <b>DEPRECATED:</b> Please use <tt>EndShipper</tt> in the main namespace instead.
|
31
|
-
def save
|
32
|
-
warn '[DEPRECATION] Please use `endShipper.save` in the main namespace instead.'
|
33
|
-
if @unsaved_values.length.positive?
|
34
|
-
values = {}
|
35
|
-
@unsaved_values.each { |k| values[k] = @values[k] }
|
36
|
-
|
37
|
-
wrapped_params = { address: values }
|
38
|
-
|
39
|
-
response = EasyPost.make_request(:put, "/beta/end_shippers/#{id}", @api_key, wrapped_params)
|
40
|
-
refresh_from(response, api_key)
|
41
|
-
end
|
42
|
-
self
|
43
|
-
end
|
44
|
-
end
|
data/lib/easypost/beta/rate.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# A Rate object contains all the details about the rate of a Shipment.
|
4
|
-
class EasyPost::Beta::Rate < EasyPost::Resource
|
5
|
-
# Retrieve a list of stateless rates.
|
6
|
-
def self.retrieve_stateless_rates(params = {}, api_key = nil)
|
7
|
-
wrapped_params = {
|
8
|
-
shipment: params,
|
9
|
-
}
|
10
|
-
|
11
|
-
response = EasyPost.make_request(:post, '/beta/rates', api_key, wrapped_params)
|
12
|
-
EasyPost::Util.convert_to_easypost_object(response['rates'], api_key)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Referral objects are User objects created from a Partner user.
|
4
|
-
class EasyPost::Beta::Referral < EasyPost::Resource
|
5
|
-
class << self
|
6
|
-
protected
|
7
|
-
|
8
|
-
# Retrieve EasyPost's Stripe public API key.
|
9
|
-
def retrieve_easypost_stripe_api_key
|
10
|
-
response = EasyPost.make_request(:get, '/beta/partners/stripe_public_key', @api_key)
|
11
|
-
response['public_key']
|
12
|
-
end
|
13
|
-
|
14
|
-
# Get credit card token from Stripe.
|
15
|
-
def create_stripe_token(number, expiration_month, expiration_year,
|
16
|
-
cvc, easypost_stripe_token)
|
17
|
-
headers = {
|
18
|
-
# This Stripe endpoint only accepts URL form encoded bodies.
|
19
|
-
Authorization: "Bearer #{easypost_stripe_token}",
|
20
|
-
'Content-type': 'application/x-www-form-urlencoded',
|
21
|
-
}
|
22
|
-
|
23
|
-
credit_card_hash = {
|
24
|
-
card: {
|
25
|
-
number: number,
|
26
|
-
exp_month: expiration_month,
|
27
|
-
exp_year: expiration_year,
|
28
|
-
cvc: cvc,
|
29
|
-
},
|
30
|
-
}
|
31
|
-
|
32
|
-
form_encoded_params = EasyPost::Util.form_encode_params(credit_card_hash)
|
33
|
-
|
34
|
-
uri = URI.parse('https://api.stripe.com/v1/tokens')
|
35
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
36
|
-
http.use_ssl = true
|
37
|
-
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
38
|
-
query = URI.encode_www_form(form_encoded_params)
|
39
|
-
|
40
|
-
response = http.request(request, query)
|
41
|
-
response_json = JSON.parse(response.body)
|
42
|
-
response_json['id']
|
43
|
-
end
|
44
|
-
|
45
|
-
# Submit Stripe credit card token to EasyPost.
|
46
|
-
def create_easypost_credit_card(referral_api_key, stripe_object_id, priority = 'primary')
|
47
|
-
wrapped_params = {
|
48
|
-
credit_card: {
|
49
|
-
stripe_object_id: stripe_object_id,
|
50
|
-
priority: priority,
|
51
|
-
},
|
52
|
-
}
|
53
|
-
response = EasyPost.make_request(:post, '/beta/credit_cards', referral_api_key, wrapped_params)
|
54
|
-
EasyPost::Util.convert_to_easypost_object(response, referral_api_key)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Create a referral customer. This function requires the Partner User's API key.
|
59
|
-
# <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
|
60
|
-
def self.create(params = {}, api_key = nil)
|
61
|
-
warn '[DEPRECATION] Please use `Referral.create` in the main namespace instead.'
|
62
|
-
response = EasyPost.make_request(:post, '/beta/referral_customers', api_key, { user: params })
|
63
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Update a referral customer. This function requires the Partner User's API key.
|
67
|
-
# <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
|
68
|
-
def self.update_email(email, user_id, api_key = nil)
|
69
|
-
warn '[DEPRECATION] Please use `Referral.update_email` in the main namespace instead.'
|
70
|
-
wrapped_params = {
|
71
|
-
user: {
|
72
|
-
email: email,
|
73
|
-
},
|
74
|
-
}
|
75
|
-
EasyPost.make_request(:put, "/beta/referral_customers/#{user_id}", api_key, wrapped_params)
|
76
|
-
|
77
|
-
# return true if API succeeds, else an error is throw if it fails.
|
78
|
-
true
|
79
|
-
end
|
80
|
-
|
81
|
-
# Retrieve a list of referral customers. This function requires the Partner User's API key.
|
82
|
-
# <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
|
83
|
-
def self.all(params = {}, api_key = nil)
|
84
|
-
warn '[DEPRECATION] Please use `Referral.all` in the main namespace instead.'
|
85
|
-
response = EasyPost.make_request(:get, '/beta/referral_customers', api_key, params)
|
86
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
87
|
-
end
|
88
|
-
|
89
|
-
# Add credit card to a referral customer. This function requires the Referral Customer's API key.
|
90
|
-
# <b>DEPRECATED:</b> Please use <tt>Referral</tt> in the main namespace instead.
|
91
|
-
def self.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary')
|
92
|
-
warn '[DEPRECATION] Please use `Referral.add_credit_card` in the main namespace instead.'
|
93
|
-
easypost_stripe_api_key = retrieve_easypost_stripe_api_key
|
94
|
-
|
95
|
-
begin
|
96
|
-
stripe_credit_card_token = create_stripe_token(
|
97
|
-
number,
|
98
|
-
expiration_month,
|
99
|
-
expiration_year,
|
100
|
-
cvc,
|
101
|
-
easypost_stripe_api_key,
|
102
|
-
)
|
103
|
-
rescue StandardError
|
104
|
-
raise EasyPost::Error.new('Could not send card details to Stripe, please try again later.')
|
105
|
-
end
|
106
|
-
|
107
|
-
response = create_easypost_credit_card(referral_api_key, stripe_credit_card_token, priority)
|
108
|
-
EasyPost::Util.convert_to_easypost_object(response, referral_api_key)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Add a Stripe payment method to a Referral Customer. This function requires the Referral Customer's API key.
|
112
|
-
# @param [String] stripe_customer_id Unique customer ID provided by Stripe.
|
113
|
-
# @param [String] payment_method_reference ID of the card or bank account provided by Stripe.
|
114
|
-
# @param [String] payment_method_type Which priority to save this payment method as on EasyPost, either 'primary' or 'secondary'.
|
115
|
-
# @param [String] api_key Override the API key used for this request.
|
116
|
-
# @return [EasyPost::PaymentMethod] The newly-added payment method.
|
117
|
-
# noinspection RubyParameterNamingConvention
|
118
|
-
def self.add_payment_method(stripe_customer_id, payment_method_reference, priority = 'primary', api_key = nil)
|
119
|
-
wrapped_params = {
|
120
|
-
payment_method: {
|
121
|
-
stripe_customer_id: stripe_customer_id,
|
122
|
-
payment_method_reference: payment_method_reference,
|
123
|
-
priority: priority.downcase,
|
124
|
-
},
|
125
|
-
}
|
126
|
-
response = EasyPost.make_request(:post, '/beta/referral_customers/payment_method', api_key, wrapped_params)
|
127
|
-
# noinspection RubyMismatchedReturnType
|
128
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
129
|
-
end
|
130
|
-
|
131
|
-
# Refund a Referral Customer's wallet by a specified amount. Refund will be issued to the user's original payment method.
|
132
|
-
# This function requires the Referral Customer's API key.
|
133
|
-
# @param [Integer] amount The amount to refund, in cents.
|
134
|
-
# @param [String] api_key Override the API key used for this request.
|
135
|
-
# @return [EasyPost::Beta::PaymentRefund] The newly-created refund.
|
136
|
-
def self.refund_by_amount(amount, api_key = nil)
|
137
|
-
params = {
|
138
|
-
refund_amount: amount,
|
139
|
-
}
|
140
|
-
response = EasyPost.make_request(:post, '/beta/referral_customers/refunds', api_key, params)
|
141
|
-
# noinspection RubyMismatchedReturnType
|
142
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key) # TODO: Needs "object" or ID prefix to determine object class.
|
143
|
-
end
|
144
|
-
|
145
|
-
# Refund a Referral Customer's wallet for a specified payment log entry. Refund will be issued to the user's original payment method.
|
146
|
-
# This function requires the Referral Customer's API key.
|
147
|
-
# @param [String] payment_log_id Payment log ID to refund.
|
148
|
-
# @param [String] api_key Override the API key used for this request.
|
149
|
-
# @return [EasyPost::Beta::PaymentRefund] The newly-created refund.
|
150
|
-
def self.refund_by_payment_log(payment_log_id, api_key = nil)
|
151
|
-
params = {
|
152
|
-
payment_log_id: payment_log_id,
|
153
|
-
}
|
154
|
-
response = EasyPost.make_request(:post, '/beta/referral_customers/refunds', api_key, params)
|
155
|
-
# noinspection RubyMismatchedReturnType
|
156
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key) # TODO: Needs "object" or ID prefix to determine object class.
|
157
|
-
end
|
158
|
-
end
|
data/lib/easypost/beta.rb
DELETED
data/lib/easypost/billing.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Billing class that users can manage their payment and fund
|
4
|
-
class EasyPost::Billing < EasyPost::Resource
|
5
|
-
class << self
|
6
|
-
protected
|
7
|
-
|
8
|
-
# Get payment method info (type of the payment method and ID of the payment method)
|
9
|
-
def get_payment_method_info(priority)
|
10
|
-
payment_methods = EasyPost::Billing.retrieve_payment_methods
|
11
|
-
payment_method_map = {
|
12
|
-
'primary' => 'primary_payment_method',
|
13
|
-
'secondary' => 'secondary_payment_method',
|
14
|
-
}
|
15
|
-
|
16
|
-
payment_method_to_use = payment_method_map[priority]
|
17
|
-
|
18
|
-
error_string = 'The chosen payment method is not valid. Please try again.'
|
19
|
-
raise EasyPost::Error.new(error_string) if payment_methods[payment_method_to_use].nil?
|
20
|
-
|
21
|
-
payment_method_id = payment_methods[payment_method_to_use]['id']
|
22
|
-
|
23
|
-
unless payment_method_id.nil?
|
24
|
-
if payment_method_id.start_with?('card_')
|
25
|
-
endpoint = '/v2/credit_cards'
|
26
|
-
elsif payment_method_id.start_with?('bank_')
|
27
|
-
endpoint = '/v2/bank_accounts'
|
28
|
-
else
|
29
|
-
raise EasyPost::Error.new(error_string)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
[endpoint, payment_method_id]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Fund your EasyPost wallet by charging your primary or secondary card on file.
|
38
|
-
def self.fund_wallet(amount, priority = 'primary', api_key = nil)
|
39
|
-
payment_info = get_payment_method_info(priority.downcase)
|
40
|
-
endpoint = payment_info[0]
|
41
|
-
payment_id = payment_info[1]
|
42
|
-
|
43
|
-
wrapped_params = { amount: amount }
|
44
|
-
EasyPost.make_request(:post, "#{endpoint}/#{payment_id}/charges", api_key, wrapped_params)
|
45
|
-
|
46
|
-
# Return true if succeeds, an error will be thrown if it fails
|
47
|
-
true
|
48
|
-
end
|
49
|
-
|
50
|
-
# Delete a payment method.
|
51
|
-
def self.delete_payment_method(priority, api_key = nil)
|
52
|
-
payment_info = get_payment_method_info(priority.downcase)
|
53
|
-
endpoint = payment_info[0]
|
54
|
-
payment_id = payment_info[1]
|
55
|
-
|
56
|
-
EasyPost.make_request(:delete, "#{endpoint}/#{payment_id}", api_key)
|
57
|
-
|
58
|
-
# Return true if succeeds, an error will be thrown if it fails
|
59
|
-
true
|
60
|
-
end
|
61
|
-
|
62
|
-
# Retrieve all payment methods.
|
63
|
-
def self.retrieve_payment_methods(api_key = nil)
|
64
|
-
response = EasyPost.make_request(:get, '/v2/payment_methods', api_key)
|
65
|
-
|
66
|
-
if response['id'].nil?
|
67
|
-
raise EasyPost::Error.new('Billing has not been setup for this user. Please add a payment method.')
|
68
|
-
end
|
69
|
-
|
70
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
71
|
-
end
|
72
|
-
end
|
data/lib/easypost/brand.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The Brand object allows you to customize the publicly-accessible html page that shows tracking details for every EasyPost tracker.
|
4
|
-
class EasyPost::Brand < EasyPost::Resource
|
5
|
-
# The url of the Brand object.
|
6
|
-
def url
|
7
|
-
if user_id.nil? || user_id.empty?
|
8
|
-
raise EasyPost::Error, "Missing user_id: #{self.class} instance is missing user_id"
|
9
|
-
end
|
10
|
-
|
11
|
-
"#{::EasyPost::User.url}/#{CGI.escape(user_id)}/brand"
|
12
|
-
end
|
13
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# A CarrierAccount encapsulates your credentials with the carrier.
|
4
|
-
class EasyPost::CarrierAccount < EasyPost::Resource
|
5
|
-
CUSTOM_WORKFLOW_CARRIER_TYPES = %w[UpsAccount FedexAccount].freeze
|
6
|
-
|
7
|
-
# Retrieve a list of available CarrierAccount types for the authenticated User.
|
8
|
-
def self.types
|
9
|
-
EasyPost::CarrierType.all
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.create(params = {}, api_key = nil)
|
13
|
-
wrapped_params = {}
|
14
|
-
wrapped_params[class_name.to_sym] = params
|
15
|
-
|
16
|
-
# For Ups and Fedex the endpoint is different
|
17
|
-
create_url = if CUSTOM_WORKFLOW_CARRIER_TYPES.include?(params[:type])
|
18
|
-
"#{url}/register"
|
19
|
-
else
|
20
|
-
url
|
21
|
-
end
|
22
|
-
|
23
|
-
response = EasyPost.make_request(:post, create_url, api_key, wrapped_params)
|
24
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
25
|
-
end
|
26
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping.
|
4
|
-
class EasyPost::CustomsInfo < EasyPost::Resource
|
5
|
-
# Retrieve a list of CustomsInfo objects
|
6
|
-
def self.all(_filters = {}, _api_key = nil)
|
7
|
-
raise NotImplementedError.new('CustomsInfo.all not implemented.')
|
8
|
-
end
|
9
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object.
|
4
|
-
class EasyPost::CustomsItem < EasyPost::Resource
|
5
|
-
# Retrieve a list of CustomsItem objects
|
6
|
-
def self.all(_filters = {}, _api_key = nil)
|
7
|
-
raise NotImplementedError.new('CustomsItem.all not implemented.')
|
8
|
-
end
|
9
|
-
end
|
data/lib/easypost/end_shipper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# EndShipper objects are fully-qualified Address objects that require all parameters and get verified upon creation.
|
4
|
-
class EasyPost::EndShipper < EasyPost::Resource
|
5
|
-
# Create an EndShipper object.
|
6
|
-
def self.create(params = {}, api_key = nil)
|
7
|
-
response = EasyPost.make_request(:post, url, api_key, { address: params })
|
8
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Updates (saves) an EndShipper object. This requires all parameters to be set.
|
12
|
-
def save
|
13
|
-
if @unsaved_values.length.positive?
|
14
|
-
values = {}
|
15
|
-
@unsaved_values.each { |k| values[k] = @values[k] }
|
16
|
-
|
17
|
-
wrapped_params = { address: values }
|
18
|
-
|
19
|
-
response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
|
20
|
-
refresh_from(response, api_key)
|
21
|
-
end
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
# TODO: Add support for getting the next page of end shippers when the API supports it.
|
26
|
-
end
|
data/lib/easypost/error.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# EasyPost Error object.
|
4
|
-
class EasyPost::Error < StandardError
|
5
|
-
attr_reader :message, :status, :http_body, :code, :errors
|
6
|
-
|
7
|
-
# Initialize a new EasyPost Error
|
8
|
-
def initialize(message = nil, status = nil, code = nil, errors = nil, http_body = nil)
|
9
|
-
# message should be a string but can sometimes incorrectly come back as an array
|
10
|
-
@message = message.is_a?(String) ? message : EasyPost::Error.traverse_json_element(message, [])
|
11
|
-
@status = status
|
12
|
-
@code = code
|
13
|
-
@errors = errors
|
14
|
-
@http_body = http_body
|
15
|
-
|
16
|
-
super(message)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Convert an error to a string.
|
20
|
-
def to_s
|
21
|
-
"#{code} (#{status}): #{message} #{errors}".strip
|
22
|
-
end
|
23
|
-
|
24
|
-
# Compare error properties.
|
25
|
-
def ==(other)
|
26
|
-
other.is_a?(EasyPost::Error) &&
|
27
|
-
message == other.message &&
|
28
|
-
status == other.status &&
|
29
|
-
code == other.code &&
|
30
|
-
errors == other.errors
|
31
|
-
end
|
32
|
-
|
33
|
-
# Recursively traverses a JSON element to extract error messages and returns them as a comma-separated string.
|
34
|
-
def self.traverse_json_element(error_message, messages_list)
|
35
|
-
case error_message
|
36
|
-
when Hash
|
37
|
-
error_message.each_value { |value| traverse_json_element(value, messages_list) }
|
38
|
-
when Array
|
39
|
-
error_message.each { |value| traverse_json_element(value, messages_list) }
|
40
|
-
else
|
41
|
-
messages_list.push(error_message.to_s)
|
42
|
-
end
|
43
|
-
|
44
|
-
messages_list.join(', ')
|
45
|
-
end
|
46
|
-
end
|
data/lib/easypost/event.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
# Webhook Events are triggered by changes in objects you've created via the API.
|
6
|
-
class EasyPost::Event < EasyPost::Resource
|
7
|
-
# Converts a raw webhook event into an EasyPost object.
|
8
|
-
def self.receive(values)
|
9
|
-
EasyPost::Util.convert_to_easypost_object(JSON.parse(values), nil)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Retrieve all payloads for an event.
|
13
|
-
def retrieve_all_payloads(api_key = nil)
|
14
|
-
response = EasyPost.make_request(:get, "#{url}/payloads", api_key)
|
15
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Retrieve a specific payload for an event.
|
19
|
-
def retrieve_payload(payload_id, api_key = nil)
|
20
|
-
response = EasyPost.make_request(:get, "#{url}/payloads/#{payload_id}", api_key)
|
21
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Get the next page of events.
|
25
|
-
def self.get_next_page(collection, page_size = nil)
|
26
|
-
get_next_page_exec(method(:all), collection, collection.events, page_size)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Build the next page parameters.
|
30
|
-
def self.build_next_page_params(_collection, current_page_items, page_size = nil)
|
31
|
-
params = {}
|
32
|
-
params[:before_id] = current_page_items.last.id
|
33
|
-
unless page_size.nil?
|
34
|
-
params[:page_size] = page_size
|
35
|
-
end
|
36
|
-
params
|
37
|
-
end
|
38
|
-
end
|
data/lib/easypost/insurance.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# An Insurance object represents insurance for packages purchased both via the EasyPost API as well
|
4
|
-
# as shipments purchased through third parties and later registered with EasyPost.
|
5
|
-
class EasyPost::Insurance < EasyPost::Resource
|
6
|
-
# Get the next page of insurances.
|
7
|
-
def self.get_next_page(collection, page_size = nil)
|
8
|
-
get_next_page_exec(method(:all), collection, collection.insurances, page_size)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Build the next page parameters.
|
12
|
-
def self.build_next_page_params(_collection, current_page_items, page_size = nil)
|
13
|
-
params = {}
|
14
|
-
params[:before_id] = current_page_items.last.id
|
15
|
-
unless page_size.nil?
|
16
|
-
params[:page_size] = page_size
|
17
|
-
end
|
18
|
-
params
|
19
|
-
end
|
20
|
-
end
|
data/lib/easypost/object.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'set'
|
4
|
-
|
5
|
-
# The EasyPostObject is extended by the EasyPost Resource object.
|
6
|
-
class EasyPost::EasyPostObject
|
7
|
-
include Enumerable
|
8
|
-
|
9
|
-
attr_accessor :parent, :name, :api_key, :unsaved_values
|
10
|
-
|
11
|
-
@@immutable_values = Set.new([:api_key, :id]) # rubocop:disable Style/ClassVars
|
12
|
-
|
13
|
-
# Initialize an EasyPostObject.
|
14
|
-
def initialize(id = nil, api_key = nil, parent = nil, name = nil)
|
15
|
-
@api_key = api_key
|
16
|
-
@values = {}
|
17
|
-
@unsaved_values = Set.new
|
18
|
-
@transient_values = Set.new
|
19
|
-
@parent = parent
|
20
|
-
@name = name
|
21
|
-
self.id = id if id
|
22
|
-
end
|
23
|
-
|
24
|
-
# Construct an object from values.
|
25
|
-
def self.construct_from(values, api_key = nil, parent = nil, name = nil)
|
26
|
-
obj = new(values[:id], api_key, parent, name)
|
27
|
-
obj.refresh_from(values, api_key)
|
28
|
-
obj
|
29
|
-
end
|
30
|
-
|
31
|
-
# Convert to a string.
|
32
|
-
def to_s(*_args)
|
33
|
-
JSON.dump(@values)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Inspect JSON.
|
37
|
-
def inspect
|
38
|
-
id_string = respond_to?(:id) && !id.nil? ? " id=#{id}" : ''
|
39
|
-
"#<#{self.class}:#{id_string}> JSON: " + to_json
|
40
|
-
end
|
41
|
-
|
42
|
-
# Refresh an object from the API.
|
43
|
-
def refresh_from(values, api_key)
|
44
|
-
@api_key = api_key
|
45
|
-
|
46
|
-
added = Set.new(values.keys - @values.keys)
|
47
|
-
|
48
|
-
instance_eval do
|
49
|
-
add_accessors(added)
|
50
|
-
end
|
51
|
-
|
52
|
-
# IDs should never change. But to be safe, only delete if they are different.
|
53
|
-
@values.delete(:id) if values[:id] != @values[:id]
|
54
|
-
|
55
|
-
values.each do |k, v|
|
56
|
-
@values[k.to_s] = EasyPost::Util.convert_to_easypost_object(v, api_key, self, k)
|
57
|
-
@transient_values.delete(k)
|
58
|
-
@unsaved_values.delete(k)
|
59
|
-
end
|
60
|
-
|
61
|
-
return if @values[:id] || (values[:id].nil? && values['id'].nil?)
|
62
|
-
|
63
|
-
@values[:id] = values[:id] || values['id']
|
64
|
-
end
|
65
|
-
|
66
|
-
# Get element of an array.
|
67
|
-
def [](key)
|
68
|
-
@values[key.to_s]
|
69
|
-
end
|
70
|
-
|
71
|
-
# Set the element of an array.
|
72
|
-
def []=(key, value)
|
73
|
-
send(:"#{key}=", value)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Keys of an object.
|
77
|
-
def keys
|
78
|
-
@values.keys
|
79
|
-
end
|
80
|
-
|
81
|
-
# Values of an object.
|
82
|
-
def values
|
83
|
-
@values.values
|
84
|
-
end
|
85
|
-
|
86
|
-
# Make values JSON.
|
87
|
-
def to_json(_options = {})
|
88
|
-
JSON.dump(@values)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Get values as JSON.
|
92
|
-
def as_json(_options = {})
|
93
|
-
@values.as_json
|
94
|
-
end
|
95
|
-
|
96
|
-
# Make values a hash.
|
97
|
-
def to_hash
|
98
|
-
@values
|
99
|
-
end
|
100
|
-
|
101
|
-
# Deconstruct the keys of an object.
|
102
|
-
def deconstruct_keys(_keys)
|
103
|
-
@values.transform_keys(&:to_sym)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Get each element of values.
|
107
|
-
def each(&blk)
|
108
|
-
@values.each(&blk)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Set the ID of an object.
|
112
|
-
def id=(id)
|
113
|
-
@values[:id] = id
|
114
|
-
end
|
115
|
-
|
116
|
-
# Get the ID of an object.
|
117
|
-
def id
|
118
|
-
@values[:id]
|
119
|
-
end
|
120
|
-
|
121
|
-
protected
|
122
|
-
|
123
|
-
# Flatten the unsaved values of an object.
|
124
|
-
def flatten_unsaved
|
125
|
-
values = {}
|
126
|
-
@unsaved_values.each do |key|
|
127
|
-
value = @values[key]
|
128
|
-
|
129
|
-
values[key] = value
|
130
|
-
|
131
|
-
if value.is_a?(EasyPost::EasyPostObject)
|
132
|
-
values[key] = flatten_unsaved(value)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
values
|
137
|
-
end
|
138
|
-
|
139
|
-
# The metaclass of an object.
|
140
|
-
def metaclass
|
141
|
-
class << self; self; end
|
142
|
-
end
|
143
|
-
|
144
|
-
# Add accessors of an object.
|
145
|
-
def add_accessors(keys)
|
146
|
-
metaclass.instance_eval do
|
147
|
-
keys.each do |k|
|
148
|
-
next if @@immutable_values.include?(k)
|
149
|
-
|
150
|
-
k = k.to_s
|
151
|
-
k_eq = :"#{k}="
|
152
|
-
define_method(k) { @values[k] }
|
153
|
-
define_method(k_eq) do |v|
|
154
|
-
@values[k] = v
|
155
|
-
@unsaved_values.add(k)
|
156
|
-
|
157
|
-
cur = self
|
158
|
-
cur_parent = parent
|
159
|
-
while cur_parent
|
160
|
-
if cur.name
|
161
|
-
cur_parent.unsaved_values.add(cur.name)
|
162
|
-
end
|
163
|
-
|
164
|
-
cur = cur_parent
|
165
|
-
cur_parent = cur.parent
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|