Class: OpenWFE::Extras::TwitterParticipant

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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).



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 107

def initialize (, 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 => ,
        :password => password)

    @params = params
end

Instance Attribute Details

#clientObject

The actual twitter4r client instance.



92
93
94
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 92

def client
  @client
end

#paramsObject

Keeping the initialization params at hand (if any)



97
98
99
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 97

def params
  @params
end

Instance Method Details

#consume(workitem) ⇒ Object

The method called by the engine when a workitem for this participant is available.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/openwfe/extras/participants/twitterparticipants.rb', line 127

def consume (workitem)

    user, tmessage = extract_message workitem

    tmessage = default_message(workitem) unless tmessage

    begin

        if user
            #
            # direct message
            #
            tuser = @client.user user.to_s
            @client.message :post, tmessage, tuser
        else
            #
            # just the classical status
            #
            @client.status :post, tmessage
        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