Created
March 23, 2009 21:23
-
-
Save ecarnevale/83791 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
require "net/http" | |
require "uri" | |
base_url = 'www.instapaper.com' | |
path_url = '/api/authenticate/' | |
username = 'instatest' | |
pwd = '' | |
#1st version | |
Net::HTTP.get_print base_url, path_url | |
#2nd version | |
Net::HTTP.start(base_url) {|http| | |
req = Net::HTTP::Get.new(path_url) | |
req.basic_auth username, pwd | |
response = http.request(req) | |
print response.body | |
} | |
#3rd version | |
url = URI.parse('http://'+base_url+path_url) | |
req = Net::HTTP::Post.new(url.path) | |
req.basic_auth username, pwd | |
#req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';') | |
res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) } | |
case res | |
when Net::HTTPSuccess, Net::HTTPRedirection | |
# OK | |
else | |
res.error! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment