rufus-jig 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ = rufus-jig CHANGELOG.txt
3
+
4
+ == rufus-jig - 0.1.1 not yet released
5
+
6
+ == rufus-jig - 0.1.0 released 2009/11/09
7
+
data/CREDITS.txt ADDED
@@ -0,0 +1,3 @@
1
+
2
+ nothing here for now
3
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ Copyright (c) 2009-2009, John Mettraux, jmettraux@gmail.com
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+
data/README.rdoc ADDED
@@ -0,0 +1,176 @@
1
+
2
+ = rufus-jig
3
+
4
+ A HTTP client, greedy with JSON content, GETting conditionally.
5
+
6
+ Uses Patron (http://github.com/toland/patron) and Yajl-ruby (http://github.com/brianmario/yajl-ruby) whenever possible.
7
+
8
+ This library also contains some CouchDB helpers.
9
+
10
+
11
+ == examples
12
+
13
+ === HTTP client
14
+
15
+ Let's say we have an hypothetical document server.
16
+
17
+ getting...
18
+
19
+ require 'patron'
20
+ require 'yajl'
21
+ require 'rufus/jig'
22
+
23
+ h = Rufus::Jig::Http.new('127.0.0.1', 4567)
24
+
25
+ p @h.get('/document/xyz.json')
26
+ #
27
+ # => { "type" => "letter", "title" => "four birds" }
28
+ #
29
+ # if it's JSON, decodes it immediately
30
+
31
+ r = @h.get('/document/xyz.txt')
32
+ p [ r.status, r.body ]
33
+ #
34
+ # => [ 200, "letter:\n\nfour birds" ]
35
+ #
36
+ # else returns a Response object (currently the one of Patron)
37
+
38
+ j = @h.get('/document', :content_type => 'application/json')
39
+ j = @h.get('/document', :content_type => :json)
40
+ #
41
+ # 'Accepts' JSON
42
+
43
+ posting...
44
+
45
+ r = @h.post(
46
+ '/documents', '<doc>four birds</doc>', :content_type => 'application/xml')
47
+ p [ r.status, r.body ]
48
+ #
49
+ # => [ 201, "created." ]
50
+
51
+
52
+ === Couch helpers
53
+
54
+ For the real thing : http://github.com/couchrest/couchrest
55
+
56
+ require 'patron'
57
+ require 'yajl'
58
+ require 'rufus/jig'
59
+
60
+ c = Rufus::Jig::Couch.get_couch('127.0.0.1', 5984)
61
+ # connecting to the local couch
62
+
63
+ db = @c.put_db('rufus_jig_test')
64
+ # let's create a database named 'rufus_jig_test'
65
+
66
+ d = @db.put_doc('ct2', { 'item' => 'suit', 'brand' => 'suit company' })
67
+ p [ d._id, d._rev, d['item'] ]
68
+ #
69
+ # => [ "ct2", "1-755f205df9f3c3a05849df3554ea24f7", "suit" ]
70
+
71
+ # meanwhile, somebody else modifies the doc ...
72
+
73
+ d['size'] = 'XL'
74
+
75
+ d.put
76
+ #
77
+ # ouch, this gives us :
78
+ # => conflict: Document update conflict. (Rufus::Jig::CouchError)
79
+
80
+ d.get
81
+ p [ d._id, d._rev, d['size'] ]
82
+ #
83
+ # re-getting the document
84
+ #
85
+ # => [ "ct2", "2-3a09eafe8739b54ab46105b96c1c69a2", "XL" ]
86
+
87
+ d.delete
88
+ #
89
+ # getting rid of the document
90
+
91
+ Some class methods (getting right to the stuff).
92
+
93
+ require 'patron'
94
+ require 'yajl'
95
+ require 'rufus/jig'
96
+
97
+ db = Rufus::Jig::Couch.get_db('http://127.0.0.1:5984/test_db')
98
+ # returns a Rufus::Jig::CouchDatabase instance
99
+ # or nil if the db doesn't exist
100
+
101
+ db = Rufus::Jig::Couch.put_db('http://127.0.0.1:5984/test_db')
102
+ # creates a new database, or raise an exception if the db already exists
103
+
104
+ doc = Rufus::Jig::Couch.get_doc('http://127.0.0.1:5984/test_db/doc0')
105
+ # returns a Rufus::Jig::CouchDocument instance
106
+ # or nil the document doesn't exist
107
+
108
+ # ...
109
+
110
+ Perhaps the right way to interact from rufus-jig to CouchDB is something like :
111
+
112
+ db = Rufus::Jig::Couch.get_db('http://127.0.0.1:5984/test_db')
113
+
114
+ doc = db.get_doc('doc0')
115
+
116
+ doc['car'] = { 'brand' => 'BMW', 'model' => 'MarkIII' }
117
+
118
+ doc.put
119
+
120
+ # ...
121
+
122
+ Get a CouchDatabase instance then play from it.
123
+
124
+
125
+ == rdoc
126
+
127
+ http://rufus.rubyforge.org/rufus-jig/
128
+
129
+
130
+ == testing
131
+
132
+ At first, make sure to start the tiny sinatra test server :
133
+
134
+ ruby test/server.rb
135
+
136
+ then do
137
+
138
+ ruby test/test.rb
139
+
140
+
141
+ To test the CouchDB helpers, make you have a running Couch on http:/127.0.0.1:5984 then do
142
+
143
+ ruby test/test.rb --couch
144
+
145
+
146
+ == mailing list
147
+
148
+ On the rufus-ruby list :
149
+
150
+ http://groups.google.com/group/rufus-ruby
151
+
152
+
153
+ == issue tracker
154
+
155
+ http://github.com/jmettraux/rufus-jig/issues
156
+
157
+
158
+ == irc
159
+
160
+ irc.freenode.net #ruote
161
+
162
+
163
+ == the rest of Rufus
164
+
165
+ http://rufus.rubyforge.org
166
+
167
+
168
+ == authors
169
+
170
+ * John Mettraux, jmettraux@gmail.com, http://jmettraux.wordpress.com
171
+
172
+
173
+ == license
174
+
175
+ MIT
176
+
data/TODO.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ [o] PUT
3
+ [o] DELETE
4
+ [o] POST
5
+ [o] :prefix
6
+ [o] :raw
7
+ [o] POST/PUT cache if etag is given back (couch)
8
+ [o] get('/x', :cache => false)
9
+ [o] get('x') vs get('/x') ?
10
+
11
+ [ ] long polling/continuous change (patron ?)
12
+ [ ] HEAD
13
+
14
+ [ ] Net::HTTP (when no Patron)
15
+
16
+ [ ] couch : attachments
17
+
18
+ [ ] redirections ? (Patron seem to understand them)
19
+
20
+ [ ] put_doc(h) where _id is set ?
21
+
data/delete.txt ADDED
@@ -0,0 +1,21 @@
1
+ $ curl -vX DELETE 'http://localhost:5984/nada/doc4?rev=1-154674290868ca95f26ead035328e2ea'
2
+ * About to connect() to localhost port 5984 (#0)
3
+ * Trying 127.0.0.1... connected
4
+ * Connected to localhost (127.0.0.1) port 5984 (#0)
5
+ > DELETE /nada/doc4?rev=1-154674290868ca95f26ead035328e2ea HTTP/1.1
6
+ > User-Agent: curl/7.19.6 (i386-apple-darwin10.0.0) libcurl/7.19.6 zlib/1.2.3
7
+ > Host: localhost:5984
8
+ > Accept: */*
9
+ >
10
+ < HTTP/1.1 200 OK
11
+ < Server: CouchDB/0.10.0 (Erlang OTP/R13B)
12
+ < Etag: "2-575dc2a2afa69152c502f4d07cc983dc"
13
+ < Date: Sun, 01 Nov 2009 09:39:25 GMT
14
+ < Content-Type: text/plain;charset=utf-8
15
+ < Content-Length: 67
16
+ < Cache-Control: must-revalidate
17
+ <
18
+ {"ok":true,"id":"doc4","rev":"2-575dc2a2afa69152c502f4d07cc983dc"}
19
+ * Connection #0 to host localhost left intact
20
+ * Closing connection #0
21
+