MS DG public message now post to twitter, if connected

This commit is contained in:
maxwell 2010-10-23 17:35:10 -07:00 committed by danielvincent
parent c4ff07b09a
commit 606c7a02a4
6 changed files with 31 additions and 10 deletions

View file

@ -12,7 +12,7 @@ gem 'devise_invitable', '~> 0.3.4'
#Authentication #Authentication
gem 'omniauth' gem 'omniauth'
gem 'twitter'
#Mongo #Mongo
gem 'mongo_mapper', :branch => 'rails3', :git => 'git://github.com/jnunemaker/mongomapper.git' gem 'mongo_mapper', :branch => 'rails3', :git => 'git://github.com/jnunemaker/mongomapper.git'
gem 'bson_ext', '1.1' gem 'bson_ext', '1.1'

View file

@ -13,10 +13,13 @@ class OmniauthServicesController < ApplicationController
def create def create
auth = request.env['omniauth.auth'] auth = request.env['omniauth.auth']
access_token = auth['extra']['access_token']
puts auth['extra']['access_token'].inspect user = auth['user_info']
current_user.services.create(:nickname => user['nickname'],
current_user.services.create(:provider => auth['provider'], :uid => auth['uid']) :access_token => access_token.token,
:access_secret => access_token.secret,
:provider => auth['provider'],
:uid => auth['uid'])
flash[:notice] = "Authentication successful." flash[:notice] = "Authentication successful."
redirect_to omniauth_services_url redirect_to omniauth_services_url
end end

View file

@ -10,12 +10,17 @@ class StatusMessagesController < ApplicationController
def create def create
data = clean_hash params[:status_message] data = clean_hash params[:status_message]
message = params[:status_message][:message]
if logged_into_fb? && params[:status_message][:public] == '1' if params[:status_message][:public] == '1'
current_user.post_to_message_fb(params[:status_message][:message], @access_token) current_user.post_to_twitter(message)
if logged_into_fb?
current_user.post_to_message_fb(message, @access_token)
end
end end
@status_message = current_user.post(:status_message, data) @status_message = current_user.post(:status_message, data)
render :nothing => true render :nothing => true
end end

View file

@ -9,5 +9,7 @@ class OmniauthService
key :provider, String key :provider, String
key :uid, String key :uid, String
key :access_token, String
key :access_secret, String
key :nickname, String
end end

View file

@ -161,6 +161,16 @@ class User
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{access_token}").post EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{access_token}").post
end end
def post_to_twitter(message)
twitter = self.services.find_by_provider("twitter")
if twitter
oauth = Twitter::OAuth.new(SERVICES['twitter']['consumer_token'], SERVICES['twitter']['consumer_secret'])
oauth.authorize_from_access(twitter.access_token, twitter.access_secret)
client = Twitter::Base.new(oauth)
client.update(message)
end
end
def intitial_post(class_name, aspect_ids, options = {}) def intitial_post(class_name, aspect_ids, options = {})
post = build_post(class_name, options) post = build_post(class_name, options)
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)

View file

@ -8,9 +8,10 @@
%ul#stream %ul#stream
- for service in @services - for service in @services
%h3 %h3
= service.provider %b= service.provider
logged in as
%b %b
=service.uid = service.nickname
= link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete
= link_to "Connect to twitter", "/auth/twitter" = link_to "Connect to twitter", "/auth/twitter"