wolf_core 1.0.0 → 1.0.1

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: d93315b5bf36dac8a13d61db31d6d1faf173be220468760e0f4365e01481b4c1
4
- data.tar.gz: f783133a7c30083979448d5e246417a41038cba54cdc37b7d62247f641ebde7d
3
+ metadata.gz: 34de3ce44a6c43a34f730c9a1e1eebf091f63ce6a94c0acbccfc6f1e15e151ab
4
+ data.tar.gz: 3e16fb618f71f3c36f17dc312933dfad77ce0f32a0d3eb87bf775d2d16591c57
5
5
  SHA512:
6
- metadata.gz: 300c4bb4ebea15cd2d3fa2980e265b9625e884192a5e1bfb4e9b8b501c0598ddae83274be01aec6a953943a6f7a6ac55c19a20c02505102d6e33bac3702fda2c
7
- data.tar.gz: 517d12bd2d0066e63f4144d7b8456aac64c786afd3ee6b05554f226cf1596266fc44bbaabef2782c253d34cbfc98febc6895b9be50fcec3e1280cdc3b3d0a440
6
+ metadata.gz: 95f3529936b64862714e4163e793a81e260193efd35dcc845569e80ea606904da74040bc17b0c69c75ff08f16d3c7361b9c6f05bc13d63cf71492ec8c8186f34
7
+ data.tar.gz: 635cd4831a4582f5bb134a917125fb95170b2b21f569e73c3d268ab37116839ce68917a4b2321cb3845cf0f8bd1fd180495f6ec03ad7395eb3a381f4f7aaa9be
@@ -4,12 +4,17 @@ module WolfCore
4
4
  include WolfCore::AsyncUtils
5
5
  include WolfCore::LoggingUtils
6
6
 
7
+ def parsed_http_get(url:, headers: {}, query: nil)
8
+ response = http_get(url: url, headers: headers, query: query)
9
+ parse_http_response(response)
10
+ end
11
+
7
12
  def async_http_get(**args)
8
- log_object 'starting async_http_get'
9
- log_object args, title: 'async_http_get args are'
13
+ log_object "starting async_http_get"
14
+ log_object args, title: "async_http_get args are"
10
15
  run_async do
11
16
  response = http_get(**args)
12
- log_object parse_http_response(response), title: 'async_http_get response is'
17
+ log_object parse_http_response(response), title: "async_http_get response is"
13
18
  end
14
19
  end
15
20
 
@@ -19,7 +24,7 @@ module WolfCore
19
24
 
20
25
  log_object response, title: title if title.present?
21
26
 
22
- error_message ||= 'Error on safe_http_get'
27
+ error_message ||= "Error on safe_http_get"
23
28
  validate_http_response(response: response, message: error_message)
24
29
 
25
30
  response
@@ -29,12 +34,17 @@ module WolfCore
29
34
  WolfCore::HttpDataSource.http_get(url: url, headers: headers, query: query)
30
35
  end
31
36
 
37
+ def parsed_http_post(url:, headers: {}, query: nil)
38
+ response = http_post(url: url, headers: headers, query: query)
39
+ parse_http_response(response)
40
+ end
41
+
32
42
  def async_http_post(**args)
33
43
  log_object "starting async_http_post"
34
- log_object args, title: 'async_http_post args are'
44
+ log_object args, title: "async_http_post args are"
35
45
  run_async do
36
46
  response = http_post(**args)
37
- log_object parse_http_response(response), title: 'async_http_post response is'
47
+ log_object parse_http_response(response), title: "async_http_post response is"
38
48
  end
39
49
  end
40
50
 
@@ -42,10 +52,10 @@ module WolfCore
42
52
  response = http_post(url: url, headers: headers, body: body, query: query)
43
53
  response = parse_http_response(response)
44
54
 
45
- title ||= 'safe_http_post response is'
55
+ title ||= "safe_http_post response is"
46
56
  log_object response, title: title
47
57
 
48
- error_message ||= 'Error on safe_http_post'
58
+ error_message ||= "Error on safe_http_post"
49
59
  validate_http_response(response: response, message: error_message)
50
60
 
51
61
  response
@@ -55,12 +65,17 @@ module WolfCore
55
65
  WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body)
56
66
  end
57
67
 
68
+ def parsed_http_put(url:, headers: {}, query: nil)
69
+ response = http_put(url: url, headers: headers, query: query)
70
+ parse_http_response(response)
71
+ end
72
+
58
73
  def async_http_put(**args)
59
- log_object 'starting async_http_put'
60
- log_object args, title: 'async_http_put args are'
74
+ log_object "starting async_http_put"
75
+ log_object args, title: "async_http_put args are"
61
76
  run_async do
62
77
  response = http_put(**args)
63
- log_object parse_http_response(response), title: 'async_http_put response is'
78
+ log_object parse_http_response(response), title: "async_http_put response is"
64
79
  end
65
80
  end
66
81
 
@@ -68,10 +83,10 @@ module WolfCore
68
83
  response = http_put(url: url, headers: headers, body: body, query: query)
69
84
  response = parse_http_response(response)
70
85
 
71
- title ||= 'safe_http_put response is'
86
+ title ||= "safe_http_put response is"
72
87
  log_object response, title: title
73
88
 
74
- error_message ||= 'Error on safe_http_put'
89
+ error_message ||= "Error on safe_http_put"
75
90
  validate_http_response(response: response, message: error_message)
76
91
 
77
92
  response
@@ -82,22 +97,26 @@ module WolfCore
82
97
  end
83
98
 
84
99
  def validate_http_response(response:, message:, error_data: nil)
85
- unless response.code == 200
86
- error_data = {
87
- message: message,
88
- response: parse_http_response(response)
89
- }.merge(error_data || {})
90
- raise_service_error(error_data)
91
- end
100
+ return if response.code == 200
101
+
102
+ error_data = {
103
+ message: message,
104
+ response: parse_http_response(response)
105
+ }.merge(error_data || {})
106
+ raise_service_error(error_data)
92
107
  end
93
108
 
94
109
  def parse_http_response(response)
95
- body = JSON.parse(response.body) rescue response.body
110
+ body = begin
111
+ JSON.parse(response.body)
112
+ rescue StandardError
113
+ response.body
114
+ end
96
115
  OpenStruct.new({
97
- code: response.code,
98
- body: body,
99
- message: response.message,
100
- })
116
+ code: response.code,
117
+ body: body,
118
+ message: response.message
119
+ })
101
120
  end
102
121
  end
103
- end
122
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolf_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo