easyship 0.1.1 → 0.1.2
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/CHANGELOG.md +11 -0
- data/CONTRIBUTORS.md +3 -0
- data/README.md +13 -4
- data/lib/easyship/middleware/error_handler_middleware.rb +28 -2
- data/lib/easyship/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a715ea30361416f3bc58cee44919e36a7ac7dbe85f1f615c2a74350f889bdef
|
4
|
+
data.tar.gz: 297a361bdad68de29061c1cf6aaa09db8aad1573aa9356c069784b564526ca7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf0c4bded300aa2b72ab47b5ddbd16ba5733c3f515bc403e74322bd4dd5b10b0c9a214aeb629bb257fe0078952b4b5ad0ec4d75e05794666207fcef57d420084
|
7
|
+
data.tar.gz: 394cc54f2400a0f1b86a66340c19e03a42298fe31dc1764ee5c443b8e8fa4e1ddc2af3be5123e2ba4efc781f843c6ab2739481d850d28e83155d178886a8b1a0
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
## [Unreleased]
|
2
|
+
|
3
|
+
## [v0.1.2](https://github.com/mmarusyk/easyship/tree/v0.1.2) - 2024-06-24
|
4
|
+
|
5
|
+
### Features
|
6
|
+
- Handle Handle different responses of errors from Easyship (v1, v2,...) by @mmarusyk in https://github.com/mmarusyk/easyship/pull/3
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- Updated README.md by @mmarusyk in https://github.com/mmarusyk/easyship/pull/2
|
10
|
+
|
11
|
+
|
2
12
|
## [v0.1.1](https://github.com/mmarusyk/easyship/tree/v0.1.1) - 2024-06-08
|
3
13
|
|
4
14
|
### Features
|
5
15
|
- Add pagination cursor by @mmarusyk in https://github.com/mmarusyk/easyship/pull/1
|
6
16
|
|
17
|
+
|
7
18
|
## [v0.1.0](https://github.com/mmarusyk/easyship/tree/v0.1.0) - 2024-06-08
|
8
19
|
|
9
20
|
- Initial release
|
data/CONTRIBUTORS.md
ADDED
data/README.md
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
This gem provides a simple client for Easyship, offering accessing to Easyship's
|
4
4
|
shipping, tracking, and logistics services directly from Ruby applications.
|
5
5
|
|
6
|
+
## Requirements
|
7
|
+
|
8
|
+
Before you begin, ensure you have met the following requirements:
|
9
|
+
|
10
|
+
- Ruby version 3.0.0 or newer. You can check your Ruby version by running `ruby -v`.
|
11
|
+
- Bundler installed. You can install Bundler with `gem install bundler`.
|
12
|
+
|
6
13
|
## Installation
|
7
14
|
|
8
15
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -25,7 +32,7 @@ If you have to use in a ruby file:
|
|
25
32
|
```ruby
|
26
33
|
require 'easyship'
|
27
34
|
|
28
|
-
Easyship
|
35
|
+
Easyship.configure do |c|
|
29
36
|
c.url = 'api_url'
|
30
37
|
c.api_key = 'your_easyship_api_key'
|
31
38
|
end
|
@@ -41,14 +48,16 @@ If you have to use in Rails:
|
|
41
48
|
|
42
49
|
3. Create a new file in `config/initializers` directory
|
43
50
|
```ruby
|
44
|
-
Easyship
|
51
|
+
Easyship.configure do |config|
|
45
52
|
config.url = 'api_url'
|
46
53
|
config.api_key = 'your_easyship_api_key'
|
47
54
|
end
|
48
55
|
```
|
56
|
+
|
49
57
|
Configuration supports the next keys: `url`, `api_key`, `per_page`.
|
50
58
|
|
51
59
|
### Making Requests
|
60
|
+
`Easyship::Client` supports the next methods: `get`, `post`, `put`, `delete`.
|
52
61
|
```ruby
|
53
62
|
Easyship::Client.get('/2023-01/account')
|
54
63
|
```
|
@@ -79,7 +88,7 @@ Easyship::Client.post('/2023-01/shipment', payload)
|
|
79
88
|
```
|
80
89
|
|
81
90
|
### Handle errors
|
82
|
-
|
91
|
+
When using the `easyship` gem in a Rails application, it's important to handle potential errors that may arise during API calls. Here's how you can handle errors gracefully:
|
83
92
|
|
84
93
|
1. Wrap your API calls in a `begin-rescue` block.
|
85
94
|
2. Catch specific errors from the `easyship` gem to handle them accordingly.
|
@@ -120,7 +129,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
120
129
|
|
121
130
|
## Contributing
|
122
131
|
|
123
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/mmarusyk/easyship. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mmarusyk/easyship/blob/main/CODE_OF_CONDUCT.md).
|
132
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mmarusyk/easyship. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mmarusyk/easyship/blob/main/CODE_OF_CONDUCT.md). You can find a list of contributors in the [CONTRIBUTORS.md](https://github.com/mmarusyk/easyship/blob/main/CONTRIBUTORS.md) file.
|
124
133
|
|
125
134
|
## License
|
126
135
|
|
@@ -25,11 +25,37 @@ module Easyship
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def body_error(body)
|
28
|
-
body.is_a?(Hash)
|
28
|
+
return {} unless body.is_a?(Hash)
|
29
|
+
|
30
|
+
if body.key?(:error) && body[:error].is_a?(Hash)
|
31
|
+
format_body_error(body)
|
32
|
+
elsif body.key?(:errors) && body[:errors].is_a?(Array)
|
33
|
+
format_body_errors_array(body)
|
34
|
+
elsif body.key?(:errors)
|
35
|
+
format_body_errors(body)
|
36
|
+
else
|
37
|
+
format_by_default(body)
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
def message(body)
|
32
|
-
body
|
42
|
+
body_error(body)[:message]
|
43
|
+
end
|
44
|
+
|
45
|
+
def format_body_error(body)
|
46
|
+
body[:error]
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_body_errors_array(body)
|
50
|
+
{ details: body[:errors], message: body[:errors].map { |error| error[:message] }.join(', ') }
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_body_errors(body)
|
54
|
+
{ details: body[:errors], message: body[:errors] }
|
55
|
+
end
|
56
|
+
|
57
|
+
def format_by_default(body)
|
58
|
+
{ details: body, message: 'Something went wrong.' }
|
33
59
|
end
|
34
60
|
|
35
61
|
def json?(body)
|
data/lib/easyship/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easyship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Marusyk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- ".rubocop.yml"
|
38
38
|
- CHANGELOG.md
|
39
39
|
- CODE_OF_CONDUCT.md
|
40
|
+
- CONTRIBUTORS.md
|
40
41
|
- LICENSE.txt
|
41
42
|
- README.md
|
42
43
|
- Rakefile
|