friendly_shipping 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/lib/friendly_shipping/http_client.rb +16 -9
- data/lib/friendly_shipping/services/ship_engine/bad_request_handler.rb +15 -3
- data/lib/friendly_shipping/services/ups_freight/restful_api_error_handler.rb +8 -2
- data/lib/friendly_shipping/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f93318bb2f4351daaf01e93d0046f0056b3ef13fac9f52e4e461823ba513a96
|
4
|
+
data.tar.gz: 5e202a71653f2310800124573a0220ddde35941634f988f9c76e9ecf8cbfa1a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee13674fe1c960e113ba8590c8c348fcc5bfb67bb04c1b28fadc3a1389347ff49609f52a4b1b14334ebd835cf9b0b17654b72eb0244716a3345fd44fb4db7ede
|
7
|
+
data.tar.gz: 3126b5a3463bed9d524e6d52b429783b1f3ac0cb631b8723fec82aa5a02152b5e38d61b89c8c19dadd26e85492c8f5419cf7025e241f39177e1648293de2fddf
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,15 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.6.0] - 2020-03-11
|
8
|
+
|
9
|
+
- Changelog additions missed in previous release
|
10
|
+
|
7
11
|
## [0.5.3] - 2020-03-11
|
8
12
|
|
9
|
-
- UPS Service: Add support for shipping labels / bills of lading
|
13
|
+
- UPS Service: Add support for shipping labels / bills of lading (#92)
|
14
|
+
- UPS/USPS Services: Return ApiFailure instead of a string for failed API responses (#95)
|
15
|
+
- UPS/USPS Services: Refactor ApiFailure to subclass ApiResponse (#96)
|
10
16
|
|
11
17
|
## [0.5.2] - 2020-01-31
|
12
18
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'dry/monads/result'
|
4
|
+
require 'friendly_shipping/api_failure'
|
4
5
|
require 'rest-client'
|
5
6
|
|
6
7
|
module FriendlyShipping
|
@@ -21,19 +22,19 @@ module FriendlyShipping
|
|
21
22
|
|
22
23
|
Success(convert_to_friendly_response(http_response))
|
23
24
|
rescue ::RestClient::Exception => e
|
24
|
-
error_handler.call(e)
|
25
|
+
error_handler.call(e, original_request: request, original_response: e.response)
|
25
26
|
end
|
26
27
|
|
27
|
-
def post(
|
28
|
+
def post(request)
|
28
29
|
http_response = ::RestClient.post(
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
request.url,
|
31
|
+
request.body,
|
32
|
+
request.headers
|
32
33
|
)
|
33
34
|
|
34
35
|
Success(convert_to_friendly_response(http_response))
|
35
36
|
rescue ::RestClient::Exception => e
|
36
|
-
error_handler.call(e)
|
37
|
+
error_handler.call(e, original_request: request, original_response: e.response)
|
37
38
|
end
|
38
39
|
|
39
40
|
def put(request)
|
@@ -45,13 +46,19 @@ module FriendlyShipping
|
|
45
46
|
|
46
47
|
Success(convert_to_friendly_response(http_response))
|
47
48
|
rescue ::RestClient::Exception => e
|
48
|
-
error_handler.call(e)
|
49
|
+
error_handler.call(e, original_request: request, original_response: e.response)
|
49
50
|
end
|
50
51
|
|
51
52
|
private
|
52
53
|
|
53
|
-
def wrap_in_failure(error)
|
54
|
-
Failure(
|
54
|
+
def wrap_in_failure(error, original_request: nil, original_response: nil)
|
55
|
+
Failure(
|
56
|
+
ApiFailure.new(
|
57
|
+
error,
|
58
|
+
original_request: original_request,
|
59
|
+
original_response: original_response
|
60
|
+
)
|
61
|
+
)
|
55
62
|
end
|
56
63
|
|
57
64
|
def convert_to_friendly_response(http_response)
|
@@ -8,11 +8,23 @@ module FriendlyShipping
|
|
8
8
|
class BadRequestHandler
|
9
9
|
extend Dry::Monads::Result::Mixin
|
10
10
|
|
11
|
-
def self.call(error)
|
11
|
+
def self.call(error, original_request: nil, original_response: nil)
|
12
12
|
if error.http_code == 400
|
13
|
-
Failure(
|
13
|
+
Failure(
|
14
|
+
ApiFailure.new(
|
15
|
+
BadRequest.new(error),
|
16
|
+
original_request: original_request,
|
17
|
+
original_response: original_response
|
18
|
+
)
|
19
|
+
)
|
14
20
|
else
|
15
|
-
Failure(
|
21
|
+
Failure(
|
22
|
+
ApiFailure.new(
|
23
|
+
error,
|
24
|
+
original_request: original_request,
|
25
|
+
original_response: original_response
|
26
|
+
)
|
27
|
+
)
|
16
28
|
end
|
17
29
|
end
|
18
30
|
end
|
@@ -6,7 +6,7 @@ module FriendlyShipping
|
|
6
6
|
class RestfulApiErrorHandler
|
7
7
|
extend Dry::Monads::Result::Mixin
|
8
8
|
|
9
|
-
def self.call(error)
|
9
|
+
def self.call(error, original_request: nil, original_response: nil)
|
10
10
|
parsed_json = JSON.parse(error.response.body)
|
11
11
|
errors = parsed_json.dig('response', 'errors')
|
12
12
|
|
@@ -16,7 +16,13 @@ module FriendlyShipping
|
|
16
16
|
[status, desc].compact.join(": ").presence || 'UPS could not process the request.'
|
17
17
|
end.join("\n")
|
18
18
|
|
19
|
-
Failure(
|
19
|
+
Failure(
|
20
|
+
ApiFailure.new(
|
21
|
+
failure_string,
|
22
|
+
original_request: original_request,
|
23
|
+
original_response: original_response
|
24
|
+
)
|
25
|
+
)
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_shipping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Meyerhoff
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: data_uri
|