Module: Appilf::APIActions
- Included in:
- Client, Listing, ResourcePage
- Defined in:
- lib/appilf/api_actions.rb
Constant Summary collapse
- BASE_API_URL =
'https://api.flippa.com/v3'
Instance Method Summary collapse
- #api_delete(path, payload, headers = {}) ⇒ Object
- #api_get(path, headers = {}) ⇒ Object
- #api_post(path, payload, headers = {}) ⇒ Object
- #handle_from_response(response_error) ⇒ Object
Instance Method Details
#api_delete(path, payload, headers = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/appilf/api_actions.rb', line 14 def api_delete(path, payload, headers = {}) RestClient::Request.execute(method: :delete, url: path, payload: payload, headers: headers) :success rescue RestClient::RequestFailed => e handle_from_response(e) end |
#api_get(path, headers = {}) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/appilf/api_actions.rb', line 22 def api_get(path, headers = {}) response = RestClient::Request.execute(method: :get, url: path, headers: headers) JSON.parse(response) rescue RestClient::RequestFailed => e handle_from_response(e) end |
#api_post(path, payload, headers = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/appilf/api_actions.rb', line 6 def api_post(path, payload, headers = {}) response = RestClient::Request.execute(method: :post, url: path, payload: payload, headers: headers) JSON.parse(response) rescue RestClient::RequestFailed => e handle_from_response(e) end |
#handle_from_response(response_error) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/appilf/api_actions.rb', line 29 def handle_from_response(response_error) = JSON.parse(response_error.response)['error'] case response_error.http_code when 400 raise BadRequest.new() when 401 raise Unauthorized.new() when 403 raise Forbidden.new() when 404 raise NotFound.new() when 500 raise InternalServerError.new() else raise response_error end end |