Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add some documentation

  • Loading branch information...
commit dea32c849a0872bd15b7af4924ab2fec9eef64ba 1 parent 134a1f9
Torsten Schönebaum authored
Showing with 85 additions and 5 deletions.
  1. +72 −0 README.rdoc
  2. +2 −1  Rakefile
  3. +11 −4 lib/ruote/jig/part/jig_participant.rb
View
72 README.rdoc
@@ -0,0 +1,72 @@
+
+= ruote-activeresource
+
+ruote 2.0 extension for a participant using rufus-jig to send http messages around
+
+== usage
+
+ require 'yajl' # by default, you will need some JSON lib (yajl-ruby or json_pure or ActiveSupport)
+
+ # require this lib
+ require 'ruote/jig/part/jig_participant'
+
+ # let's assume you have a ruote engine in '''engine'''
+ engine.register_participant :jig_default, Ruote::Jig::JigParticipant
+ engine.register_participant :jig_advanced, Ruote::Jig::JigParticipant.new(
+ :host => 'somehost',
+ :port => 80,
+ :path => '/path/to/the/magic',
+ :method => :post,
+ :content_type => 'foo/bar',
+ :data_preparition => Proc.new {|workitem| workitem.fields['foo_bar'].to_s},
+ :response_handling => Proc.new do |response, workitem|
+ workitem.set_field('incoming_foo_bar', FooBar.from_str(response.body))
+ end
+ )
+
+ # in a workflow definition...
+ participant :ref => 'jig_default' # will POST the current workitem as JSON
+ # to http://127.0.0.1:3000/ and save the
+ # responded data in the workitem field
+ # \_\_jig_response__
+
+ participant :ref => 'jig_advanced', # will PUT the the string returned by
+ :host => 'anotherhost', # workitem.fields['foo_bar'].to_s to
+ :path => '/path/to/bar', # http://anotherhost:80/path/to/bar,
+ :method => :put # processes the response body and
+ # saves the result in the workitem
+ # field 'incoming_foo_bar'
+
+== running tests
+
+to run unit tests
+
+ ruby test/test.rb
+
+fakeweb and yajl-ruby have to be installed.
+
+
+== license
+
+MIT
+
+
+== links
+
+* http://github.com/tosch/ruote-jig
+* http://rufus.rubyforge.org/rufus-jig/
+* http://ruote.rubyforge.org/
+
+
+== feedback
+
+mailing list:: http://groups.google.com/group/openwferu-users
+irc:: irc.freenode.net \#ruote
+
+== credits
+
+* Torsten Schönebaum, Planquadrat Software-Integration GmbH (http://github.com/tosch)
+
+Many thanks to John Mettraux (http://jmettraux.wordpress.com) for his tireless
+work on Ruote and the many rufus libs. Thanks to Kenneth Kalmer
+(http://github.com/kennethkalmer) for his work on rufus-jig.
View
3  Rakefile
@@ -8,7 +8,8 @@ begin
gemspec.homepage = "http://github.com/tosch/ruote-jig"
gemspec.authors = ["Torsten Schönebaum"]
gemspec.add_dependency('ruote', '>= 2.0.0')
- gemspec.add_dependency('rufus-jig', '>= 0.1.1')
+ gemspec.add_dependency('rufus-jig', '>= 0.1.2')
+ gemspec.rdoc_options << '--line-numbers' << '--main' << 'README.rdoc'
end
Jeweler::GemcutterTasks.new
rescue LoadError
View
15 lib/ruote/jig/part/jig_participant.rb
@@ -27,8 +27,8 @@
require 'ruote/engine/context' # gem install ruote
require 'ruote/part/local_participant' # gem install ruote
-module Ruote
- module Jig
+module Ruote #:nodoc:
+ module Jig #:nodoc:
#
# Ruote 2.0 participant which does a HTTP call using rufus-jig
# (http://rufus.rubyforge.org/rufus-jig/), a HTTP client, greedy with JSON
@@ -42,7 +42,7 @@ module Jig
# The handling of outgoing and incoming data may be customized by Procs.
#
# == Using it
- # require 'yajl' # by default, you will need some JSON lib (yajl-ruby or json 'pure' or ActiveSupport)
+ # require 'yajl' # by default, you will need some JSON lib (yajl-ruby or json_pure or ActiveSupport)
#
# # require this lib
# require 'ruote/jig/part/jig_participant'
@@ -93,7 +93,7 @@ class JigParticipant
# :method <Symbol>:: Which HTTP method shall be used? One of :get, :post, :put and :delete.
# :options_for_jig <Hash>:: Hash of options which will be passed to Rufus::Jig::Http.new.
# :options_for_jig_requests <Hash>:: Hash of options which will be passed to the get, put, post or delete method of Rufus::Jig::Http
- # :response_handling <Proc>:: An optional Proc which handles the results Rufus::Jig::Http returns. Takes the results and the workitem as arguments. By default (when no Proc is given), the server's response is stored in the workitem field __jig_response__ and the HTTP status code in __jig_status__.
+ # :response_handling <Proc>:: An optional Proc which handles the results Rufus::Jig::Http returns. Takes the results and the workitem as arguments. By default (when no Proc is given), the server's response is stored in the workitem field \_\_jig_response__ and the HTTP status code in \_\_jig_status__.
# :data_preparition <Proc>:: An optional Proc which prepares the data being sent with POST or PUT requests. Takes the workitem as argument. Should return a string or another type Rufus::Jig::Http can handle. By default (if no Proc is given), the workitem will be converted into a Hash (and then into a JSON string by rufus-jig).
# :content_type <String or Symbol>:: The content type to use for the HTTP request. Defaults to :json. Other types has to be submitted as strings. Note that you really should provide a :data_preparition-Proc if you don't use JSON!
#
@@ -113,6 +113,13 @@ def initialize(options = {})
@http = Rufus::Jig::Http.new @options[:host], @options[:port], @options[:options_for_jig] || {}
end
+ #
+ # This is where the work is done...
+ #
+ # The engine calls this method and passes it a workitem as argument. The
+ # HTTP request will be processed and the workitem will be returned to the
+ # engine immediately after that.
+ #
def consume workitem
# do we need a new instance of the http client?
http = if(@http.host == param(workitem, :host) and @http.port == param(workitem, :port))
Please sign in to comment.
Something went wrong with that request. Please try again.