Created
May 3, 2012 08:38
-
-
Save andrewytliu/2584413 to your computer and use it in GitHub Desktop.
CCSP 2012 Checkin
This file contains hidden or 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
# Gemfile | |
source 'https://rubygems.org' | |
gem 'rails', '3.2.3' | |
# Bundle edge Rails instead: | |
# gem 'rails', :git => 'git://github.com/rails/rails.git' | |
gem 'rest-graph' | |
gem 'rest-client' | |
gem 'json' | |
group :development do | |
gem 'sqlite3' | |
end | |
group :production do | |
gem 'pg' | |
end | |
# Gems used only for assets and not required | |
# in production environments by default. | |
group :assets do | |
gem 'sass-rails', '~> 3.2.3' | |
gem 'coffee-rails', '~> 3.2.1' | |
# See https://github.com/sstephenson/execjs#readme for more supported runtimes | |
gem 'therubyracer', :platform => :ruby | |
gem 'uglifier', '>= 1.0.3' | |
end | |
gem 'jquery-rails' | |
# To use ActiveModel has_secure_password | |
# gem 'bcrypt-ruby', '~> 3.0.0' | |
# To use Jbuilder templates for JSON | |
# gem 'jbuilder' | |
# Use unicorn as the app server | |
# gem 'unicorn' | |
# Deploy with Capistrano | |
# gem 'capistrano' | |
# To use debugger | |
# gem 'ruby-debug19', :require => 'ruby-debug' |
This file contains hidden or 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
# app/controller/home.rb | |
class HomeController < ApplicationController | |
include RestGraph::RailsUtil | |
before_filter :login_facebook, :only => [:login] | |
before_filter :load_facebook, :except => [:login] | |
def index | |
@access_token = rest_graph.access_token | |
if @access_token | |
@me = rest_graph.get('/me') | |
end | |
end | |
def login | |
redirect_to home_path | |
end | |
def logout | |
reset_session | |
redirect_to home_path | |
end | |
def checkin | |
unless rest_graph.access_token.nil? | |
# logged in | |
place_id = "152222568167545" | |
location = { :latitude => "25.019588", :longitude => "121.541722" } | |
tag = "1125666248" | |
message = "La la la!" | |
rest_graph.post('/me/checkins', :place => place_id, | |
:coordinates => location, | |
:tags => tag, | |
:message => message) | |
end | |
redirect_to home_path, :notice => 'Checked in CCSP!' | |
end | |
private | |
def load_facebook | |
rest_graph_setup(:write_session => true) | |
end | |
def login_facebook | |
rest_graph_setup(:auto_authorize => true, | |
:auto_authorize_scope => 'publish_checkins', | |
:ensure_authorized => true, | |
:write_session => true) | |
end | |
end |
This file contains hidden or 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
<!-- app/views/home/index.html.erb --> | |
<h1><%= notice %></h1> | |
<h1> Hello to everyone! </h1> | |
<p>Access token: <%= @access_token %></p> | |
<% if @access_token %> | |
<p>Logged in!</p> | |
<h2>Hi, <%= @me['name'] %></h2> | |
<img src="https://graph.facebook.com/me/picture?access_token=<%= @access_token %>" /> | |
<p><%= @me %></p> | |
<p><%= link_to 'Check in!', checkin_path %></p> | |
<p><%= link_to 'Log out', logout_path %></p> | |
<% else %> | |
<p><%= link_to 'Log in', login_path %></p> | |
<% end %> |
This file contains hidden or 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
# config/rest-graph.yaml | |
development: | |
app_id: '...' | |
secret: '...' | |
callback_host: 'localhost:3000' |
This file contains hidden or 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
Checkin::Application.routes.draw do | |
get '/' => 'home#index', :as => :home | |
get '/login' => 'home#login' | |
get '/logout' => 'home#logout' | |
get '/checkin' => 'home#checkin' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment