shipengine_ruby 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6315cc92d9570601b5ef7cc4af4fe897fc9c46d0d3811b9afa38f5c7f5837448
4
- data.tar.gz: c8da6af5d9f58df59e17df17e76aead80aaa6d4df67a22216df09be3c7f1731a
3
+ metadata.gz: 623cec2a7f40bf13f4f6094812d11e4b5a929bf8ce81f67a8472493fdef3bd6d
4
+ data.tar.gz: 84cd4bf666bb3c72f89b3c0a051ba2362e41bfe07092f90c3234700877491b3d
5
5
  SHA512:
6
- metadata.gz: 218bd9c247ce4d89c80d842f1fddaba8d3b9a52b359e8cdbbb04c15ef179f7405ac6de4d5b1d7ed30251624fef01ff056f07dec2eb3852602b90d513847f0338
7
- data.tar.gz: 8fb8a2b74bd08bfaa7fe733758c7e57aeb3f25ba54f1399ca92b71b47638c8420adadf4f6588c1e7f5ca10a3815c62b2842629488b3fd537dc3cc22c4429d948
6
+ metadata.gz: 062cc63359517d87dc76ffd2a0c6853da7eff55e6c0565b1f4452ad2029c1a51fce1f619fdccdc0472e38655550adc9ab1cc3afabea39f189456e21167abd294
7
+ data.tar.gz: d7eb59f62036b13b3b632f75c11bfd1285a6eef21a96d4aff3b31f3b4d1ae96b06baa75f962b1ff9172d25ce9ec141a39ecec0e8e93c9599ec0b35b127ff21bc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shipengine_ruby (0.0.6)
4
+ shipengine_ruby (0.0.7)
5
5
  faraday (~> 1.0)
6
6
  faraday_middleware (~> 1.0)
7
7
  hashie (~> 5.0)
@@ -8,12 +8,13 @@ module ShipEngine
8
8
  module Exceptions
9
9
  class ShipEngineError < StandardError
10
10
  # message is inherited
11
- attr_reader :source, :type, :code, :url
11
+ attr_reader :source, :type, :code, :request_id, :url
12
12
 
13
- def initialize(message:, source:, type:, code:, url: nil)
13
+ def initialize(message:, source:, type:, code:, request_id: nil, url: nil)
14
14
  code = ShipEngine::Errors::ErrorCode.get(code) if code.is_a?(String)
15
15
  source = ShipEngine::Errors::ErrorSource.get(source) if source.is_a?(String)
16
16
  super(message)
17
+ @request_id = request_id
17
18
  @source = source
18
19
  @type = type
19
20
  @code = code
@@ -46,32 +47,34 @@ module ShipEngine
46
47
  source: source,
47
48
  message: message,
48
49
  type: ShipEngine::Errors::ErrorType.get(:VALIDATION),
49
- )
50
+ )
50
51
  end
51
52
  end
52
53
 
53
54
  class SystemError < ShipEngineError
54
- def initialize(message:, code:, source: nil, url: nil)
55
+ def initialize(message:, code:, source: nil, url: nil, request_id: nil)
55
56
  super(
56
57
  url: url,
57
58
  code: code,
58
59
  source: source,
59
60
  message: message,
61
+ request_id: request_id,
60
62
  type: ShipEngine::Errors::ErrorType.get(:SYSTEM),
61
- )
63
+ )
62
64
  end
63
65
  end
64
66
 
65
67
  class RateLimitError < SystemError
66
68
  attr_reader :retries
67
69
 
68
- def initialize(retries: nil, message: "You have exceeded the rate limit.", source: nil)
70
+ def initialize(retries: nil, message: "You have exceeded the rate limit.", source: nil, request_id: nil)
69
71
  super(
70
72
  message: message,
71
73
  code: ShipEngine::Errors::ErrorCode.get(:RATE_LIMIT_EXCEEDED),
72
74
  source: source,
75
+ request_id: request_id,
73
76
  url: URI("https://www.shipengine.com/docs/rate-limits"),
74
- )
77
+ )
75
78
  @retries = retries
76
79
  end
77
80
  end
@@ -14,11 +14,13 @@ module ShipEngine
14
14
  source: error_source(response[:body]),
15
15
  type: error_type(response[:body]),
16
16
  code: error_code(response[:body]),
17
+ request_id: error_request_id(response[:body]),
17
18
  url: response[:url].to_s
18
19
  )
19
20
  elsif [429].include?(status_code)
20
21
  raise ShipEngine::Exceptions::RateLimitError.new(
21
22
  retries: env.request_headers["Retries"].to_i,
23
+ request_id: error_request_id(response[:body]),
22
24
  source: error_source(response[:body])
23
25
  )
24
26
  end
@@ -78,6 +80,18 @@ module ShipEngine
78
80
  body["errors"][0]["error_code"]
79
81
  end
80
82
  end
83
+
84
+ def error_request_id(body)
85
+ if !body.nil? && !body.empty? && body.is_a?(String)
86
+ body = JSON.parse(body)
87
+ end
88
+
89
+ if body.nil?
90
+ nil
91
+ elsif body["request_id"]
92
+ body["request_id"]
93
+ end
94
+ end
81
95
  end
82
96
  end
83
97
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ShipEngine
4
4
  module VERSION
5
- VERSION = "0.0.6"
5
+ VERSION = "0.0.7"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipengine_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohammed Abdel Raouf