From c489f49a25939d66a8c7be989a9ffb9f922fe667 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 13:59:26 -0700 Subject: [PATCH] DG beginning to collapse twitter&facebook --- app/controllers/application_controller.rb | 3 ++- app/controllers/omniauth_services_controller.rb | 2 ++ app/controllers/services_controller.rb | 1 - app/models/user.rb | 11 ++++++----- app/views/omniauth_services/index.html.haml | 1 + config/initializers/omniauth.rb | 2 +- config/oauth_keys.yml | 3 +++ 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 137705df4..d61cb193d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -45,15 +45,16 @@ class ApplicationController < ActionController::Base end end + ## take this out def fb_user_info if current_user @access_token = warden.session[:access_token] @logged_in = @access_token.present? end end - def logged_into_fb? @logged_in end + ## end diff --git a/app/controllers/omniauth_services_controller.rb b/app/controllers/omniauth_services_controller.rb index b15746875..23ff7afe5 100644 --- a/app/controllers/omniauth_services_controller.rb +++ b/app/controllers/omniauth_services_controller.rb @@ -13,6 +13,8 @@ class OmniauthServicesController < ApplicationController def create auth = request.env['omniauth.auth'] + puts auth.inspect + access_token = auth['extra']['access_token'] user = auth['user_info'] current_user.services.create(:nickname => user['nickname'], diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 97f52cef2..29da09872 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -12,7 +12,6 @@ class ServicesController < ApplicationController code = params['code'] # Facebooks verification string if code access_token_hash = MiniFB.oauth_access_token(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", FB_SECRET, code) - p access_token_hash @access_token = access_token_hash["access_token"] # TODO: This is where you'd want to store the token in your database diff --git a/app/models/user.rb b/app/models/user.rb index 75a0d0989..a52201fa0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -154,11 +154,12 @@ class User intitial_post(class_name, aspect_ids, options) end - def post_to_facebook(message, access_token) - id = 'me' - type = 'feed' - Rails.logger.info("Sending a message: #{message} to Facebook") - EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{access_token}").post + def post_to_facebook(message) + facebook = self.services.find_by_provider("facebook") + if facebook + Rails.logger.info("Sending a message: #{message} to Facebook") + EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{facebook.access_token}").post + end end def post_to_twitter(message) diff --git a/app/views/omniauth_services/index.html.haml b/app/views/omniauth_services/index.html.haml index 9b6be3946..282df96fc 100644 --- a/app/views/omniauth_services/index.html.haml +++ b/app/views/omniauth_services/index.html.haml @@ -15,4 +15,5 @@ = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete = link_to "Connect to twitter", "/auth/twitter" += link_to "Connect to facebook", "/auth/facebook" diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 876d3f3f2..a9253f6c2 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -4,6 +4,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, SERVICES['twitter']['consumer_key'], SERVICES['twitter']['consumer_secret'] - #provider :facebook, 'APP_ID', 'APP_SECRET' + provider :facebook, SERVICES['facebook']['app_id'], SERVICES['facebook']['app_secret'] end diff --git a/config/oauth_keys.yml b/config/oauth_keys.yml index 1460b861f..c3dc20afd 100644 --- a/config/oauth_keys.yml +++ b/config/oauth_keys.yml @@ -1,3 +1,6 @@ twitter: consumer_key: no69jTnL5SCOnWgk5XWqbQ consumer_secret: 2DZyu8DA43AIeFsRVdz8OtAHLvCtPjdRKdNO3UZGqWM +facebook: + app_id: 120373411325347 + app_secret: 7fe864834726f8a5e65bc93928b99a53