shipengine_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +305 -0
- data/.rspec +3 -0
- data/.rubocop.yml +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +111 -0
- data/LICENSE.txt +21 -0
- data/README.md +14 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/shipengine/client.rb +71 -0
- data/lib/shipengine/configuration.rb +26 -0
- data/lib/shipengine/constants.rb +203 -0
- data/lib/shipengine/domains/addresses.rb +33 -0
- data/lib/shipengine/domains/batches.rb +103 -0
- data/lib/shipengine/domains/carriers.rb +67 -0
- data/lib/shipengine/domains/carriers_accounts.rb +49 -0
- data/lib/shipengine/domains/labels.rb +94 -0
- data/lib/shipengine/domains/manifests.rb +49 -0
- data/lib/shipengine/domains/package_pickups.rb +49 -0
- data/lib/shipengine/domains/package_types.rb +58 -0
- data/lib/shipengine/domains/rates.rb +49 -0
- data/lib/shipengine/domains/service_points.rb +31 -0
- data/lib/shipengine/domains/shipments.rb +103 -0
- data/lib/shipengine/domains/shipsurance.rb +49 -0
- data/lib/shipengine/domains/tags.rb +49 -0
- data/lib/shipengine/domains/tokens.rb +22 -0
- data/lib/shipengine/domains/tracking.rb +40 -0
- data/lib/shipengine/domains/warehouses.rb +58 -0
- data/lib/shipengine/domains/webhooks.rb +58 -0
- data/lib/shipengine/domains.rb +19 -0
- data/lib/shipengine/enums/address_residential_indicator_types.rb +20 -0
- data/lib/shipengine/enums/address_status.rb +34 -0
- data/lib/shipengine/enums/batch_status.rb +34 -0
- data/lib/shipengine/enums/carriers_names.rb +91 -0
- data/lib/shipengine/enums/label_status.rb +22 -0
- data/lib/shipengine/enums/message_types.rb +30 -0
- data/lib/shipengine/enums/validate_address_types.rb +19 -0
- data/lib/shipengine/enums/webhooks_types.rb +52 -0
- data/lib/shipengine/enums.rb +9 -0
- data/lib/shipengine/errors/error_code.rb +224 -0
- data/lib/shipengine/errors/error_source.rb +39 -0
- data/lib/shipengine/errors/error_type.rb +49 -0
- data/lib/shipengine/exceptions.rb +79 -0
- data/lib/shipengine/faraday/raise_http_exception.rb +83 -0
- data/lib/shipengine/utils/validate.rb +102 -0
- data/lib/shipengine/utils.rb +3 -0
- data/lib/shipengine/version.rb +7 -0
- data/lib/shipengine.rb +26 -0
- data/shipengine.gemspec +41 -0
- metadata +249 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Enums
|
5
|
+
module CarrierNames
|
6
|
+
ACCESS_WORLDWIDE = "access_worldwide"
|
7
|
+
|
8
|
+
AMAZON_BUY_SHIPPING = "amazon_buy_shipping"
|
9
|
+
|
10
|
+
AMAZON_SHIPPING_UK = "amazon_shipping_uk"
|
11
|
+
|
12
|
+
APC = "apc"
|
13
|
+
|
14
|
+
ASENDIA = "asendia"
|
15
|
+
|
16
|
+
AUSTRALIA_POST = "australia_post"
|
17
|
+
|
18
|
+
CANADA_POST = "canada_post"
|
19
|
+
|
20
|
+
DHL_ECOMMERCE = "dhl_ecommerce"
|
21
|
+
|
22
|
+
DHL_EXPRESS = "dhl_express"
|
23
|
+
|
24
|
+
DHL_EXPRESS_AU = "dhl_express_au"
|
25
|
+
|
26
|
+
DHL_EXPRESS_CA = "dhl_express_ca"
|
27
|
+
|
28
|
+
DHL_EXPRESS_UK = "dhl_express_uk"
|
29
|
+
|
30
|
+
DPD = "dpd"
|
31
|
+
|
32
|
+
ENDICIA = "endicia"
|
33
|
+
|
34
|
+
FEDEX = "fedex"
|
35
|
+
|
36
|
+
FEDEX_UK = "fedex_uk"
|
37
|
+
|
38
|
+
FIRSTMILE = "firstmile"
|
39
|
+
|
40
|
+
IMEX = "imex"
|
41
|
+
|
42
|
+
NEWGISTICS = "newgistics"
|
43
|
+
|
44
|
+
ONTRAC = "ontrac"
|
45
|
+
|
46
|
+
PUROLATOR_CANADA = "purolator_canada"
|
47
|
+
|
48
|
+
ROYAL_MAIL = "royal_mail"
|
49
|
+
|
50
|
+
RR_DONNELLEY = "rr_donnelley"
|
51
|
+
|
52
|
+
SEKO = "seko"
|
53
|
+
|
54
|
+
SENDLE = "sendle"
|
55
|
+
|
56
|
+
STAMPS_COM = "stamps_com"
|
57
|
+
|
58
|
+
UPS = "ups"
|
59
|
+
|
60
|
+
ALL = [
|
61
|
+
ACCESS_WORLDWIDE,
|
62
|
+
AMAZON_BUY_SHIPPING,
|
63
|
+
AMAZON_SHIPPING_UK,
|
64
|
+
APC,
|
65
|
+
ASENDIA,
|
66
|
+
AUSTRALIA_POST,
|
67
|
+
CANADA_POST,
|
68
|
+
DHL_ECOMMERCE,
|
69
|
+
DHL_EXPRESS,
|
70
|
+
DHL_EXPRESS_AU,
|
71
|
+
DHL_EXPRESS_CA,
|
72
|
+
DHL_EXPRESS_UK,
|
73
|
+
DPD,
|
74
|
+
ENDICIA,
|
75
|
+
FEDEX,
|
76
|
+
FEDEX_UK,
|
77
|
+
FIRSTMILE,
|
78
|
+
IMEX,
|
79
|
+
NEWGISTICS,
|
80
|
+
ONTRAC,
|
81
|
+
PUROLATOR_CANADA,
|
82
|
+
ROYAL_MAIL,
|
83
|
+
RR_DONNELLEY,
|
84
|
+
SEKO,
|
85
|
+
SENDLE,
|
86
|
+
STAMPS_COM,
|
87
|
+
UPS,
|
88
|
+
].freeze
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Enums
|
5
|
+
module LabelStatus
|
6
|
+
PROCESSING = "processing"
|
7
|
+
|
8
|
+
COMPLETED = "completed"
|
9
|
+
|
10
|
+
ERROR = "error"
|
11
|
+
|
12
|
+
VOIDED = "voided"
|
13
|
+
|
14
|
+
ALL = [
|
15
|
+
PROCESSING,
|
16
|
+
COMPLETED,
|
17
|
+
ERROR,
|
18
|
+
VOIDED,
|
19
|
+
].freeze
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Enums
|
5
|
+
module MessageStatus
|
6
|
+
#
|
7
|
+
# Info messages will describe the partial or complete level of accuracy available for the Address Validation.
|
8
|
+
#
|
9
|
+
INFO = "info"
|
10
|
+
|
11
|
+
#
|
12
|
+
# Warning messages will usually consist of significant changes* or
|
13
|
+
# additions to the data that was provided in the request
|
14
|
+
#
|
15
|
+
WARNING = "warning"
|
16
|
+
|
17
|
+
#
|
18
|
+
# Error messages will usually describe a portion of the data sent in the request,
|
19
|
+
# that could not be validated with any measure of accuracy
|
20
|
+
#
|
21
|
+
ERROR = "error"
|
22
|
+
|
23
|
+
ALL = [
|
24
|
+
INFO,
|
25
|
+
WARNING,
|
26
|
+
ERROR,
|
27
|
+
].freeze
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Enums
|
5
|
+
module ValidateAddress
|
6
|
+
NO_VALIDATION = "no_validation"
|
7
|
+
|
8
|
+
VALIDATE_ONLY = "validate_only"
|
9
|
+
|
10
|
+
VALIDATE_AND_CLEAN = "validate_and_clean"
|
11
|
+
|
12
|
+
ALL = [
|
13
|
+
NO_VALIDATION,
|
14
|
+
VALIDATE_ONLY,
|
15
|
+
VALIDATE_AND_CLEAN,
|
16
|
+
].freeze
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Enums
|
5
|
+
module WebhooksTypes
|
6
|
+
##
|
7
|
+
# Batch completed
|
8
|
+
# #/
|
9
|
+
API_BATCH = "batch"
|
10
|
+
|
11
|
+
##
|
12
|
+
# Shipment rate updated
|
13
|
+
# #/
|
14
|
+
API_RATE = "rate"
|
15
|
+
|
16
|
+
##
|
17
|
+
# Any tracking event
|
18
|
+
# #/
|
19
|
+
API_TRACK = "track"
|
20
|
+
|
21
|
+
##
|
22
|
+
# Carrier connected
|
23
|
+
# #/
|
24
|
+
API_CARRIER_CONNECTED = "carrier_connected"
|
25
|
+
|
26
|
+
##
|
27
|
+
# Sales Orders imported (Beta)
|
28
|
+
# #/
|
29
|
+
API_SALES_ORDERS_IMPORTED = "sales_orders_imported"
|
30
|
+
|
31
|
+
##
|
32
|
+
# Order Source refresh complete (Beta)
|
33
|
+
# #/
|
34
|
+
API_ORDER_SOURCE_REFRESH_COMPLETE = "order_source_refresh_complete"
|
35
|
+
|
36
|
+
##
|
37
|
+
# A requested report is ready
|
38
|
+
# #/
|
39
|
+
API_REPORT_COMPLETE = "report_complete"
|
40
|
+
|
41
|
+
ALL = [
|
42
|
+
API_BATCH,
|
43
|
+
API_RATE,
|
44
|
+
API_TRACK,
|
45
|
+
API_CARRIER_CONNECTED,
|
46
|
+
API_SALES_ORDERS_IMPORTED,
|
47
|
+
API_ORDER_SOURCE_REFRESH_COMPLETE,
|
48
|
+
API_REPORT_COMPLETE,
|
49
|
+
].freeze
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "shipengine/enums/address_residential_indicator_types"
|
4
|
+
require "shipengine/enums/address_status"
|
5
|
+
require "shipengine/enums/batch_status"
|
6
|
+
require "shipengine/enums/carriers_names"
|
7
|
+
require "shipengine/enums/label_status"
|
8
|
+
require "shipengine/enums/message_types"
|
9
|
+
require "shipengine/enums/webhooks_types"
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Errors
|
5
|
+
##
|
6
|
+
## This class has the ability to return a specific error code.
|
7
|
+
##
|
8
|
+
## @see https://www.shipengine.com/docs/errors/codes/#error-code
|
9
|
+
# #/
|
10
|
+
class ErrorCode
|
11
|
+
# @param [Symbol | String] key
|
12
|
+
# @return [String] error type
|
13
|
+
def self.get(key)
|
14
|
+
@codes[key.upcase.to_sym]
|
15
|
+
end
|
16
|
+
|
17
|
+
@codes = {
|
18
|
+
##
|
19
|
+
# Only certain carriers support pre-paid balances.
|
20
|
+
# So you can only add funds to those carriers.
|
21
|
+
# If you attempt to add funds to a carrier that doesn't support it, then you'll get this error code.
|
22
|
+
# #/
|
23
|
+
AUTO_FUND_NOT_SUPPORTED: "auto_fund_not_supported",
|
24
|
+
|
25
|
+
##
|
26
|
+
# Once a batch has started [processing]/reference/process-batch),
|
27
|
+
# it cannot be modified. Attempting to modify it will cause this error.
|
28
|
+
# #/
|
29
|
+
BATCH_CANNOT_BE_MODIFIED: "batch_cannot_be_modified",
|
30
|
+
|
31
|
+
##
|
32
|
+
# You attempted to perform an operation on multiple shipments from different carriers.
|
33
|
+
# Try performing separate operations for each carrier instead.
|
34
|
+
# #/
|
35
|
+
CARRIER_CONFLICT: "carrier_conflict",
|
36
|
+
|
37
|
+
##
|
38
|
+
# This error means that you're trying to use a carrier that hasn't been setup yet.
|
39
|
+
# You can setup carriers from your ShipEngine dashboard, or via the API.
|
40
|
+
# #/
|
41
|
+
CARRIER_NOT_CONNECTED: "carrier_not_connected",
|
42
|
+
|
43
|
+
##
|
44
|
+
# The operation you are performing isn't supported by the specified carrier.
|
45
|
+
# #/
|
46
|
+
CARRIER_NOT_SUPPORTED: "carrier_not_supported",
|
47
|
+
|
48
|
+
##
|
49
|
+
# Some forms of delivery confirmation aren't supported by some carriers.
|
50
|
+
# This error means that the combination of carrier and delivery confirmation are not supported.
|
51
|
+
# #/
|
52
|
+
CONFIRMATION_NOT_SUPPORTED: "confirmation_not_supported",
|
53
|
+
|
54
|
+
##
|
55
|
+
# This error means that two or more fields in your API request are mutually exclusive or
|
56
|
+
# contain conflicting values. The error will include a fields array that lists the conflicting fields.
|
57
|
+
# #/
|
58
|
+
FIELD_CONFLICT: "field_conflict",
|
59
|
+
|
60
|
+
##
|
61
|
+
# A required field is missing or empty. The field_name property indicates which field is missing.
|
62
|
+
# Note that some fields are conditionally required, based on the values of other fields or
|
63
|
+
# the type of operation being performed.
|
64
|
+
# #/
|
65
|
+
FIELD_VALUE_REQUIRED: "field_value_required",
|
66
|
+
|
67
|
+
##
|
68
|
+
# You attempted to perform an operation that you don't have permissions to do.
|
69
|
+
# Check your API key to ensure that you're using the correct one.
|
70
|
+
# Or contact our support team to ensure that your account has the necessary permissions.
|
71
|
+
# #/
|
72
|
+
FORBIDDEN: "forbidden",
|
73
|
+
|
74
|
+
##
|
75
|
+
# A few parts of the ShipEngine API allow you to provide your own ID for resources.
|
76
|
+
# These IDs must be unique; otherwise, you'll get this error code.
|
77
|
+
# #/
|
78
|
+
IDENTIFIER_CONFLICT: "identifier_conflict",
|
79
|
+
|
80
|
+
##
|
81
|
+
# When updating a resource (such as a [shipment](/reference/update-shipment or warehouse),
|
82
|
+
# the ID in the URL and in the request body must match.
|
83
|
+
# #/
|
84
|
+
IDENTIFIERS_MUST_MATCH: "identifiers_must_match",
|
85
|
+
|
86
|
+
##
|
87
|
+
# When creating a return label, you can optionally pair it to an outbound_label_id.
|
88
|
+
# The outbound label must be from the same carrier as the return label.
|
89
|
+
# #/
|
90
|
+
INCOMPATIBLE_PAIRED_LABELS: "incompatible_paired_labels",
|
91
|
+
|
92
|
+
##
|
93
|
+
# The mailing address that you provided is invalid.
|
94
|
+
# Try using our address validation API to verify addresses before using them.
|
95
|
+
# #/
|
96
|
+
INVALID_ADDRESS: "invalid_address",
|
97
|
+
|
98
|
+
##
|
99
|
+
# You attempted to perform an operation that isn't allowed for your billing plan.
|
100
|
+
# Contact our sales team for assistance.
|
101
|
+
# #/
|
102
|
+
INVALID_BILLING_PLAN: "invalid_billing_plan",
|
103
|
+
|
104
|
+
##
|
105
|
+
# When creating a label or creating a return label,
|
106
|
+
# if you set the charge_event field to a value that isn't offered by the carrier,
|
107
|
+
# then you will receive this error. You can leave the charge_event field unset,
|
108
|
+
# or set it to carrier_default instead.
|
109
|
+
# #/
|
110
|
+
INVALID_CHARGE_EVENT: "invalid_charge_event",
|
111
|
+
|
112
|
+
##
|
113
|
+
# One of the fields in your API request has an invalid value.
|
114
|
+
# The field_name property indicates which field is invalid.
|
115
|
+
# #/
|
116
|
+
INVALID_FIELD_VALUE: "invalid_field_value",
|
117
|
+
|
118
|
+
##
|
119
|
+
# This error is similar to invalid_field_value, but is specifically for ID fields,
|
120
|
+
# such as label_id, shipment_id, carrier_id, etc. The field_name property indicates which field is invalid.
|
121
|
+
# #/
|
122
|
+
INVALID_IDENTIFIER: "invalid_identifier",
|
123
|
+
|
124
|
+
##
|
125
|
+
# The operation you're attempting to perform is not allowed because the resource is in the wrong status.
|
126
|
+
# For example, if a label's status is "voided", then it cannot be included in a manifest.
|
127
|
+
# #/
|
128
|
+
INVALID_STATUS: "invalid_status",
|
129
|
+
|
130
|
+
##
|
131
|
+
# A string field in your API request is either too short or too long.
|
132
|
+
# The field_name property indicates which field is invalid,
|
133
|
+
# and the min_length and max_length properties indicate the allowed length.
|
134
|
+
# #/
|
135
|
+
INVALID_STRING_LENGTH: "invalid_string_length",
|
136
|
+
|
137
|
+
##
|
138
|
+
# Not all carriers allow you to add custom images to labels.
|
139
|
+
# You can only set the label_image_id for supported carriers
|
140
|
+
# #/
|
141
|
+
LABEL_IMAGES_NOT_SUPPORTED: "label_images_not_supported",
|
142
|
+
|
143
|
+
##
|
144
|
+
# This error indicates a problem with your FedEx account.
|
145
|
+
# Please contact FedEx to resolve the issue.
|
146
|
+
# #/
|
147
|
+
METER_FAILURE: "meter_failure",
|
148
|
+
|
149
|
+
##
|
150
|
+
# You have exceeded a rate limit.
|
151
|
+
# Check the the error_source field to determine whether the rate limit was imposed by ShipEngine or
|
152
|
+
# by a third-party, such as a carrier. If the rate limit is from ShipEngine,
|
153
|
+
# then consider using bulk operations to reduce the number of API calls,
|
154
|
+
# or contact our support team about increasing your rate limit.
|
155
|
+
# #/
|
156
|
+
RATE_LIMIT_EXCEEDED: "rate_limit_exceeded",
|
157
|
+
|
158
|
+
##
|
159
|
+
# The API call requires a JSON request body.
|
160
|
+
# See the corresponding documentation page for details about the request structure.
|
161
|
+
# #/
|
162
|
+
REQUEST_BODY_REQUIRED: "request_body_required",
|
163
|
+
|
164
|
+
##
|
165
|
+
# You may receive this error if you attempt to schedule a pickup for a return label.
|
166
|
+
# #/
|
167
|
+
RETURN_LABEL_NOT_SUPPORTED: "return_label_not_supported",
|
168
|
+
|
169
|
+
##
|
170
|
+
# You may receive this error if you attempt to perform an operation that requires a subscription.
|
171
|
+
# Please contact our sales department to discuss a ShipEngine enterprise contract.
|
172
|
+
# #/
|
173
|
+
SUBSCRIPTION_INACTIVE: "subscription_inactive",
|
174
|
+
|
175
|
+
##
|
176
|
+
# Some carriers require you to accept their terms and conditions before you can use them via ShipEngine.
|
177
|
+
# If you get this error, then please login to the ShipEngine dashboard to read and accept the carrier's terms.
|
178
|
+
# #/
|
179
|
+
TERMS_NOT_ACCEPTED: "terms_not_accepted",
|
180
|
+
|
181
|
+
##
|
182
|
+
# This error will occur if you attempt to track a package for a carrier that doesn't offer that service.
|
183
|
+
# #/
|
184
|
+
TRACKING_NOT_SUPPORTED: "tracking_not_supported",
|
185
|
+
|
186
|
+
##
|
187
|
+
# You may receive this error if your free trial period has expired and
|
188
|
+
# you have not upgraded your account or added billing information.
|
189
|
+
# #/
|
190
|
+
TRIAL_EXPIRED: "trial_expired",
|
191
|
+
|
192
|
+
##
|
193
|
+
# Your API key is incorrect, expired, or missing.
|
194
|
+
# Check our authentication guide to learn more about authentication with ShipEngine.
|
195
|
+
# #/
|
196
|
+
UNAUTHORIZED: "unauthorized",
|
197
|
+
|
198
|
+
##
|
199
|
+
# This error has not yet been assigned a code.
|
200
|
+
# See the notes above about how to handle these.
|
201
|
+
# #/
|
202
|
+
UNSPECIFIED: "unspecified",
|
203
|
+
|
204
|
+
##
|
205
|
+
# When verifying your account (by email, SMS, phone call, etc.) this error indicates that
|
206
|
+
# the verification code is incorrect. Please re-start the verification process to get a new code.
|
207
|
+
# #/
|
208
|
+
VERIFICATION_FAILURE: "verification_failure",
|
209
|
+
|
210
|
+
##
|
211
|
+
# You attempted to perform an operation on multiple shipments from different warehouses.
|
212
|
+
# Try performing separate operations for each warehouse instead.
|
213
|
+
# #/
|
214
|
+
WAREHOUSE_CONFLICT: "warehouse_conflict",
|
215
|
+
|
216
|
+
##
|
217
|
+
# ShipEngine only allows you to have one webhook of each type.
|
218
|
+
# If you would like to replace a webhook with a new one, please delete the old one first.
|
219
|
+
# #/
|
220
|
+
WEBHOOK_EVENT_TYPE_CONFLICT: "webhook_event_type_conflict",
|
221
|
+
}.freeze
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Errors
|
5
|
+
##
|
6
|
+
## This class has the ability to return a specific error source.
|
7
|
+
##
|
8
|
+
## @see https://www.shipengine.com/docs/errors/codes/#error-source
|
9
|
+
# #/
|
10
|
+
class ErrorSource
|
11
|
+
# @param [Symbol | String] key
|
12
|
+
# @return [String] error type
|
13
|
+
def self.get(key)
|
14
|
+
@sources[key.upcase.to_sym] || @sources[:SHIPENGINE]
|
15
|
+
end
|
16
|
+
|
17
|
+
@sources = {
|
18
|
+
##
|
19
|
+
# The error is from ShipEngine. If you have any questions or require support, please contact us
|
20
|
+
# #/
|
21
|
+
SHIPENGINE: "shipengine",
|
22
|
+
|
23
|
+
##
|
24
|
+
# The error came from a shipping carrier (such as UPS, FedEx, DHL, etc).
|
25
|
+
# ShipEngine support may be able to help clarify the error for you,
|
26
|
+
# but if the problem is with your carrier account, then you will need to contact them directly.
|
27
|
+
# #/
|
28
|
+
CARRIER: "carrier",
|
29
|
+
|
30
|
+
##
|
31
|
+
# The error came from an order source (such as Shopify, Ebay, WalMart, etc).
|
32
|
+
# ShipEngine support may be able to help clarify the error for you,
|
33
|
+
# but if the problem is with your seller account, then you will need to contact them directly.
|
34
|
+
# #/
|
35
|
+
ORDER_SOURCE: "order_source",
|
36
|
+
}.freeze
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Errors
|
5
|
+
##
|
6
|
+
## This class has the ability to return a specific error type.
|
7
|
+
# #/
|
8
|
+
class ErrorType
|
9
|
+
# @param [Symbol | String] key
|
10
|
+
# @return [String] error type
|
11
|
+
def self.get(key)
|
12
|
+
@types[key.upcase.to_sym]
|
13
|
+
end
|
14
|
+
|
15
|
+
@types = {
|
16
|
+
# There is a problem with your account. This may be your ShipEngine account
|
17
|
+
# or a third-party account. See the the error source to determine which
|
18
|
+
# account needs your attention.
|
19
|
+
ACCOUNT_STATUS: "account_status",
|
20
|
+
|
21
|
+
# There was a business rule violation. Business rules are requirements or
|
22
|
+
# limitations of a system. If the error source is ShipEngine, then please
|
23
|
+
# read the relevant documentation to find out what limitations or requirements
|
24
|
+
# apply. Or contact our support for help. If the error source is the carrier
|
25
|
+
# or order source, then ShipEngine support may still be able to help clarify
|
26
|
+
# the problem or propose a solution, or you may need to contact the third-party
|
27
|
+
# for assistance.
|
28
|
+
BUSINESS_RULES: "business_rules",
|
29
|
+
|
30
|
+
# Something is wrong with the input provided, such as missing a required field,
|
31
|
+
# or an illegal value or combination of values. This error type always means
|
32
|
+
# that some change needs to be made to the input before retrying.
|
33
|
+
VALIDATION: "validation",
|
34
|
+
|
35
|
+
# A security error will occur if your API key is invalid or expired, or if
|
36
|
+
# you attempt to perform an operation that is not permitted for your account.
|
37
|
+
SECURITY: "security",
|
38
|
+
|
39
|
+
# An unknown or unexpected error occurred in our system. Or an error occurred
|
40
|
+
# that has not yet been assigned a specific error_type. If you receive
|
41
|
+
# persistent system errors, then please contact our support or check our API
|
42
|
+
# status page to see if there's a known issue.
|
43
|
+
SYSTEM: "system",
|
44
|
+
|
45
|
+
INTEGRATIONS: "integrations",
|
46
|
+
}.freeze
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "shipengine/errors/error_code"
|
4
|
+
require "shipengine/errors/error_source"
|
5
|
+
require "shipengine/errors/error_type"
|
6
|
+
|
7
|
+
module ShipEngine
|
8
|
+
module Exceptions
|
9
|
+
class ShipEngineError < StandardError
|
10
|
+
# message is inherited
|
11
|
+
attr_reader :source, :type, :code, :url
|
12
|
+
|
13
|
+
def initialize(message:, source:, type:, code:, url: nil)
|
14
|
+
code = ShipEngine::Errors::ErrorCode.get(code) if code.is_a?(String)
|
15
|
+
source = ShipEngine::Errors::ErrorSource.get(source) if source.is_a?(String)
|
16
|
+
super(message)
|
17
|
+
@source = source
|
18
|
+
@type = type
|
19
|
+
@code = code
|
20
|
+
@url = url
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
# only create custom errors for error "types" (which encompass codes). Prefer to use generic ShipEngine errors.
|
26
|
+
def invalid_field_value_error(message:)
|
27
|
+
ValidationError.new(
|
28
|
+
message: message,
|
29
|
+
code: ShipEngine::Errors::ErrorCode.get(:INVALID_FIELD_VALUE)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def required_error(field_name:)
|
34
|
+
ValidationError.new(
|
35
|
+
message: "#{field_name} must be specified.",
|
36
|
+
code: ShipEngine::Errors::ErrorCode.get(:FIELD_VALUE_REQUIRED)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# 400 error, or other "user exceptions"
|
42
|
+
class ValidationError < ShipEngineError
|
43
|
+
def initialize(message:, code:, source: nil)
|
44
|
+
super(
|
45
|
+
code: code,
|
46
|
+
source: source,
|
47
|
+
message: message,
|
48
|
+
type: ShipEngine::Errors::ErrorType.get(:VALIDATION),
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class SystemError < ShipEngineError
|
54
|
+
def initialize(message:, code:, source: nil, url: nil)
|
55
|
+
super(
|
56
|
+
url: url,
|
57
|
+
code: code,
|
58
|
+
source: source,
|
59
|
+
message: message,
|
60
|
+
type: ShipEngine::Errors::ErrorType.get(:SYSTEM),
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class RateLimitError < SystemError
|
66
|
+
attr_reader :retries
|
67
|
+
|
68
|
+
def initialize(retries: nil, message: "You have exceeded the rate limit.", source: nil)
|
69
|
+
super(
|
70
|
+
message: message,
|
71
|
+
code: ShipEngine::Errors::ErrorCode.get(:RATE_LIMIT_EXCEEDED),
|
72
|
+
source: source,
|
73
|
+
url: URI("https://www.shipengine.com/docs/rate-limits"),
|
74
|
+
)
|
75
|
+
@retries = retries
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|