Skip to content

Instantly share code, notes, and snippets.

@skylar
Created June 7, 2009 00:46
Show Gist options
  • Select an option

  • Save skylar/125078 to your computer and use it in GitHub Desktop.

Select an option

Save skylar/125078 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'net/http'
require 'rexml/document'
require 'cgi'
#setup
method_name = 'loans'
endpoint_prefix = 'http://api.kivaws.org/v1'
methods = {'loans' => '/loans/newest.json', 'partners' => '/partners.json' }
# get input parameters
cgi = CGI.new
if cgi.params.has_key?('method') && methods.has_key?(cgi.params['method'][0]) then
method_name = cgi.params['method'][0]
end
endpoint = endpoint_prefix + methods[method_name]
# get the JSON data as a string
json_data = Net::HTTP.get_response(URI.parse(endpoint)).body
#print "HTTP/1.0 200 OK\n"
print "Content-type: application/json\n\n"
puts json_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment