ruote-extras 0.9.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007-2008, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+
34
+ #
35
+ # "made in Japan"
36
+ #
37
+ # John Mettraux at openwfe.org
38
+ #
39
+
40
+ #require 'rubygems'
41
+ require 'rufus/decision' # gem 'rufus-decision'
42
+
43
+ require 'openwfe/utils'
44
+ require 'openwfe/util/dollar'
45
+ require 'openwfe/participants/participant'
46
+
47
+
48
+ module OpenWFE
49
+ module Extras
50
+
51
+ #
52
+ # Using CSV files to transform workitems
53
+ # This concept is called "decision participant" in OpenWFEja, here
54
+ # it's simply called "csv participant".
55
+ #
56
+ # See CsvTable for an explanation of the core concept behind a
57
+ # CsvParticipant
58
+ #
59
+ # An example :
60
+ #
61
+ # class TestDefinition0 < ProcessDefinition
62
+ # sequence do
63
+ # set :field => "weather", :value => "cloudy"
64
+ # set :field => "month", :value => "may"
65
+ # decision
66
+ # _print "${f:take_umbrella?}"
67
+ # end
68
+ # end
69
+ #
70
+ #
71
+ # csvParticipant = CsvParticipant.new(
72
+ # """
73
+ # in:weather, in:month, out:take_umbrella?
74
+ # ,,
75
+ # raining, , yes
76
+ # sunny, , no
77
+ # cloudy, june, yes
78
+ # cloudy, may, yes
79
+ # cloudy, , no
80
+ # """)
81
+ #
82
+ # engine.register_participant("decision", csvParticipant)
83
+ #
84
+ # # ...
85
+ #
86
+ # engine.launch(new OpenWFE::LaunchItem(TestDefinition0)
87
+ #
88
+ # Note that the CsvParticipant constructor also accepts a block.
89
+ #
90
+ class CsvParticipant
91
+ include LocalParticipant
92
+
93
+ attr_accessor :csv_table
94
+
95
+ #
96
+ # Builds a new CsvParticipant instance, csv_data or the block
97
+ # may contain a File instance, a String or an Array of Array of
98
+ # String instances.
99
+ #
100
+ def initialize (csv_data=nil, &block)
101
+
102
+ super()
103
+
104
+ csv_data = block.call if block
105
+
106
+ @csv_table = Rufus::DecisionTable.new csv_data
107
+ end
108
+
109
+ #
110
+ # This is the method called by the engine (actually the
111
+ # ParticipantExpression) when handling a workitem to this participant.
112
+ #
113
+ def consume (workitem)
114
+
115
+ fe = get_flow_expression workitem
116
+
117
+ @csv_table.transform!(FlowDict.new(fe, workitem, 'f'))
118
+ #
119
+ # default_prefix set to 'f'
120
+
121
+ reply_to_engine workitem
122
+ end
123
+ end
124
+
125
+ end
126
+ end
127
+
@@ -0,0 +1,125 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007-2008, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ #
34
+
35
+ #
36
+ # "made in Japan"
37
+ #
38
+ # John Mettraux at openwfe.org
39
+ #
40
+
41
+ require 'yaml'
42
+ require 'base64'
43
+
44
+ #require 'rubygems'
45
+ require 'rufus/sqs' # gem 'rufus-sqs'
46
+
47
+ require 'openwfe/participants/participant'
48
+
49
+
50
+ module OpenWFE
51
+ module Extras
52
+
53
+ #
54
+ # This participant dispatches its workitem to an Amazon SQS queue.
55
+ #
56
+ # If the queue doesn't exist, the participant will create it.
57
+ #
58
+ # a small example :
59
+ #
60
+ # # ...
61
+ # engine.register_participant(:sqs0, SqsParticipant.new("workqueue0"))
62
+ # # ...
63
+ #
64
+ # For more details about SQS :
65
+ # http://aws.amazon.com
66
+ #
67
+ class SqsParticipant
68
+ include LocalParticipant
69
+
70
+ attr_reader :queue, :queue_service
71
+
72
+ #
73
+ # Builds an SqsParticipant instance pointing to a given queue.
74
+ # (Refer to the SQS service on how to set up AWS key ids).
75
+ #
76
+ # By default the host_name is 'queue.amazonaws.com'
77
+ #
78
+ def initialize (queue_name, host_name=nil)
79
+
80
+ @queue_name = queue_name
81
+
82
+ @queue_service = Rufus::SQS::QueueService.new host_name
83
+
84
+ @queue_service.create_queue @queue_name
85
+ # make sure the queue exists
86
+
87
+ @queue = @queue_service.get_queue @queue_name
88
+ end
89
+
90
+ #
91
+ # The method called by the engine when it has a workitem for this
92
+ # participant.
93
+ #
94
+ def consume (workitem)
95
+
96
+ msg = encode_workitem workitem
97
+
98
+ msg_id = @queue_service.put_message @queue, msg
99
+
100
+ ldebug do
101
+ "consume() msg sent to queue #{@queue.path} id is #{msg_id}"
102
+ end
103
+ end
104
+
105
+ protected
106
+
107
+ #
108
+ # Turns the workitem into a Hash, pass it through YAML and
109
+ # encode64 the result.
110
+ #
111
+ # Override this method as needed.
112
+ #
113
+ # Something of 'text/plain' flavour should be returned.
114
+ #
115
+ def encode_workitem (wi)
116
+
117
+ msg = wi.to_h
118
+ msg = YAML.dump(msg)
119
+ msg = Base64.encode64(msg)
120
+ msg
121
+ end
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,176 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007-2008, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+
34
+ #
35
+ # "made in Japan"
36
+ #
37
+ # John Mettraux at openwfe.org
38
+ #
39
+
40
+ #
41
+ # this participant requires the twitter4r gem
42
+ #
43
+ # http://rubyforge.org/projects/twitter4r/
44
+ #
45
+ # atom-tools' license is X11/MIT
46
+ #
47
+
48
+ #require 'rubygems'
49
+ #gem 'twitter4r', '0.2.3'
50
+ require 'twitter' # gem 'twitter4r'
51
+
52
+ require 'openwfe/utils'
53
+ require 'openwfe/participants/participant'
54
+
55
+
56
+ module OpenWFE
57
+ module Extras
58
+
59
+ #
60
+ # Sometimes email is a bit too heavy for notification, this participant
61
+ # emit messages via a twitter account.
62
+ #
63
+ # By default, the message emitted is the value of the field
64
+ # "twitter_message", but this behaviour can be changed by overriding
65
+ # the extract_message() method.
66
+ #
67
+ # If the extract_message doesn't find a message, the message will
68
+ # be the result of the default_message method call, of course this
69
+ # method is overridable as well.
70
+ #
71
+ class TwitterParticipant
72
+ include OpenWFE::LocalParticipant
73
+
74
+ #
75
+ # The actual twitter4r client instance.
76
+ #
77
+ attr_accessor :client
78
+
79
+ #
80
+ # Keeping the initialization params at hand (if any)
81
+ #
82
+ attr_accessor :params
83
+
84
+ #
85
+ # This participant expects a login (twitter user name) and a password.
86
+ #
87
+ # The only optional param for now is :no_ssl, which you can set to
88
+ # true if you want the connection to twitter to not use SSL.
89
+ # (seems like the Twitter SSL service is available less often
90
+ # than the plain http one).
91
+ #
92
+ def initialize (login, password, params={})
93
+
94
+ super()
95
+
96
+ Twitter::Client.configure do |conf|
97
+ conf.protocol = :http
98
+ conf.port = 80
99
+ end if params[:no_ssl] == true
100
+
101
+ @client = Twitter::Client.new(
102
+ :login => login,
103
+ :password => password)
104
+
105
+ @params = params
106
+ end
107
+
108
+ #
109
+ # The method called by the engine when a workitem for this
110
+ # participant is available.
111
+ #
112
+ def consume (workitem)
113
+
114
+ user, tmessage = extract_message workitem
115
+
116
+ tmessage = default_message(workitem) unless tmessage
117
+
118
+ begin
119
+
120
+ if user
121
+ #
122
+ # direct message
123
+ #
124
+ tuser = @client.user user.to_s
125
+ @client.message :post, tmessage, tuser
126
+ else
127
+ #
128
+ # just the classical status
129
+ #
130
+ @client.status :post, tmessage
131
+ end
132
+
133
+ rescue Exception => e
134
+
135
+ linfo do
136
+ "consume() not emitted twitter, because of " +
137
+ OpenWFE::exception_to_s(e)
138
+ end
139
+ end
140
+
141
+ reply_to_engine(workitem) if @application_context
142
+ end
143
+
144
+ protected
145
+
146
+ #
147
+ # Returns a pair : the target user (twitter login name)
148
+ # and the message (or status message if there is no target user) to
149
+ # send to Twitter.
150
+ #
151
+ # This default implementation returns a pair composed with the
152
+ # values of the field 'twitter_target' and of the field
153
+ # 'twitter_message'.
154
+ #
155
+ def extract_message (workitem)
156
+
157
+ [ workitem.attributes['twitter_target'],
158
+ workitem.attributes['twitter_message'] ]
159
+ end
160
+
161
+ #
162
+ # Returns the default message (called when the extract_message
163
+ # returned nil as the second element of its pair).
164
+ #
165
+ # This default implementation simply returns the workitem
166
+ # FlowExpressionId instance in its to_s() representation.
167
+ #
168
+ def default_message (workitem)
169
+
170
+ workitem.fei.to_s
171
+ end
172
+ end
173
+
174
+ end
175
+ end
176
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruote-extras
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.18
5
+ platform: ruby
6
+ authors:
7
+ - John Mettraux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-22 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: john at openwfe dot org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/openwfe/extras/engine
26
+ - lib/openwfe/extras/engine/db_persisted_engine.rb
27
+ - lib/openwfe/extras/expool
28
+ - lib/openwfe/extras/expool/dberrorjournal.rb
29
+ - lib/openwfe/extras/expool/dbexpstorage.rb
30
+ - lib/openwfe/extras/listeners
31
+ - lib/openwfe/extras/listeners/sqslisteners.rb
32
+ - lib/openwfe/extras/misc
33
+ - lib/openwfe/extras/misc/activityfeed.rb
34
+ - lib/openwfe/extras/misc/basecamp.rb
35
+ - lib/openwfe/extras/participants
36
+ - lib/openwfe/extras/participants/activeparticipants.rb
37
+ - lib/openwfe/extras/participants/atomfeed_participants.rb
38
+ - lib/openwfe/extras/participants/atompub_participants.rb
39
+ - lib/openwfe/extras/participants/basecamp_participants.rb
40
+ - lib/openwfe/extras/participants/csvparticipants.rb
41
+ - lib/openwfe/extras/participants/sqsparticipants.rb
42
+ - lib/openwfe/extras/participants/twitterparticipants.rb
43
+ has_rdoc: false
44
+ homepage: http://openwferu.rubyforge.org/
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project: openwferu
65
+ rubygems_version: 1.1.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: OpenWFEru extras (sqs, csv, ...)
69
+ test_files: []
70
+