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 +4 -4
- data/README.md +2 -2
- data/lib/my_target_api/request.rb +9 -8
- data/lib/my_target_api/request_error.rb +16 -5
- data/lib/my_target_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0197ba27a7aa8993d54a2c8ea47385c14aa1c84
|
4
|
+
data.tar.gz: 9dc501f763b29f54054c0a41ee9813d4c4bd248b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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(
|
88
|
-
|
89
|
-
|
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(
|
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
|
-
@
|
14
|
-
|
23
|
+
@request_body = request_body
|
24
|
+
end
|
15
25
|
|
16
|
-
|
26
|
+
def set_response_info(response:)
|
27
|
+
@response = response
|
17
28
|
end
|
18
29
|
|
19
30
|
end
|