public
Rubygem
Description: Makes http fun! Also, makes consuming restful web services dead easy.
Homepage:
Clone URL: git://github.com/jnunemaker/httparty.git
Click here to lend your support to: httparty and make a donation at www.pledgie.com !
Updated readme.
jnunemaker (author)
Fri Dec 05 14:14:54 -0800 2008
commit  11894cbf01509a740f87e253e799fbd58569ec0a
tree    889582b3ee57b439c8f92d416a49e3fa5a075d5e
parent  c49ba063100e238e2dd174b264d25302e56797bc
0
...
4
5
6
7
 
8
9
10
11
12
13
14
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 
59
60
61
...
4
5
6
 
7
8
9
10
11
12
13
 
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
19
0
@@ -4,58 +4,16 @@
0
 
0
 Makes http fun again!
0
 
0
-== FEATURES/PROBLEMS:
0
+== FEATURES:
0
 
0
 * Easy get, post, put, delete requests
0
 * Basic http authentication
0
 * Default request query string parameters (ie: for api keys that are needed on each request)
0
 * Automatic parsing of JSON and XML into ruby hashes based on response content-type
0
 
0
-== SYNOPSIS:
0
+== EXAMPLES:
0
 
0
-The following is a simple example of wrapping Twitter's API for posting updates.
0
-
0
-  class Twitter
0
-    include HTTParty
0
-    base_uri 'twitter.com'
0
-    basic_auth 'username', 'password'
0
-  end
0
-
0
-  Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})
0
-
0
-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). 
0
-
0
-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:
0
-
0
-  class Twitter
0
-    include HTTParty
0
-    base_uri 'twitter.com'
0
-
0
-    def initialize(u, p)
0
-      @auth = {:username => u, :password => p}
0
-    end
0
-
0
-    def post(text)
0
-      options = { :query => {:status => text}, :basic_auth => @auth }
0
-      self.class.post('/statuses/update.json', options)
0
-    end
0
-  end
0
-  
0
-  Twitter.new('username', 'password').post("It's an HTTParty and everyone is invited!")
0
-
0
-=== REQUEST OPTIONS
0
-
0
-Each of the HTTP method (get, post, put and delete) each take a hash of options.
0
-The following keys can be specified in the options:
0
-
0
-headers::       A <tt>Hash</tt> of header key/value pairs
0
-query::         A <tt>Hash</tt> of query key/value pairs
0
-body::          The body of the request. If it's a <tt>Hash</tt>, it is
0
-                converted into query-string format, otherwise it is sent
0
-                as-is.
0
-basic_auth::    A <tt>Hash</tt> containing keys for <tt>:username</tt> and
0
-                <tt>:password</tt>.
0
-no_follow::     Turns off automatic redirect following
0
+See http://github.com/jnunemaker/httparty/tree/master/examples
0
 
0
 == REQUIREMENTS:
0
 

Comments