Module: SEPOMEX_HCKDRK::JsonApi::ClassMethods
- Defined in:
- lib/sepomex_hckdrk/client/json_api.rb
Instance Method Summary collapse
- #api_get(url:, headers: {}) ⇒ Object
- #api_post(url:, body: {}, headers: {}) ⇒ Object
- #api_post_multipart(url:, body: {}, headers: {}) ⇒ Object
- #default_headers ⇒ Object
Instance Method Details
#api_get(url:, headers: {}) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/sepomex_hckdrk/client/json_api.rb', line 12 def api_get(url:, headers: {}) custom_headers = headers.merge(default_headers) response = HTTParty.get(SEPOMEX_HCKDRK.api_base + url, headers: custom_headers) JSON.parse(response.body, symbolize_names: true) end |
#api_post(url:, body: {}, headers: {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sepomex_hckdrk/client/json_api.rb', line 19 def api_post(url:, body: {}, headers: {}) custom_headers = headers.merge(default_headers) response = HTTParty.post( SEPOMEX_HCKDRK.api_base + url, body: body.to_json, headers: custom_headers ) JSON.parse(response.body, symbolize_names: true) end |
#api_post_multipart(url:, body: {}, headers: {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sepomex_hckdrk/client/json_api.rb', line 31 def api_post_multipart(url:, body: {}, headers: {}) custom_headers = headers.merge(default_headers) response = HTTParty.post( SEPOMEX_HCKDRK.api_base + url, multipart: true, body: body, headers: custom_headers ) response.body end |
#default_headers ⇒ Object
6 7 8 9 10 |
# File 'lib/sepomex_hckdrk/client/json_api.rb', line 6 def default_headers { 'Content-type' => 'application/json' } end |