my_target_api 2.0.8 → 2.0.9

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
  SHA1:
3
- metadata.gz: 9d2b150e6e583301d7e8df189f972037f5e172a7
4
- data.tar.gz: 99fad25af3476285363e81850cf49bcabba45b67
3
+ metadata.gz: f0197ba27a7aa8993d54a2c8ea47385c14aa1c84
4
+ data.tar.gz: 9dc501f763b29f54054c0a41ee9813d4c4bd248b
5
5
  SHA512:
6
- metadata.gz: 2c0e9287d76ee717e286c854e122e7bdde90bf55a67b1b86f7ee87504a189458c3266446e86a5398c8701ec80590581333c5726e5c72bd975f09ff6af5c892d5
7
- data.tar.gz: 0e23ad56c3c82f091a143dcf8aaee5543a13b670535e01a4382c293a3476bd1acd11001952675fb4d1db9bc51a04f5f4c48722bba230251fcef8b51f8723d526
6
+ metadata.gz: e8c4bc53c0e5e96d4adfba82fd4e0b6bc8cc4c4a87128badc6e260505270e71e101f54bab7e7c5f7a3e555bbdc1f990d8e156ed2790edd98a7fa11b54d063707
7
+ data.tar.gz: 83b3e83127cc85414eb2f04de1caafc58312af26a1c409a7e0cd05196da04e9e35737277d235eda64e6242efd351d4b9822c709d604f1029600554550b958c9b
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```
10
- gem 'my_target_api', '~> 2.0.8'
10
+ gem 'my_target_api', '~> 2.0.9'
11
11
  ```
12
12
 
13
13
  Or install from command line:
@@ -99,7 +99,7 @@ def read_active_campaigns
99
99
 
100
100
  rescue MyTargetApi::RequestError => e
101
101
 
102
- puts e.message, e.method, e.url, e.params, e.response, e.backtrace
102
+ puts e.message, e.method, e.url, e.params, e.request_body, e.response, e.backtrace
103
103
  # You can access the original exception
104
104
  puts e.original_exception&.message, e.original_exception&.backtrace
105
105
 
@@ -38,7 +38,7 @@ class MyTargetApi
38
38
  end
39
39
 
40
40
  def upload(url, content, params = {}, headers = {})
41
- response = with_exception_handling('POST', url, params) do
41
+ response = with_exception_handling('POST', url, params, content: content) do
42
42
  NetClient.post(
43
43
  url,
44
44
  content,
@@ -65,17 +65,18 @@ class MyTargetApi
65
65
  response.body
66
66
  end
67
67
 
68
- def with_exception_handling(method, url, params)
68
+ def with_exception_handling(method, url, params, content: nil)
69
69
  response = yield
70
70
  log_response(response)
71
71
  if response.code >= 400
72
- raise_with_params(method: method, url: url, params: params, response: response)
72
+ raise_with_params(method: method, url: url, params: params, response: response,
73
+ content: content)
73
74
  end
74
75
  response
75
76
  rescue NetClient::Exception => e
76
77
  original_exception = e.original_exception
77
78
  logger << "#{original_exception.class.name} #{original_exception.message}"
78
- raise_with_params(method: method, url: url, params: params,
79
+ raise_with_params(method: method, url: url, params: params, content: content,
79
80
  original_exception: original_exception)
80
81
  end
81
82
 
@@ -83,10 +84,10 @@ class MyTargetApi
83
84
  logger << ResponseFormatter.new(response).format
84
85
  end
85
86
 
86
- def raise_with_params(method:, url:, params:, response: nil, original_exception: nil)
87
- result = MyTargetApi::RequestError.new(method: method, url: url,
88
- params: params, response: response,
89
- original_exception: original_exception)
87
+ def raise_with_params(method:, url:, params:, response: nil, content:, original_exception: nil)
88
+ result = MyTargetApi::RequestError.new(original_exception: original_exception)
89
+ result.set_request_info(method: method, url: url, request_body: content, params: params)
90
+ result.set_response_info(response: response)
90
91
  result.set_backtrace(caller)
91
92
  raise result
92
93
  end
@@ -4,16 +4,27 @@ class MyTargetApi
4
4
  # Error for request
5
5
  class RequestError < StandardError
6
6
 
7
- attr_reader :method, :url, :params, :original_exception, :response
7
+ attr_reader :method, :url, :params, :original_exception, :response, :request_body
8
8
 
9
- def initialize(method:, url:, params:, original_exception: nil, response: nil)
9
+ def initialize(original_exception: nil)
10
+ @original_exception = original_exception
11
+
12
+ super(original_exception ? original_exception.message : 'No original exception')
13
+ end
14
+
15
+ def message
16
+ response ? "#{response.code}: #{response.body}" : 'No response'
17
+ end
18
+
19
+ def set_request_info(method:, url:, params:, request_body:)
10
20
  @method = method
11
21
  @url = url
12
22
  @params = params
13
- @response = response
14
- @original_exception = original_exception
23
+ @request_body = request_body
24
+ end
15
25
 
16
- super(response ? "#{response.code}: #{response.body}" : 'No response')
26
+ def set_response_info(response:)
27
+ @response = response
17
28
  end
18
29
 
19
30
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  class MyTargetApi
4
4
 
5
- VERSION = '2.0.8'
5
+ VERSION = '2.0.9'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_target_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneRetarget.com