easyship 0.1.1 → 0.1.3

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: 812760f6c36e7f28cbdbf710f5828178f3f983dc99f356fa8382877321d616f6
4
+ data.tar.gz: f3a18b45e2fbf246790b1d0e10dec6d5b2905205833f6b2a436601faa21a557f
5
5
  SHA512:
6
- metadata.gz: fc149787c49b67629702d71bc0bffba4043b2aff2216e46606a2623a0bbaedb4991aa3d7adadc662a2302ca1b05ad1f570eb8d772fc0fdc1af7acf1f5dab0d96
7
- data.tar.gz: 4d602bda8293d6434b3b4e17fba312dfb58792c6cf27b591ef7383613b6eae53d8dcf748fee1ff0a181e32dc618b5cd8e71c12a765dd3f343cc178b910347278
6
+ metadata.gz: 3c1c3673c3ff7516cb39cd7507c6c49564eaf3989b884bc847874b701bc4d77fc9e87d818f99add52b6bc80832db2fe75eb9be0756e6ceb67731cb29831faeba
7
+ data.tar.gz: fb50c604914a06b7aaa73e0105cf053f11be690e352acf4692e5e9bcb4f4a892bfe87abaf30dab16c04d6d767c82d6931960733972d63d835992bea3c3a07134
data/CHANGELOG.md CHANGED
@@ -1,9 +1,25 @@
1
1
  ## [Unreleased]
2
+
3
+ ## [v0.1.3](https://github.com/mmarusyk/easyship/tree/v0.1.3) - 2024-06-27
4
+
5
+ ### Fixed
6
+ - Error from v1 is not handled by @mmarusyk
7
+
8
+ ## [v0.1.2](https://github.com/mmarusyk/easyship/tree/v0.1.2) - 2024-06-24
9
+
10
+ ### Features
11
+ - Handle Handle different responses of errors from Easyship (v1, v2,...) by @mmarusyk in https://github.com/mmarusyk/easyship/pull/3
12
+
13
+ ### Fixed
14
+ - Updated README.md by @mmarusyk in https://github.com/mmarusyk/easyship/pull/2
15
+
16
+
2
17
  ## [v0.1.1](https://github.com/mmarusyk/easyship/tree/v0.1.1) - 2024-06-08
3
18
 
4
19
  ### Features
5
20
  - Add pagination cursor by @mmarusyk in https://github.com/mmarusyk/easyship/pull/1
6
21
 
22
+
7
23
  ## [v0.1.0](https://github.com/mmarusyk/easyship/tree/v0.1.0) - 2024-06-08
8
24
 
9
25
  - 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
 
@@ -7,6 +7,7 @@ module Easyship
7
7
  class Error
8
8
  # rubocop:disable Style::MutableConstant Style::MissingElse
9
9
  ERRORS = {
10
+ 400 => Easyship::Errors::BadRequestError,
10
11
  401 => Easyship::Errors::InvalidTokenError,
11
12
  402 => Easyship::Errors::PaymentRequiredError,
12
13
  404 => Easyship::Errors::ResourceNotFoundError,
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'client_error'
4
+
5
+ module Easyship
6
+ module Errors
7
+ # Raised when Easyship returns the HTTP status code 400
8
+ class BadRequestError < ClientError; end
9
+ end
10
+ end
@@ -25,11 +25,33 @@ 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)
33
+ format_body_errors(body)
34
+ else
35
+ format_by_default(body)
36
+ end
29
37
  end
30
38
 
31
39
  def message(body)
32
- body.is_a?(Hash) ? body[:error][:message] : body
40
+ body_error(body)[:message]
41
+ end
42
+
43
+ def format_body_error(body)
44
+ body[:error]
45
+ end
46
+
47
+ def format_body_errors(body)
48
+ errors = Array(body[:errors])
49
+
50
+ { details: errors, message: errors.join(', ') }
51
+ end
52
+
53
+ def format_by_default(body)
54
+ { details: body, message: 'Something went wrong.' }
33
55
  end
34
56
 
35
57
  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.3'
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.3
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-27 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
@@ -44,6 +45,7 @@ files:
44
45
  - lib/easyship/client.rb
45
46
  - lib/easyship/configuration.rb
46
47
  - lib/easyship/error.rb
48
+ - lib/easyship/errors/bad_request_error.rb
47
49
  - lib/easyship/errors/client_error.rb
48
50
  - lib/easyship/errors/easyship_error.rb
49
51
  - lib/easyship/errors/invalid_token_error.rb
@@ -81,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  requirements: []
84
- rubygems_version: 3.5.9
86
+ rubygems_version: 3.4.10
85
87
  signing_key:
86
88
  specification_version: 4
87
89
  summary: A Ruby client for integrating with Easyship's API for shipping and logistics