bud 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,49 +0,0 @@
1
- require 'rubygems'
2
- require 'bud'
3
- require 'nestful'
4
- require 'bud/bust/client/idempotence'
5
-
6
- module RestClient
7
- include Idempotence # :nodoc: all
8
-
9
- state do
10
- # complains about underspecified dataflow because it can't see the
11
- # nested rules...
12
- interface input, :rest_req, [:rid, :verb, :form, :url, :params]
13
- interface output, :rest_response, [:rid, :resp, :exception]
14
-
15
- # we don't really need to store this i suppose
16
- scratch :rest_req_thread, [:thread]
17
- end
18
-
19
- bloom :rest_client do
20
- rest_req_thread <= rest_req.map do |req|
21
- # start up a new thread to deal with the response
22
- [Thread.start(req, self) do |r, bud|
23
- params = (r.params or {})
24
- begin
25
- case r.verb
26
- when :get
27
- get_hash = {:params => params}
28
- get_hash[:format] = r.form if r.form
29
- resp_tuple = [r.rid, Nestful.get(r.url, get_hash), false]
30
- when :post
31
- # not sure if this is a sensible default for format?
32
- format = (r.form or :form)
33
- resp_tuple = [r.rid, Nestful.post(r.url, :format => format,
34
- :params => params), false]
35
- else
36
- raise "invalid verb"
37
- end
38
- rescue
39
- resp_tuple = [r.rid, "#{$!}", true]
40
- end
41
- # insert the response
42
- bud.async_do do
43
- rest_response <+ [resp_tuple]
44
- end
45
- end] if bust_idempotent [[req.rid, req.verb, req.form, req.url, req.params,
46
- @budtime]]
47
- end
48
- end
49
- end