module Arke::Resource::Requests::ClassMethods
Public Instance Methods
delete(params={})
click to toggle source
# File lib/arke/resource/requests.rb, line 27 def delete(params={}) HTTParty.delete url(params) end
deserialize(body)
click to toggle source
# File lib/arke/resource/requests.rb, line 47 def deserialize(body) begin @deserializer.call(body) rescue => e raise Errors::DeserializationError.new(e) end end
deserializer(&block)
click to toggle source
# File lib/arke/resource/requests.rb, line 23 def deserializer(&block) @deserializer = block end
get(params={})
click to toggle source
# File lib/arke/resource/requests.rb, line 35 def get(params={}) handle_response(HTTParty.get url(params)) end
handle(code, &block)
click to toggle source
# File lib/arke/resource/requests.rb, line 55 def handle(code, &block) self.response_handlers ||= {} raise Arke::Errors::MissingHandlerBlock unless block_given? case code when String, Integer, Fixnum self.response_handlers[code.to_i] = block return true when Range, Array code.to_a.each do |c| self.response_handlers[c.to_i] = block end return true else raise Errors::InvalidHandler. new("#{code.class.name} is an invalid class, please user an Integer, Fixnum, String, Range or Array") end end
handle_response(response)
click to toggle source
# File lib/arke/resource/requests.rb, line 43 def handle_response(response) self.response_handlers[response.code.to_i].call(response) end
post(body={}, params={})
click to toggle source
# File lib/arke/resource/requests.rb, line 31 def post(body={}, params={}) handle_response(HTTParty.post(url(params.empty? ? body : params), body: body)) end
put(body={}, params={})
click to toggle source
# File lib/arke/resource/requests.rb, line 39 def put(body={}, params={}) handle_response(HTTParty.put(url(params.empty? ? body : params), body: body)) end