Created
June 7, 2009 00:46
-
-
Save skylar/125078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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