fbgraph_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .loadpath
2
+ pkg
3
+
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>fbgraph_rails</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,30 @@
1
+ FbgraphRails
2
+ ============
3
+
4
+ Integrates the fbgraph gem for the Facebook OpenGraph API with Rails
5
+ applications. Useful for session management.
6
+
7
+
8
+ Installation
9
+ =======
10
+
11
+ Add the following to your controllers:
12
+
13
+ # Acts a like a before_filter.
14
+ requires_facebook_access_token :except => :new
15
+ # Also acts like a before_filter, but doesn't redirect to Facebook.
16
+ probes_facebook_access_token :except => :new
17
+
18
+ The following methods become available to your controllers.
19
+
20
+ # FBGraph client.
21
+ facebook_client
22
+
23
+ # The raw Facebook access token, or nil.
24
+ current_facebook_access_token
25
+
26
+ # Set the Facebook access token, e.g. when a different login method is used.
27
+ current_facebook_access_token=
28
+
29
+
30
+ Copyright (c) 2010 Victor Costan, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "fbgraph_rails"
8
+ gem.summary = %Q{Rails plug-in for integrating the fbgraph gem}
9
+ gem.description = %Q{Support for sessions tied to Facebook users.}
10
+ gem.email = "victor@costan.us"
11
+ gem.homepage = "http://github.com/costan/fbgraph_rails"
12
+ gem.authors = ["costan"]
13
+ gem.add_dependency "erubis", ">= 2.3.5"
14
+ gem.add_dependency "fbgraph", ">= 0.0.5"
15
+ gem.add_dependency "json", ">= 1.4.2"
16
+ gem.add_dependency "oauth2", ">= 0.0.8"
17
+ gem.add_development_dependency "jeweler", ">=1.4.0"
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "fbgraph_rails #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,22 @@
1
+ class FacebookOauthController < ApplicationController
2
+ probes_facebook_access_token
3
+
4
+ # GET /facebook_oauth/new
5
+ def new
6
+ self.current_facebook_access_token = nil
7
+ enforce_facebook_access_token root_path
8
+ end
9
+
10
+ # Redirect from Facebook: GET /facebook_oauth
11
+ def show
12
+ self.current_facebook_access_token =
13
+ facebook_client.authorization.process_callback params[:code],
14
+ :redirect_uri => facebook_oauth_url
15
+ redirect_to flash[:facebook_redirect_url]
16
+ end
17
+
18
+ # DELETE /facebook_oauth
19
+ def destroy
20
+ self.current_facebook_access_token = nil
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module FacebookOauthHelper
2
+ attr_reader :facebook_client
3
+ attr_reader :current_facebook_access_token
4
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails::Application.routes.draw do |map|
2
+ resource :facebook_oauth, :controller => 'FacebookOauth'
3
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fbgraph_rails}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["costan"]
12
+ s.date = %q{2010-05-27}
13
+ s.description = %q{Support for sessions tied to Facebook users.}
14
+ s.email = %q{victor@costan.us}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ ".project",
21
+ "MIT-LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "app/controllers/facebook_oauth_controller.rb",
26
+ "app/helpers/facebook_oauth_helper.rb",
27
+ "config/routes.rb",
28
+ "fbgraph_rails.gemspec",
29
+ "lib/fbgraph_rails.rb",
30
+ "lib/fbgraph_rails/controller.rb",
31
+ "lib/fbgraph_rails/engine.rb",
32
+ "lib/fbgraph_rails/fbgraph_client.rb",
33
+ "test/fbgraph_rails_test.rb",
34
+ "test/test_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/costan/fbgraph_rails}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{Rails plug-in for integrating the fbgraph gem}
41
+ s.test_files = [
42
+ "test/fbgraph_rails_test.rb",
43
+ "test/test_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<erubis>, [">= 2.3.5"])
52
+ s.add_runtime_dependency(%q<fbgraph>, [">= 0.0.5"])
53
+ s.add_runtime_dependency(%q<json>, [">= 1.4.2"])
54
+ s.add_runtime_dependency(%q<oauth2>, [">= 0.0.8"])
55
+ s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
56
+ else
57
+ s.add_dependency(%q<erubis>, [">= 2.3.5"])
58
+ s.add_dependency(%q<fbgraph>, [">= 0.0.5"])
59
+ s.add_dependency(%q<json>, [">= 1.4.2"])
60
+ s.add_dependency(%q<oauth2>, [">= 0.0.8"])
61
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<erubis>, [">= 2.3.5"])
65
+ s.add_dependency(%q<fbgraph>, [">= 0.0.5"])
66
+ s.add_dependency(%q<json>, [">= 1.4.2"])
67
+ s.add_dependency(%q<oauth2>, [">= 0.0.8"])
68
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,10 @@
1
+ # FbgraphRails
2
+ module FBGraphRails
3
+ end
4
+
5
+ require 'fbgraph_rails/fbgraph_client.rb'
6
+
7
+ if defined?(Rails)
8
+ require 'fbgraph_rails/controller.rb'
9
+ require 'fbgraph_rails/engine.rb'
10
+ end
@@ -0,0 +1,57 @@
1
+ require 'action_controller'
2
+
3
+ # :nodoc: namespace
4
+ module FBGraphRails
5
+
6
+ # Mixed into ActiveController::Base
7
+ module ControllerMixin
8
+ def self.included(base)
9
+ base.send :extend, ControllerClassMethods
10
+ end
11
+ end
12
+
13
+ # Methods here become ActiveController::Base class methods.
14
+ module ControllerClassMethods
15
+ def probes_facebook_access_token(options = {})
16
+ send :include, ControllerInstanceMethods
17
+ before_filter :probe_facebook_access_token, options
18
+ end
19
+
20
+ def requires_facebook_access_token
21
+ send :include, ControllerInstanceMethods
22
+ before_filter :enforce_facebook_access_token, options
23
+ end
24
+ end
25
+
26
+ # Included in controllers that call the ActiveController::Base class methods.
27
+ module ControllerInstanceMethods
28
+ attr_reader :facebook_client
29
+ attr_reader :current_facebook_access_token
30
+
31
+ def current_facebook_access_token=(new_token)
32
+ @current_facebook_access_token = new_token
33
+ session[:facebook_token] = new_token
34
+ end
35
+
36
+ def probe_facebook_access_token
37
+ @current_facebook_access_token = session[:facebook_token]
38
+ @facebook_client = if @current_facebook_access_token
39
+ FBGraphRails.global_fbclient
40
+ else
41
+ FBGraphRails.fbclient @current_facebook_access_token
42
+ end
43
+ end
44
+
45
+ def enforce_facebook_access_token(redirect_url = request.url)
46
+ probe_facebook_access_token
47
+ unless current_facebook_access_token
48
+ flash[:facebook_redirect_url] = redirect_url
49
+ redirect_to FBGraphRails.authorization_url(facebook_oauth_url)
50
+ return false
51
+ end
52
+ end
53
+ end
54
+
55
+ ActionController::Base.send :include, ControllerMixin
56
+
57
+ end # namespace FBGraphRails
@@ -0,0 +1,22 @@
1
+ require 'fbgraph_rails'
2
+ require 'rails'
3
+
4
+ # :nodoc: namespace
5
+ module FBGraphRails
6
+
7
+ class Engine < Rails::Engine
8
+ # paths.app = "app"
9
+ paths.app.controllers = "app/controllers"
10
+ paths.app.helpers = "app/helpers"
11
+ paths.app.models = "app/models"
12
+ paths.app.metals = "app/metal"
13
+ paths.app.views = "app/views"
14
+ paths.lib = "lib"
15
+ paths.lib.tasks = "lib/tasks"
16
+ # paths.config = "config"
17
+ # paths.config.initializers = "config/initializers"
18
+ # paths.config.locales = "config/locales"
19
+ paths.config.routes = "config/routes.rb"
20
+ end # class FBGraphRails::Engine
21
+
22
+ end # namespace FBGraphRails
@@ -0,0 +1,32 @@
1
+ require 'erubis'
2
+ require 'fbgraph'
3
+
4
+ module FBGraphRails
5
+ def self.config
6
+ @config ||= config_without_caching
7
+ end
8
+
9
+ def self.config_without_caching
10
+ erb_file = File.read(Rails.root.join('config', 'fbgraph.yml'))
11
+ YAML.load Erubis::Eruby.new(erb_file).result
12
+ end
13
+
14
+ def self.global_fbclient
15
+ @client ||= new_global_fbclient
16
+ end
17
+
18
+ def self.fbclient(access_token)
19
+ FBGraph::Client.new :client_id => config['id'], :token => access_token,
20
+ :secret_id => config['secret']
21
+ end
22
+
23
+ def self.new_global_fbclient
24
+ FBGraph::Client.new :client_id => config['id'],
25
+ :secret_id => config['secret']
26
+ end
27
+
28
+ def self.authorization_url(redirect_url)
29
+ global_fbclient.authorization.authorize_url :redirect_uri => redirect_url,
30
+ :scope => config['scope'].sort.join(',')
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class FbgraphRailsTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fbgraph_rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - costan
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-27 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: erubis
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 5
31
+ version: 2.3.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: fbgraph
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 0
44
+ - 5
45
+ version: 0.0.5
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: json
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 4
58
+ - 2
59
+ version: 1.4.2
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: oauth2
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 0
72
+ - 8
73
+ version: 0.0.8
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: jeweler
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 1
85
+ - 4
86
+ - 0
87
+ version: 1.4.0
88
+ type: :development
89
+ version_requirements: *id005
90
+ description: Support for sessions tied to Facebook users.
91
+ email: victor@costan.us
92
+ executables: []
93
+
94
+ extensions: []
95
+
96
+ extra_rdoc_files:
97
+ - README
98
+ files:
99
+ - .gitignore
100
+ - .project
101
+ - MIT-LICENSE
102
+ - README
103
+ - Rakefile
104
+ - VERSION
105
+ - app/controllers/facebook_oauth_controller.rb
106
+ - app/helpers/facebook_oauth_helper.rb
107
+ - config/routes.rb
108
+ - fbgraph_rails.gemspec
109
+ - lib/fbgraph_rails.rb
110
+ - lib/fbgraph_rails/controller.rb
111
+ - lib/fbgraph_rails/engine.rb
112
+ - lib/fbgraph_rails/fbgraph_client.rb
113
+ - test/fbgraph_rails_test.rb
114
+ - test/test_helper.rb
115
+ has_rdoc: true
116
+ homepage: http://github.com/costan/fbgraph_rails
117
+ licenses: []
118
+
119
+ post_install_message:
120
+ rdoc_options:
121
+ - --charset=UTF-8
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirements: []
139
+
140
+ rubyforge_project:
141
+ rubygems_version: 1.3.6
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Rails plug-in for integrating the fbgraph gem
145
+ test_files:
146
+ - test/fbgraph_rails_test.rb
147
+ - test/test_helper.rb