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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b78843ee202c13d7e7ffd9fe40f3f6129896959c3ae689070787c9caffbd5d6a
4
- data.tar.gz: 72b3086492a9938697547f90e96d126afe88431c93298dbc198b054d858c490d
3
+ metadata.gz: 0a715ea30361416f3bc58cee44919e36a7ac7dbe85f1f615c2a74350f889bdef
4
+ data.tar.gz: 297a361bdad68de29061c1cf6aaa09db8aad1573aa9356c069784b564526ca7f
5
5
  SHA512:
6
- metadata.gz: fc149787c49b67629702d71bc0bffba4043b2aff2216e46606a2623a0bbaedb4991aa3d7adadc662a2302ca1b05ad1f570eb8d772fc0fdc1af7acf1f5dab0d96
7
- data.tar.gz: 4d602bda8293d6434b3b4e17fba312dfb58792c6cf27b591ef7383613b6eae53d8dcf748fee1ff0a181e32dc618b5cd8e71c12a765dd3f343cc178b910347278
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
@@ -0,0 +1,3 @@
1
+ Contributors to Easyship gem include:
2
+
3
+ * [Michael Marusyk](https://github.com/mmarusyk)
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::Configuration.configure do |c|
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::Configuration.configure do |config|
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
- Then 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:
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) ? body[:error] : {}
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.is_a?(Hash) ? body[:error][:message] : 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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Easyship
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
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.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-08 00:00:00.000000000 Z
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