Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

facebook auth works

  • Loading branch information...
commit 18a90491edf59cf2c03a6f0d6fe943d9dc376865 1 parent 81b1496
@dhgwilliam authored
View
1  .gitignore
@@ -1,3 +1,4 @@
.bundle
*.swp
.sass-cache
+config.rb
View
1  Gemfile
@@ -3,3 +3,4 @@ gem 'sinatra'
gem 'haml'
gem 'sass'
gem 'redis'
+gem 'koala'
View
11 Gemfile.lock
@@ -1,7 +1,17 @@
GEM
remote: http://rubygems.org/
specs:
+ addressable (2.2.2)
+ faraday (0.7.6)
+ addressable (~> 2.2)
+ multipart-post (~> 1.1)
+ rack (~> 1.1)
haml (3.1.3)
+ koala (1.4.0)
+ faraday (~> 0.7.0)
+ multi_json (~> 1.0)
+ multi_json (1.2.0)
+ multipart-post (1.1.5)
rack (1.3.5)
rack-protection (1.1.4)
rack
@@ -18,6 +28,7 @@ PLATFORMS
DEPENDENCIES
haml
+ koala
redis
sass
sinatra
View
4 config.rb.example
@@ -0,0 +1,4 @@
+API_KEY = ""
+APP_SECRET = ""
+CALLBACK_URL = ""
+
View
29 index.rb
@@ -1,4 +1,10 @@
require 'json'
+require 'koala'
+require './config'
+
+OAUTH = Koala::Facebook::OAuth.new(API_KEY, APP_SECRET, CALLBACK_URL)
+
+enable :sessions
redis = Redis.new
redis.select 1
@@ -12,9 +18,31 @@
@start = 0
@finish = @start + 9
@article_array = redis.keys("*reader/item/*").sort { |x,y| y <=> x }.slice(0..9)
+ @oauth_url = OAUTH.url_for_oauth_code(:permissions => "publish_stream")
+ unless session["access_token"].nil?
+ GRAPH = Koala::Facebook::API.new(session["access_token"])
+ @uid = GRAPH.get_object("me")["first_name"]
+ end
haml :list
end
+get '/login' do
+ if params[:code]
+ session["code"] = params[:code]
+ session["access_token"] = OAUTH.get_access_token(session["code"])
+ end
+ redirect to('/')
+end
+
+get '/logout' do
+ session["access_token"] = nil
+ redirect to('/')
+end
+
+get '/post' do
+
+end
+
get '/random' do
@object = JSON.parse(redis.get(redis.randomkey))
if @object.has_key?("content")
@@ -71,6 +99,7 @@
sass :"css/#{params[:stylesheet]}"
end
+
helpers do
def get_article(key)
redis = Redis.new
View
8 views/list.haml
@@ -3,6 +3,8 @@
%link{:href => "/css/960.css", :rel => "stylesheet", :type => "text/css"}
%head
%title david's shared items
+ :javascript
+ if (window.location.hash == '#_=_')window.location.hash = '';
%body
.clear
#content.container-12
@@ -12,6 +14,12 @@
%a{:href => "/popular"} popular
\-
%a{:href => "/random"} random
+ - if session["access_token"].nil?
+ \-
+ %a{:href => "#{@oauth_url}"} login
+ - else
+ \-
+ %a{:href => "/logout"}= "logout " + @uid
#body.grid-8.prefix-2
- 0.upto(9) do |x|
- @article_id = @article_array[x]
Please sign in to comment.
Something went wrong with that request. Please try again.