This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
William Roe
committed
Apr 23, 2010
1 parent
12710d4
commit 12fcbb9
Showing
10 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ db/*.sqlite3 | |
log/*.log | ||
tmp/**/* | ||
.DS_Store | ||
*~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rvm ruby-1.8.7@sonia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ group :runtime do | |
gem "rake" | ||
gem "configliere" | ||
gem "optiflag" | ||
gem "httparty" | ||
end | ||
|
||
group :test do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'yajl' | ||
require 'twitter/json_stream' | ||
require 'uri' | ||
require 'httparty' | ||
require 'em-http' | ||
require 'digest/md5' | ||
|
||
module Sonia | ||
module Widgets | ||
class Campfire < Sonia::Widget | ||
GRAVATAR_URL = "http://www.gravatar.com/avatar/" | ||
|
||
def initialize(config) | ||
super(config) | ||
@room_uri = URI.encode("#{config[:url]}/room/#{config[:room_id]}.json") | ||
user_info() | ||
connect_to_stream() | ||
|
||
EventMachine::add_periodic_timer(150) { user_info() } | ||
end | ||
|
||
private | ||
def connect_to_stream | ||
puts "Connecting to campfire: #{config.inspect}" | ||
@stream = ::Twitter::JSONStream.connect( | ||
:path => "/room/#{config[:room_id]}/live.json", | ||
:host => 'streaming.campfirenow.com', | ||
:auth => "#{config[:token]}:x" | ||
) | ||
|
||
@stream.each_item do |message| | ||
json_message = Yajl::Parser.parse(message) | ||
puts json_message | ||
formatted = format_message(json_message) | ||
push formatted unless formatted.nil? | ||
end | ||
end | ||
|
||
def format_message(message) | ||
if message['type']=='TextMessage' | ||
user = @users[message['user_id']] | ||
img = user.nil? ? '' : user_gravatar(user[:email]) | ||
name = user.nil? ? 'Unknown' : user[:name] | ||
return { | ||
:body => message['body'], | ||
:user => name, | ||
:avatar => img | ||
} | ||
end | ||
return nil | ||
end | ||
|
||
def user_info() | ||
puts "Getting user info" | ||
@users ||= {} | ||
room_info = HTTParty.get(@room_uri, :format => :json, :basic_auth => {:username => config[:token], :password => 'x'}) | ||
puts room_info.inspect | ||
room_info['room']['users'].each do |user| | ||
@users[user['id']] = { | ||
:name => user['name'], | ||
:email => user['email_address'] | ||
} | ||
end | ||
puts @users.inspect | ||
end | ||
|
||
def user_gravatar(email) | ||
email_digest = Digest::MD5.hexdigest(email) | ||
"#{GRAVATAR_URL}#{email_digest}?d=identicon" | ||
end | ||
end | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var Campfire = Class.create(Widget, { | ||
initialize: function($super, widget_id, config) { | ||
this.messages = []; | ||
return($super(widget_id, config)); | ||
}, | ||
receive: function(payload) { | ||
console.log("Received some payload: " + payload); | ||
if(this.messages.length >= this.config.nitems) { | ||
this.messages.shift(); | ||
} | ||
this.messages.push(payload); | ||
this.update(); | ||
}, | ||
update: function() { | ||
this.container.childElements().invoke('remove'); | ||
this.container.appendChild(this.buildWidgetIcon()); | ||
this.container.appendChild(this.buildHeader()); | ||
this.messages.reverse(false).each(function(message) { | ||
var cont = new Element('p'); | ||
cont.appendChild(new Element('img', { src: message.avatar, width: 48, height: 48 })); | ||
cont.appendChild(new Element('a', { href: '#', className: 'author' }).update(message.user)); | ||
cont.appendChild(document.createTextNode(message.body)); | ||
cont.appendChild(new Element('hr' )); | ||
this.container.appendChild(cont); | ||
}.bind(this)); | ||
}, | ||
|
||
buildHeader: function() { | ||
return(new Element("h2").update(this.title)); | ||
}, | ||
|
||
buildWidgetIcon: function() { | ||
return(new Element("img", {width: 32, height: 32, className: 'campfire_icon'})); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12fcbb9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am so aweome
12fcbb9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True story