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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26a4f14b66c264e247eba786be5a7e7c69e364b15bd82fb3a0b972d3738a2291
4
- data.tar.gz: a602f6940102161c1b6e2e9e8a9714f7cd2e2576f5d4d5e04621d8119d7dbc06
3
+ metadata.gz: 7c050cd7909443866f9f0365555f577024aa49ce0065be2a961018385409972d
4
+ data.tar.gz: a827b2cdaa8207b8723f5a7c2b65efba7c6b7f9e10cf16b46ea36f34aebae763
5
5
  SHA512:
6
- metadata.gz: 2548182a0a00f80abe3096a247f1a85b0878f8ed737f370813e169de5a0db67fc982080fc7650eae22a931f844adfc465566e27cfb331d381744ca53e038693d
7
- data.tar.gz: c5be671de26cefaa90af42d8b5f22ddb32af00e84dcc4ad57db9a8fd193b05902a6b60fdc093968e7781ac523ca066cd322c9a478ea637cf8ca775f79fce329e
6
+ metadata.gz: 959f2149e8e0d3f33ce0592de28df9718a0fb1c24cdb78909acffbdcecbeab71449b29a1000c03589d24616603214f0f9aa0dc05bad67e96ee413b2acad2a25c
7
+ data.tar.gz: 0ba62b8bf714db84417d4c2abb13e66738b0510dd0f57997c9403cdbfb81e2fa78029fb9b058d07a5ed943bb5eb8a9054be8929f6a7975b816fc59dda360b781
data/.rubocop.yml CHANGED
@@ -1,4 +1,5 @@
1
- require:
1
+ plugins:
2
+ - rubocop-rake
2
3
  - rubocop-rspec
3
4
  - rubocop-performance
4
5
 
@@ -8,3 +9,6 @@ AllCops:
8
9
 
9
10
  Style/Copyright:
10
11
  Enabled: false
12
+
13
+ RSpec/ExampleLength:
14
+ Max: 10
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
+ [![Gem Version](https://badge.fury.io/rb/easyship.svg)](https://badge.fury.io/rb/easyship)
4
+ [![Build Status](https://github.com/mmarusyk/easyship/workflows/Ruby/badge.svg)](https://github.com/mmarusyk/easyship/actions?query=workflow%3ARuby)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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, :body_error
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(message: message(body), body_error: body_error(body))
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Easyship
4
- VERSION = '0.1.5'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easyship
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Marusyk