Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sandro/888478 to your computer and use it in GitHub Desktop.
Save sandro/888478 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'httparty'
class FakeRestJsonApi
include HTTParty
base_uri 'http://google.com/THIS_IS_A_FAKE_URL'
headers 'Accept' => 'application/json'
default_params :output => 'json'
format :json
debug_output
class Parser < HTTParty::Parser
def json
begin
Crack::JSON.parse(body)
rescue StandardError
puts "Use another JSON parser"
end
end
end
parser Parser
def fake_get_request(params={})
self.class.get('/fake_get_request', :body => params)
end
end
if __FILE__ == $0
frj_api = FakeRestJsonApi.new
#
# NOTE:
# How can one retrieve the Response Body which causes the
# the Crack::ParseError in order to log and debug?
#
begin
resp = frj_api.fake_get_request
rescue Exception => e
require 'pp'
puts "\n--------------\nResponse from fake_get_request:\n\n"
pp resp
puts "\n--------------\n\n"
raise
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment