Skip to content
Browse files

update facebook oauth2 code to annoyingly use latest fucking oauth2 gem.

  • Loading branch information...
1 parent 7d675ed commit 22bbe99efb5937bdd836ae36f2d585542aa75c86 @kyleshank committed Nov 18, 2012
View
4 Gemfile
@@ -3,8 +3,8 @@ source 'http://rubygems.org'
gem 'rails', '=3.2.8'
gem 'mysql2'
gem 'oauth'
-gem 'oauth2', :path => "vendor/gems/oauth2"
-gem 'twitter', '4.1.0'
+gem 'oauth2'
+gem 'twitter'
gem "delayed_job"
gem 'will_paginate'
gem 'jquery-rails'
View
22 Gemfile.lock
@@ -1,10 +1,3 @@
-PATH
- remote: vendor/gems/oauth2
- specs:
- oauth2 (0.4.1)
- faraday (>= 0.6.1)
- multi_json (>= 0.0.5)
-
GEM
remote: http://rubygems.org/
specs:
@@ -67,12 +60,15 @@ GEM
multipart-post (~> 1.1)
highline (1.6.15)
hike (1.2.1)
+ httpauth (0.2.0)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (2.1.3)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.5)
+ jwt (0.1.5)
+ multi_json (>= 1.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -89,6 +85,12 @@ GEM
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
oauth (0.4.7)
+ oauth2 (0.8.0)
+ faraday (~> 0.8)
+ httpauth (~> 0.1)
+ jwt (~> 0.1.4)
+ multi_json (~> 1.0)
+ rack (~> 1.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
@@ -139,7 +141,7 @@ GEM
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
- twitter (4.1.0)
+ twitter (4.2.0)
faraday (~> 0.8)
multi_json (~> 1.3)
simple_oauth (~> 0.1.6)
@@ -162,13 +164,13 @@ DEPENDENCIES
jquery-rails
mysql2
oauth
- oauth2!
+ oauth2
rails (= 3.2.8)
rails_autolink
rvm
rvm-capistrano
sass-rails (~> 3.2.3)
thin
- twitter (= 4.1.0)
+ twitter
uglifier (>= 1.0.3)
will_paginate
View
11 app/controllers/facebook_accounts_controller.rb
@@ -20,17 +20,18 @@ class FacebookAccountsController < ApplicationController
include FacebookAccountsHelper
def new
- redirect_to get_oauth_client.web_server.authorize_url(
+ redirect_to get_oauth_client.auth_code.authorize_url(
:redirect_uri => facebook_redirect_uri,
:scope => 'offline_access,share_item,manage_pages'
)
end
def create
begin
- access_token = get_oauth_client.web_server.get_access_token(params[:code], :redirect_uri => facebook_redirect_uri)
+ access_token = get_oauth_client.auth_code.get_token(params[:code], :redirect_uri => facebook_redirect_uri, :parsed => :facebook)
+
response = access_token.get('/me')
- user_info = JSON.parse(response)
+ user_info = JSON.parse(response.body)
@account = FacebookAccount.where(:uid => user_info["id"]).first
@@ -43,8 +44,8 @@ def create
@account.name = "#{user_info["first_name"]} #{user_info["last_name"]}"
@account.screen_name = user_info["username"]
@account.token = params[:code]
- @account.followers = JSON.parse(access_token.get("/me/friends"))["data"].size
- @account.facebook_pages = JSON.parse(access_token.get("/me/accounts"))["data"].select{|a| a["category"] != "Application"}.to_json
+ @account.followers = JSON.parse(access_token.get("/me/friends").body)["data"].size
+ @account.facebook_pages = JSON.parse(access_token.get("/me/accounts").body)["data"].select{|a| a["category"] != "Application"}.to_json
if @account.save
self.current_facebook_account=@account
View
2 app/controllers/facebook_statuses_controller.rb
@@ -31,6 +31,8 @@ def create
if @facebook_status.save
flash[:notice] = "Publishing to Facebook"
redirect_to campaign_permalink_path(@campaign) and return
+ else
+ p @facebook_status.errors
end
redirect_to dashboard_path
View
1 app/helpers/facebook_accounts_helper.rb
@@ -19,6 +19,7 @@
module FacebookAccountsHelper
def get_oauth_client
OAuth2::Client.new(FACEBOOK_APPLICATION_ID, FACEBOOK_APPLICATION_SECRET,
+ :token_url => '/oauth/access_token',
:site => {
:url => 'https://graph.facebook.com',
:ssl => {
View
15 app/models/facebook_account.rb
@@ -24,15 +24,15 @@ class FacebookAccount < Account
def get(uri, opts = {})
try_to do
- @graph ||= get_oauth_client.web_server.get_access_token(self.token, :redirect_uri => FACEBOOK_OAUTH_REDIRECT)
- JSON.parse(@graph.get(uri, opts))
+ @graph ||= get_oauth_client.auth_code.get_token(self.token, :redirect_uri => FACEBOOK_OAUTH_REDIRECT, :parsed => :facebook)
+ JSON.parse(@graph.get(uri, opts).body)
end
end
def post(uri, opts = {})
try_to do
- @graph ||= get_oauth_client.web_server.get_access_token(self.token, :redirect_uri => FACEBOOK_OAUTH_REDIRECT)
- JSON.parse(@graph.post(uri, opts))
+ @graph ||= get_oauth_client.auth_code.get_token(self.token, :redirect_uri => FACEBOOK_OAUTH_REDIRECT, :parsed => :facebook)
+ JSON.parse(@graph.post(uri, opts).body)
end
end
@@ -55,11 +55,8 @@ def share(_data)
d.delete("id")
try_to do
begin
- @graph ||= get_oauth_client.web_server.get_access_token(self.token, :redirect_uri => FACEBOOK_OAUTH_REDIRECT)
- @graph.post("/me/links", d)
- rescue OAuth2::HTTPError
- # NOOP
- rescue OAuth2::AccessDenied
+ post("/me/links", {:body => d})
+ rescue OAuth2::Error
# NOOP
end
end
View
2 app/views/campaigns/edit.html.erb
@@ -1,5 +1,5 @@
<h1><%=@campaign.name%></h1>
-<% form_for @campaign, :url => campaign_path, :method => :put do |f|%>
+<%= form_for @campaign, :url => campaign_path, :method => :put do |f|%>
<%=render :partial => "layouts/errors", :locals => {:model => @campaign}%>
<%=f.label :name %>
<%=f.text_field :name%>
View
2 app/views/campaigns/new.html.erb
@@ -1,5 +1,5 @@
<h1>Create Campaign</h1>
-<% form_for @campaign do |f|%>
+<%= form_for @campaign do |f|%>
<%=render :partial => "layouts/errors", :locals => {:model => @campaign}%>
<%=f.label :name %>
<%=f.text_field :name%>
View
2 app/views/donations/facebook.html.erb
@@ -1,7 +1,7 @@
<div id="campaign">
<h1><%=image_tag(@campaign.image) if @campaign.image%><%=@campaign.name%></h1>
-<%form_for @donation, :url => facebook_campaign_donations_path(@campaign) do |f|%>
+<%=form_for @donation, :url => facebook_campaign_donations_path(@campaign) do |f|%>
<p>
Your account will automatically share links posted to the <strong><%=link_to @campaign.facebook_page["name"], @campaign.facebook_page["link"], :target => "_blank"%></strong> page on Facebook.
</p>
View
2 app/views/donations/twitter.html.erb
@@ -1,7 +1,7 @@
<div id="campaign">
<h1><%=image_tag(@campaign.image) if @campaign.image%><%=@campaign.name%></h1>
-<%form_for @donation, :url => twitter_campaign_donations_path(@campaign) do |f|%>
+<%=form_for @donation, :url => twitter_campaign_donations_path(@campaign) do |f|%>
<p>
Your account will automatically retweet messages posted to <strong><%=link_to "@#{@campaign.twitter_account.screen_name}", @campaign.twitter_account.url, :target => "_blank"%></strong> on Twitter.
</p>
View
4 config/initializers/oauth2_facebook.rb
@@ -0,0 +1,4 @@
+OAuth2::Response.register_parser(:facebook, 'text/plain') do |body|
+ token_key, token_value, expiration_key, expiration_value = body.split(/[=&]/)
+ {token_key => token_value, expiration_key => expiration_value, :mode => :query, :param_name => 'access_token'}
+end
View
BIN vendor/cache/httpauth-0.2.0.gem
Binary file not shown.
View
BIN vendor/cache/jwt-0.1.5.gem
Binary file not shown.
View
BIN vendor/cache/oauth2-0.8.0.gem
Binary file not shown.
View
BIN vendor/cache/twitter-4.1.0.gem
Binary file not shown.
View
BIN vendor/cache/twitter-4.2.0.gem
Binary file not shown.

0 comments on commit 22bbe99

Please sign in to comment.
Something went wrong with that request. Please try again.