easyship 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/CHANGELOG.md +8 -0
- data/README.md +13 -0
- data/lib/easyship/errors/easyship_error.rb +10 -2
- data/lib/easyship/middleware/error_handler_middleware.rb +22 -5
- data/lib/easyship/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c050cd7909443866f9f0365555f577024aa49ce0065be2a961018385409972d
|
4
|
+
data.tar.gz: a827b2cdaa8207b8723f5a7c2b65efba7c6b7f9e10cf16b46ea36f34aebae763
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 959f2149e8e0d3f33ce0592de28df9718a0fb1c24cdb78909acffbdcecbeab71449b29a1000c03589d24616603214f0f9aa0dc05bad67e96ee413b2acad2a25c
|
7
|
+
data.tar.gz: 0ba62b8bf714db84417d4c2abb13e66738b0510dd0f57997c9403cdbfb81e2fa78029fb9b058d07a5ed943bb5eb8a9054be8929f6a7975b816fc59dda360b781
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [v.0.2.0](https://github.com/mmarusyk/easyship/tree/v0.2.0) - 2025-05-04
|
4
|
+
|
5
|
+
### Added
|
6
|
+
- Add response_body and response_header to Easyship::Error
|
7
|
+
- Deprecate body_error by @mmarusyk in https://github.com/mmarusyk/easyship/pull/9
|
8
|
+
- Add badges by @mmarusyk in https://github.com/mmarusyk/easyship/pull/10
|
9
|
+
|
10
|
+
|
3
11
|
## [v0.1.5](https://github.com/mmarusyk/easyship/tree/v0.1.5) - 2025-05-03
|
4
12
|
|
5
13
|
### Fixed
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Easyship
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/easyship)
|
4
|
+
[](https://github.com/mmarusyk/easyship/actions?query=workflow%3ARuby)
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
6
|
+
|
3
7
|
This gem provides a simple client for Easyship, offering accessing to Easyship's
|
4
8
|
shipping, tracking, and logistics services directly from Ruby applications.
|
5
9
|
|
@@ -103,6 +107,15 @@ rescue Easyship::Errors::RateLimitError => e
|
|
103
107
|
end
|
104
108
|
```
|
105
109
|
|
110
|
+
Each error instance provides these methods:
|
111
|
+
|
112
|
+
- `message`: Returns the error message text.
|
113
|
+
- `body_error`: Returns an error details **(Deprecated)**.
|
114
|
+
- `error`: Returns a hash containing original detailed error object from Easyship.
|
115
|
+
- `response_body`: Returns the full response body from the API.
|
116
|
+
- `response_headers`: Returns the HTTP headers from the API response.
|
117
|
+
|
118
|
+
|
106
119
|
### Pagination
|
107
120
|
The `get` method in the `Easyship::Client` class is designed to support pagination seamlessly when interacting with the Easyship API by passing block of code. This method abstracts the complexity of managing pagination logic, allowing you to retrieve all items across multiple pages with a single method call.
|
108
121
|
|
@@ -4,12 +4,20 @@ module Easyship
|
|
4
4
|
module Errors
|
5
5
|
# Represents an error that is raised when an error occurs in the Easyship API.
|
6
6
|
class EasyshipError < StandardError
|
7
|
-
attr_reader :message, :
|
7
|
+
attr_reader :message, :error, :response_body, :response_headers
|
8
8
|
|
9
|
-
def initialize(message: '', body_error: {})
|
9
|
+
def initialize(message: '', body_error: {}, error: {}, response_body: nil, response_headers: {})
|
10
10
|
super(message)
|
11
|
+
@error = error
|
11
12
|
@message = message
|
12
13
|
@body_error = body_error
|
14
|
+
@response_body = response_body
|
15
|
+
@response_headers = response_headers
|
16
|
+
end
|
17
|
+
|
18
|
+
def body_error
|
19
|
+
warn '[DEPRECATION] `body_error` is deprecated. Please use `error` instead.'
|
20
|
+
@body_error
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
@@ -9,20 +9,33 @@ module Easyship
|
|
9
9
|
def on_complete(env)
|
10
10
|
status_code = env[:status].to_i
|
11
11
|
body = response_body(env[:body])
|
12
|
+
headers = env[:response_headers]
|
12
13
|
|
13
|
-
handle_status_code(status_code, body)
|
14
|
+
handle_status_code(status_code, headers, body)
|
14
15
|
end
|
15
16
|
|
16
17
|
private
|
17
18
|
|
18
|
-
def handle_status_code(status_code, body)
|
19
|
+
def handle_status_code(status_code, headers, body)
|
19
20
|
error_class = Easyship::Error.for_status(status_code)
|
20
21
|
|
21
|
-
raise_error(error_class, body) if error_class
|
22
|
+
raise_error(error_class, headers, body) if error_class
|
22
23
|
end
|
23
24
|
|
24
|
-
def raise_error(class_error, body)
|
25
|
-
raise class_error.new(
|
25
|
+
def raise_error(class_error, headers, body)
|
26
|
+
raise class_error.new(
|
27
|
+
message: message(body),
|
28
|
+
body_error: body_error(body),
|
29
|
+
error: build_error(body),
|
30
|
+
response_body: body,
|
31
|
+
response_headers: headers
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_error(body)
|
36
|
+
return default_error unless body.is_a?(Hash)
|
37
|
+
|
38
|
+
body[:error]
|
26
39
|
end
|
27
40
|
|
28
41
|
def body_error(body)
|
@@ -55,6 +68,10 @@ module Easyship
|
|
55
68
|
{ details: body, message: 'Something went wrong.' }
|
56
69
|
end
|
57
70
|
|
71
|
+
def default_error
|
72
|
+
{ details: [], message: 'Something went wrong.' }
|
73
|
+
end
|
74
|
+
|
58
75
|
def response_body(body)
|
59
76
|
JSON.parse(body, symbolize_names: true)
|
60
77
|
rescue JSON::ParserError
|
data/lib/easyship/version.rb
CHANGED