class GetAccept::Resource
Attributes
client[R]
Public Class Methods
new(client)
click to toggle source
# File lib/get_accept/resource.rb, line 5 def initialize client @client = client end
Protected Instance Methods
delete(path)
click to toggle source
# File lib/get_accept/resource.rb, line 20 def delete (path) client.delete("#{API_BASE}#{path}") end
get(path)
click to toggle source
# File lib/get_accept/resource.rb, line 10 def get(path) response = client.get("#{API_BASE}#{path}") handle_response(response) end
handle_response(response)
click to toggle source
# File lib/get_accept/resource.rb, line 24 def handle_response(response) parsed_response = response.parse if response.code < 400 parsed_response else error_klass = response.code >= 500 ? ServerError : RequestError raise error_klass.new({ response_code: response.code, response_body: parsed_response, type: parsed_response['error'], message: parsed_response['description'], errors: parsed_response['errors'], }) end end
post(path, data = nil)
click to toggle source
# File lib/get_accept/resource.rb, line 15 def post(path, data = nil) response = client.post("#{API_BASE}#{path}", json: data) handle_response(response) end