Module: WolfCore::HttpOperations
- Includes:
- 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 ExceptionOperations
Instance Method Details
#async_http_get(**args) ⇒ Object
5 6 7 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 5 def async_http_get(**args) fork { http_get(**args) } end |
#async_http_post(**args) ⇒ Object
13 14 15 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 13 def async_http_post(**args) fork { http_post(**args) } end |
#async_http_put(**args) ⇒ Object
21 22 23 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 21 def async_http_put(**args) fork { http_put(**args) } end |
#http_get(url:, headers: {}, query: nil) ⇒ Object
9 10 11 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 9 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
17 18 19 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 17 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
25 26 27 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 25 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
39 40 41 42 43 44 45 46 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 39 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
29 30 31 32 33 34 35 36 37 |
# File 'lib/wolf_core/infrastructure/http_operations.rb', line 29 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 |