Class: Messed::Interface::Adapter::TwitterSender
Constant Summary
Registry
Instance Attribute Summary
#interface
Instance Method Summary
collapse
for_name, #init, #initialize, #load_state, register_for_name, #save_state, #send, #state_file, #type
included, #logger, #logger=
Instance Method Details
#message_class ⇒ Object
8
9
10
|
# File 'lib/messed/interface/adapter/twitter_sender.rb', line 8
def message_class
Messed::Message::Twitter
end
|
#process_outgoing(job, message) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/messed/interface/adapter/twitter_sender.rb', line 23
def process_outgoing(job, message)
if message.private?
req = EventMachine::HttpRequest.new("http://twitter.com/direct_messages/new.json")
data = {:body => {:user => message.to_user_id, :text => message.body}, :timeout => 30, :head => {'authorization' => [interface.configuration.options[:username], interface.configuration.options[:password]]}}
data[:body][:in_reply_to] = message.in_reply_to if message.in_reply_to
http = req.post(data)
http.callback {
job.delete
}
else
http = EventMachine::HttpRequest.new("http://twitter.com/statuses/update.json").
post(:body => {:status => message.body}, :timeout => 30)
http.callback {
job.delete
}
end
end
|
#start ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/messed/interface/adapter/twitter_sender.rb', line 12
def start
jack = EM::Beanstalk.new
jack.watch(interface.application.outgoing.tube) do
jack.use(interface.application.outgoing.tube) do
jack.each_job do |job|
process_outgoing(job, message_class.from_json(job.body))
end
end
end
end
|