class EasyRestClient
Public Class Methods
delete(*args)
click to toggle source
# File lib/easy_rest_client.rb, line 11 def delete(*args); new.send_request(:delete, *args); end
execute(*args)
click to toggle source
# File lib/easy_rest_client.rb, line 12 def execute(*args); new.send_request(:execute, *args); end
get(*args)
click to toggle source
# File lib/easy_rest_client.rb, line 8 def get(*args); new.send_request(:get, *args); end
post(*args)
click to toggle source
# File lib/easy_rest_client.rb, line 9 def post(*args); new.send_request(:post, *args); end
put(*args)
click to toggle source
# File lib/easy_rest_client.rb, line 10 def put(*args); new.send_request(:put, *args); end
Public Instance Methods
send_request(method_name, *args)
click to toggle source
# File lib/easy_rest_client.rb, line 15 def send_request(method_name, *args) klass = method_name == :execute ? ::RestClient::Request : ::RestClient response = klass.send(method_name, *args) parse(response) end
Private Instance Methods
convert_to_object(element)
click to toggle source
# File lib/easy_rest_client.rb, line 34 def convert_to_object(element) if element.is_a?(Hash) Hashie::Mash.new(element) elsif element.is_a?(Array) element.map { |sub_element| convert_to_object(sub_element) } else element end end
parse(response)
click to toggle source
# File lib/easy_rest_client.rb, line 25 def parse(response) if response.headers[:content_type] !~ %r(application/json) return response.body end parsed_body = JSON.parse(response.body) convert_to_object(parsed_body) end