Class: OpenWFE::Extras::TwitterParticipant
- Inherits:
-
Object
- Object
- OpenWFE::Extras::TwitterParticipant
- Includes:
- LocalParticipant
- Defined in:
- lib/openwfe/extras/participants/twitterparticipants.rb
Overview
Sometimes email is a bit too heavy for notification, this participant emit messages via a twitter account.
By default, the message emitted is the value of the field “twitter_message”, but this behaviour can be changed by overriding the extract_message() method.
If the extract_message doesn’t find a message, the message will be the result of the default_message method call, of course this method is overridable as well.
Instance Attribute Summary collapse
-
#client ⇒ Object
The actual twitter4r client instance.
-
#params ⇒ Object
Keeping the initialization params at hand (if any).
Instance Method Summary collapse
-
#consume(workitem) ⇒ Object
The method called by the engine when a workitem for this participant is available.
-
#initialize(login, password, params = {}) ⇒ TwitterParticipant
constructor
This participant expects a login (twitter user name) and a password.
Constructor Details
#initialize(login, password, params = {}) ⇒ TwitterParticipant
This participant expects a login (twitter user name) and a password.
The only optional param for now is :no_ssl, which you can set to true if you want the connection to twitter to not use SSL. (seems like the Twitter SSL service is available less often than the plain http one).
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 92 def initialize (login, password, params={}) super() Twitter::Client.configure do |conf| conf.protocol = :http conf.port = 80 end if params[:no_ssl] == true @client = Twitter::Client.new( :login => login, :password => password) @params = params end |
Instance Attribute Details
#client ⇒ Object
The actual twitter4r client instance.
77 78 79 |
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 77 def client @client end |
#params ⇒ Object
Keeping the initialization params at hand (if any)
82 83 84 |
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 82 def params @params end |
Instance Method Details
#consume(workitem) ⇒ Object
The method called by the engine when a workitem for this participant is available.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 112 def consume (workitem) user, = workitem = (workitem) unless begin if user # # direct message # tuser = @client.user user.to_s @client. :post, , tuser else # # just the classical status # @client.status :post, end rescue Exception => e linfo do "consume() not emitted twitter, because of " + OpenWFE::exception_to_s(e) end end reply_to_engine(workitem) if @application_context end |