ruote-jig

Ruote 2.0 participant which does a HTTP call using rufus-jig (rufus.rubyforge.org/rufus-jig/), a HTTP client, greedy with JSON content.

By default, it POSTs received workitems as JSON to a HTTP server and stores the answer back into the workitem. If the answer is in JSON, it is automatically converted into Ruby data types (this magic is thanks to rufus-jig).

The handling of outgoing and incoming data may be customized by Procs.

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

feedback

mailing list

groups.google.com/group/openwferu-users

irc

irc.freenode.net #ruote

credits

  • Torsten Schönebaum, Planquadrat Software-Integration GmbH (github.com/tosch)

Many thanks to John Mettraux (jmettraux.wordpress.com) for his tireless work on Ruote and the many rufus libs. Thanks to Kenneth Kalmer (github.com/kennethkalmer) for his work on rufus-jig.