Browse files

add pictures example

  • Loading branch information...
1 parent dabf471 commit 925bbf45591eafaf947d69be4bd6961b78e37347 @nsanta committed May 10, 2010
View
1 Gemfile
@@ -29,3 +29,4 @@ gem 'oauth2'
gem 'ruby-debug'
gem 'json'
gem 'fbgraph'
+gem 'haml'
View
2 app/controllers/application_controller.rb
@@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
protected
def client(token = nil)
- @client ||= FBAuth::Client.new(:client_id => '114709451898747',
+ @client ||= FBGraph::Client.new(:client_id => '114709451898747',
:secret_id => '7c87164749a02552e3d204142e3af16b' ,
:token => token)
end
View
8 app/controllers/oauth_controller.rb
@@ -1,18 +1,20 @@
class OauthController < ApplicationController
def start
- redirect_to client.authorization.authorize_url(:redirect_uri => callback_oauths_url)
+ redirect_to client.authorization.authorize_url(:redirect_uri => callback_oauths_url , :scope => 'email,user_photos,friends_photos')
end
def callback
access_token = client.authorization.process_callback(params[:code], :redirect_uri => callback_oauths_url)
session[:access_token] = access_token
- user_json = client.selection.me.with('home').info
+ user_json = client.selection.me.home.info
# in reality you would at this point store the access_token.token value as well as
# any user info you wanted
render :json => user_json
end
-
+ def oclient
+ OAuth2::Client.new('114709451898747','7c87164749a02552e3d204142e3af16b', :site => 'https://graph.facebook.com')
+ end
end
View
10 app/controllers/pictures_controller.rb
@@ -0,0 +1,10 @@
+class PicturesController < ApplicationController
+ def index
+ end
+
+ def create
+ selection = client(session[:access_token]).selection
+ selection.send(params[:type], params[:object])
+ redirect_to selection.picture
+ end
+end
View
2 app/controllers/search_controller.rb
@@ -1,6 +1,6 @@
class SearchController < ApplicationController
- def index
+ def show
end
def create
View
2 app/controllers/selections_controller.rb
@@ -6,7 +6,7 @@ def index
def create
selection = client(session[:access_token]).selection
selection.send(params[:type], params[:object])
- selection.send(params[:connection_type]) unless params[:connection_type].blank
+ selection.send(params[:connection_type]) unless params[:connection_type].blank?
render :json => selection.info
end
View
2 app/helpers/application_helper.rb
@@ -1,2 +0,0 @@
-module ApplicationHelper
-end
View
2 app/helpers/oauth_helper.rb
@@ -1,2 +0,0 @@
-module OauthHelper
-end
View
2 app/helpers/search_helper.rb
@@ -1,2 +0,0 @@
-module SearchHelper
-end
View
2 app/helpers/selections_helper.rb
@@ -1,2 +0,0 @@
-module SelectionsHelper
-end
View
9 app/views/pictures/index.html.haml
@@ -0,0 +1,9 @@
+- form_tag do
+ .field
+ = label_tag :type
+ = text_field_tag :type
+ .field
+ = label_tag :object
+ = text_field_tag :object
+ .field
+ = submit_tag 'get picture'
View
10 app/views/search/show.html.haml
@@ -0,0 +1,10 @@
+- form_tag do
+ .field
+ = label_tag :query
+ = text_field_tag :q
+ .field
+ = label_tag :on
+ = text_field_tag :on
+ .field
+ = submit_tag 'search'
+
View
12 app/views/selections/index.html.haml
@@ -0,0 +1,12 @@
+- form_tag do
+ .field
+ = label_tag :type
+ = text_field_tag :type
+ .field
+ = label_tag :object
+ = text_field_tag :object
+ .field
+ = label_tag :connection_type
+ = text_field_tag :connection_type
+ .field
+ = submit_tag 'select'
View
6 config/application.rb
@@ -31,11 +31,11 @@ class Application < Rails::Application
# config.i18n.default_locale = :de
# Configure generators values. Many other options are available, be sure to check the documentation.
- # config.generators do |g|
+ config.generators do |g|
# g.orm :active_record
- # g.template_engine :erb
+ g.template_engine :haml
# g.test_framework :test_unit, :fixture => true
- # end
+ end
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
View
5 config/routes.rb
@@ -8,8 +8,11 @@
end
resources :selections
-
+ resources :pictures
resource :search , :controller => 'search'
+
+
+ root :to => 'oauth#start'
# The priority is based upon order of creation:
# first created -> highest priority.
View
279 public/index.html
@@ -1,279 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("images/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #search {
- margin: 0;
- padding-top: 10px;
- padding-bottom: 10px;
- font-size: 11px;
- }
- #search input {
- font-size: 11px;
- margin: 2px;
- }
- #search-text {width: 170px}
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
-
- function prepend() {
- search = document.getElementById('search-text');
- text = search.value;
- search.value = 'site:rubyonrails.org ' + text;
- }
-
- window.onload = function() {
- document.getElementById('search-text').value = '';
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <form id="search" action="http://www.google.com/search" method="get" onSubmit="prepend();">
- <input type="hidden" name="hl" value="en" />
- <input type="text" id="search-text" name="q" value="site:rubyonrails.org " />
- <input type="submit" value="Search" /> the Rails site
- </form>
- </li>
-
- <li>
- <h3>Join the community</h3>
- <ul class="links">
- <li><a href="http://www.rubyonrails.org/">Ruby on Rails</a></li>
- <li><a href="http://weblog.rubyonrails.org/">Official weblog</a></li>
- <li><a href="http://wiki.rubyonrails.org/">Wiki</a></li>
- </ul>
- </li>
-
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
- <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove or rename this file</h2>
- <p>Routes are set up in config/routes.rb.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:migrate</code> to create your database. If you're not using SQLite (the default), edit <code>config/database.yml</code> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
8 test/functional/picture_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PictureControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
4 test/unit/helpers/picture_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PictureHelperTest < ActionView::TestCase
+end

0 comments on commit 925bbf4

Please sign in to comment.