1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/website/index.html

83 lines
3 KiB
HTML
Raw Normal View History

2008-07-29 12:16:01 -04:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>HTTParty by John Nunemaker</title>
<link rel="stylesheet" href="css/common.css" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>HTTParty</h1>
<p>Tonight we're gonna HTTParty like it's 1999!</p>
<ul id="nav">
<li><a href="rdoc/">Docs</a></li>
<li><a href="http://github.com/jnunemaker/httparty">Github</a></li>
2008-07-31 00:29:17 -04:00
<li><a href="http://jnunemaker.lighthouseapp.com/projects/14842-httparty/tickets">Lighthouse</a></li>
2008-07-29 12:16:01 -04:00
<li><a href="http://rubyforge.org/projects/httparty/">Rubyforge</a></li>
</ul>
</div>
<div id="content">
<h2>Install</h2>
<pre><code>$ sudo gem install httparty</code></pre>
<h2>Some Quick Examples</h2>
<p>The following is a simple example of wrapping Twitter's API for posting updates.</p>
<pre><code>class Twitter
include HTTParty
base_uri 'twitter.com'
basic_auth 'username', 'password'
end
Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})</code></pre>
<p>That is really it! The object returned is a ruby hash that is decoded from Twitter's json response. JSON parsing is used because of the .json extension in the path of the request. You can also explicitly set a format (see the examples). </p>
<p>That works and all but what if you don't want to embed your username and password in the class? Below is an example to fix that:</p>
<pre><code>class Twitter
include HTTParty
base_uri 'twitter.com'
2008-07-31 00:29:17 -04:00
def initialize(u, p)
@auth = {:username => u, :password => p}
2008-07-29 12:16:01 -04:00
end
def post(text)
2008-07-31 00:29:17 -04:00
options = { :query => {:status => text}, :basic_auth => @auth }
self.class.post('/statuses/update.json', options)
2008-07-29 12:16:01 -04:00
end
end
Twitter.new('username', 'password').post("It's an HTTParty and everyone is invited!")</code></pre>
<p><strong>More Examples:</strong> There are <a href="http://github.com/jnunemaker/httparty/tree/master/examples/">several examples in the gem itself</a>.</p>
<h2>Support</h2>
<p>Conversations welcome in the <a href="http://groups.google.com/group/httparty-gem">google group</a> and bugs/features over at <a href="http://jnunemaker.lighthouseapp.com/projects/14842-httparty/overview">Lightouse</a>.</p>
</div>
<div id="footer">
<p>Created by <a href="http://addictedtonew.com/about/">John Nunemaker</a></p>
</div>
</div>
2008-07-31 00:29:17 -04:00
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-85301-19");
pageTracker._initData();
pageTracker._trackPageview();
</script>
2008-07-29 12:16:01 -04:00
</body>
</html>