Module: WolfCore::HttpOperations
- Includes:
- AsyncUtils, ExceptionOperations
- Included in:
- ApplicationService, FkmOperations
- Defined in:
- lib/wolf_core/infrastructure/http_operations.rb
Instance Method Summary collapse
- #async_http_get(**args) ⇒ Object
- #async_http_post(**args) ⇒ Object
- #async_http_put(**args) ⇒ Object
- #http_get(url:, headers: {}, query: nil) ⇒ Object
- #http_post(url:, headers: {}, body: nil, query: nil) ⇒ Object
- #http_put(url:, headers: {}, body: nil, query: nil) ⇒ Object
- #parse_http_response(response) ⇒ Object
- #validate_http_response(response:, message:, error_data: nil) ⇒ Object
Methods included from AsyncUtils
Methods included from ExceptionOperations
Instance Method Details
#async_http_get(**args) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 6 def async_http_get(**args) puts "starting async_http_get" run_async do response = http_get(**args) puts "async_http_get response is" pp parse_http_response(response).to_h end end |
#async_http_post(**args) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 19 def async_http_post(**args) puts "starting async_http_post" run_async do response = http_post(**args) puts "async_http_post response is" pp parse_http_response(response).to_h end end |
#async_http_put(**args) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 32 def async_http_put(**args) puts "starting async_http_put" run_async do response = http_put(**args) puts "async_http_put response is" pp parse_http_response(response).to_h end end |
#http_get(url:, headers: {}, query: nil) ⇒ Object
15 16 17 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 15 def http_get(url:, headers: {}, query: nil) WolfCore::HttpDataSource.http_get(url: url, headers: headers, query: query) end |
#http_post(url:, headers: {}, body: nil, query: nil) ⇒ Object
28 29 30 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 28 def http_post(url:, headers: {}, body: nil, query: nil) WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body) end |
#http_put(url:, headers: {}, body: nil, query: nil) ⇒ Object
41 42 43 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 41 def http_put(url:, headers: {}, body: nil, query: nil) WolfCore::HttpDataSource.http_put(url: url, headers: headers, query: query, body: body) end |
#parse_http_response(response) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 55 def parse_http_response(response) body = JSON.parse(response.body) rescue response.body OpenStruct.new({ code: response.code, body: body, message: response., }) end |
#validate_http_response(response:, message:, error_data: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 45 def validate_http_response(response:, message:, error_data: nil) unless response.code == 200 error_data = { message: , response: parse_http_response(response) }.merge(error_data || {}) raise_service_error(error_data) end end |