Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svperfecta/285370 to your computer and use it in GitHub Desktop.
Save svperfecta/285370 to your computer and use it in GitHub Desktop.
require "rubygems"
require "uri"
require "yajl/http_stream"
require "twitter"
# Campfire Setup
token = 'yourtoken'
room_id = 111111
url = URI.parse("http://#{token}:x@streaming.campfirenow.com//room/#{room_id}/live.json")
# Twitter setup
twitter_auth = Twitter::HTTPAuth.new('yourname', 'yourpasswordh')
twitter_pattern = Regexp.new('@test\s', Regexp::IGNORECASE)
twitter = Twitter::Base.new(twitter_auth)
# Monitor the Campfire feed then tweet
Yajl::HttpStream.get(url, :symbolize_keys => true) do |message|
puts "Received #{message.inspect}"
# We only care about text messages, with valid bodies, that contain the case insensitive word '@twitter' at the beginning of the message
if message[:body] and
message[:type] == 'TextMessage' and
message[:body].index(twitter_pattern) == 0
tweet = message[:body].sub(twitter_pattern, '').strip
# Let's tweet
if tweet.length > 0
puts "Attempting to post: #{tweet}"
# Make three attempts, then bail
attempts = 0
begin
twitter.update(tweet)
rescue Exception => e
attempts += 1
retry if attempts <= 3
puts "Failboat. Damn Twitter. On the last attempt we got #{e.message}"
end
end
end
end
puts 'Failed for some reason?'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment