Module: WolfCore::HttpOperations
- Includes:
- ExceptionOperations
- Included in:
- ApplicationService, FkmOperations
- Defined in:
- lib/wolf_core/application/http_operations.rb
Instance Method Summary collapse
- #http_get(url:, headers: {}, query: nil) ⇒ Object
- #http_post(url:, headers: {}, body: nil, query: nil) ⇒ Object
- #parse_http_response(response) ⇒ Object
- #validate_http_response(response:, message:, error_data: nil) ⇒ Object
Methods included from ExceptionOperations
Instance Method Details
#http_get(url:, headers: {}, query: nil) ⇒ Object
5 6 7 |
# File 'lib/wolf_core/application/http_operations.rb', line 5 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
9 10 11 |
# File 'lib/wolf_core/application/http_operations.rb', line 9 def http_post(url:, headers: {}, body: nil, query: nil) WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body) end |
#parse_http_response(response) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/wolf_core/application/http_operations.rb', line 23 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
13 14 15 16 17 18 19 20 21 |
# File 'lib/wolf_core/application/http_operations.rb', line 13 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 |