frankie 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ v0.2.0. Converted codebase to become Ruby Gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Ron Evans
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.
@@ -0,0 +1,7 @@
1
+ CHANGELOG
2
+ lib/frankie.rb
3
+ LICENSE
4
+ Manifest
5
+ Rakefile
6
+ README.rdoc
7
+ test/frankie_test.rb
@@ -0,0 +1,69 @@
1
+ = Frankie
2
+
3
+ Frankie (http://facethesinatra.com) is a plugin for the Sinatra web framework (http://sinatrarb.com) that allows you to easily create a Facebook application by using the Facebooker gem.
4
+
5
+ Written by Ron Evans (http://www.deadprogrammersociety.com)
6
+
7
+ Based on merb_facebooker (http://github.com/vanpelt/merb_facebooker) by Chris Van Pelt, which was based on
8
+ the Rails classes in Facebooker (http://facebooker.rubyforge.org/) by Mike Mangino, Shane Vitarana, & Chad Fowler
9
+
10
+ Thanks, everyone!
11
+
12
+ = Here is a very simple example application:
13
+
14
+ require 'rubygems'
15
+ require 'frankie'
16
+
17
+ configure do
18
+ set_option :sessions, true
19
+ load_facebook_config "./config/facebooker.yml", Sinatra.env
20
+ end
21
+
22
+ ## facebooker helpers
23
+ before do
24
+ ensure_authenticated_to_facebook
25
+ ensure_application_is_installed_by_facebook_user
26
+ end
27
+
28
+ ## the site
29
+ get '/' do
30
+ body "<h1>Hello #{session['facebook_session'].user.name} and welcome to frankie!</h1>"
31
+ end
32
+
33
+
34
+ = How to use frankie
35
+ - Install the frankie gem (which will install both Sinatra and Facebooker if you do not already have them)
36
+ sudo gem install frankie
37
+
38
+ - Create the application directories for your new app
39
+ mkdir myapp
40
+ cd myapp
41
+ mkdir config
42
+
43
+ - Put your facebooker.yml file into the /myapp/config directory, and set the values to your information. Here is a simple example of the file:
44
+
45
+ development:
46
+ api_key: apikeyhere
47
+ secret_key: secretkeyhere
48
+ canvas_page_name: yourcanvashere
49
+ callback_url: http://localhost:4567
50
+ test:
51
+ api_key: apikeyhere
52
+ secret_key: secretkeyhere
53
+ canvas_page_name: yourcanvashere
54
+ callback_url: http://localhost:4567
55
+ production:
56
+ api_key: apikeyhere
57
+ secret_key: secretkeyhere
58
+ canvas_page_name: yourcanvashere
59
+ callback_url: http://yourrealserver.com
60
+
61
+
62
+ - Make sure you have setup your Facebook application on the facebook site. Google "setup new facebook application" if you are unsure how to do this. I recommend starting with an IFrame application. A more advanced and cooler approach uses a tunneling script like this one: http://pastie.caboo.se/178903
63
+
64
+ - Create your application, based on the sample above, and then run it:
65
+ ruby sample.rb
66
+
67
+ - Test your app by going to http://apps.facebook.com/yourappname
68
+
69
+ Have fun!
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'echoe'
5
+
6
+ task :default => :test
7
+
8
+ Rake::RDocTask.new do |rd|
9
+ rd.main = "README.rdoc"
10
+ rd.rdoc_files += ["README.rdoc"]
11
+ rd.rdoc_files += Dir.glob("lib/**/*.rb")
12
+ rd.rdoc_dir = 'doc'
13
+ end
14
+
15
+ Rake::TestTask.new do |t|
16
+ ENV['SINATRA_ENV'] = 'test'
17
+ t.pattern = File.dirname(__FILE__) + "/test/*_test.rb"
18
+ end
19
+
20
+ Echoe.new("frankie") do |p|
21
+ p.author = "Ron Evans"
22
+ p.summary = "Easy creation of Facebook applications in Ruby using plugin for Sinatra web framework that integrates with Facebooker gem."
23
+ p.url = "http://facethesinatra.com/"
24
+ # p.docs_host = "sinatrarb.com:/var/www/blakemizerany.com/public/docs/"
25
+ p.dependencies = ["sinatra >=0.2.0", "facebooker >=0.9.5"]
26
+ p.install_message = "*** Frankie was installed ***"
27
+ p.include_rakefile = true
28
+ end
29
+
@@ -0,0 +1,63 @@
1
+
2
+ # Gem::Specification for Frankie-0.2.0
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{frankie}
7
+ s.version = "0.2.0"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Ron Evans"]
13
+ s.date = %q{2008-04-12}
14
+ s.description = %q{Easy creation of Facebook applications in Ruby using plugin for Sinatra web framework that integrates with Facebooker gem.}
15
+ s.email = %q{}
16
+ s.extra_rdoc_files = ["CHANGELOG", "lib/frankie.rb", "LICENSE", "README.rdoc"]
17
+ s.files = ["CHANGELOG", "lib/frankie.rb", "LICENSE", "Manifest", "Rakefile", "README.rdoc", "test/frankie_test.rb", "frankie.gemspec"]
18
+ s.has_rdoc = true
19
+ s.homepage = %q{http://facethesinatra.com/}
20
+ s.post_install_message = %q{*** Frankie was installed ***}
21
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Frankie", "--main", "README.rdoc"]
22
+ s.require_paths = ["lib"]
23
+ s.rubyforge_project = %q{frankie}
24
+ s.rubygems_version = %q{1.1.1}
25
+ s.summary = %q{Easy creation of Facebook applications in Ruby using plugin for Sinatra web framework that integrates with Facebooker gem.}
26
+ s.test_files = ["test/frankie_test.rb"]
27
+
28
+ s.add_dependency(%q<sinatra>, [">= 0.2.0"])
29
+ s.add_dependency(%q<facebooker>, [">= 0.9.5"])
30
+ end
31
+
32
+
33
+ # # Original Rakefile source (requires the Echoe gem):
34
+ #
35
+ # require 'rubygems'
36
+ # require 'rake/testtask'
37
+ # require 'rake/rdoctask'
38
+ # require 'echoe'
39
+ #
40
+ # task :default => :test
41
+ #
42
+ # Rake::RDocTask.new do |rd|
43
+ # rd.main = "README.rdoc"
44
+ # rd.rdoc_files += ["README.rdoc"]
45
+ # rd.rdoc_files += Dir.glob("lib/**/*.rb")
46
+ # rd.rdoc_dir = 'doc'
47
+ # end
48
+ #
49
+ # Rake::TestTask.new do |t|
50
+ # ENV['SINATRA_ENV'] = 'test'
51
+ # t.pattern = File.dirname(__FILE__) + "/test/*_test.rb"
52
+ # end
53
+ #
54
+ # Echoe.new("frankie") do |p|
55
+ # p.author = "Ron Evans"
56
+ # p.summary = "Easy creation of Facebook applications in Ruby using plugin for Sinatra web framework that integrates with Facebooker gem."
57
+ # p.url = "http://facethesinatra.com/"
58
+ # # p.docs_host = "sinatrarb.com:/var/www/blakemizerany.com/public/docs/"
59
+ # p.dependencies = ["sinatra >=0.2.0", "facebooker >=0.9.5"]
60
+ # p.install_message = "*** Frankie was installed ***"
61
+ # p.include_rakefile = true
62
+ # end
63
+ #
@@ -0,0 +1,186 @@
1
+ # frankie - a plugin for sinatra that integrates with the facebooker gem
2
+ #
3
+ # written by Ron Evans (http://www.deadprogrammersociety.com)
4
+ #
5
+ # based on merb_facebooker (http://github.com/vanpelt/merb_facebooker)
6
+ # and the Rails classes in Facebooker (http://facebooker.rubyforge.org/) from Mike Mangino, Shane Vitarana, & Chad Fowler
7
+ #
8
+
9
+ require 'sinatra'
10
+
11
+ module Frankie
12
+
13
+ module Loader
14
+
15
+ require "yaml"
16
+
17
+ def load_facebook_config(file, env=:development)
18
+ if File.exist?(file)
19
+ yaml = YAML.load_file(file)[env.to_s]
20
+ ENV['FACEBOOK_API_KEY'] = yaml['api_key']
21
+ ENV['FACEBOOK_SECRET_KEY'] = yaml['secret_key']
22
+ ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = yaml['canvas_page_name']
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ module EventContext
29
+
30
+ require "facebooker"
31
+
32
+ def facebook_session
33
+ @facebook_session
34
+ end
35
+
36
+ def facebook_session_parameters
37
+ {:fb_sig_session_key=>params["fb_sig_session_key"]}
38
+ end
39
+
40
+ def set_facebook_session
41
+ session_set = session_already_secured? || secure_with_token! || secure_with_facebook_params!
42
+ if session_set
43
+ capture_facebook_friends_if_available!
44
+ Facebooker::Session.current = facebook_session
45
+ end
46
+ session_set
47
+ end
48
+
49
+ def facebook_params
50
+ @facebook_params ||= verified_facebook_params
51
+ end
52
+
53
+ private
54
+
55
+ def session_already_secured?
56
+ (@facebook_session = session['facebook_session']) && session['facebook_session'].secured?
57
+ end
58
+
59
+ def secure_with_token!
60
+ if params['auth_token']
61
+ @facebook_session = new_facebook_session
62
+ @facebook_session.auth_token = params['auth_token']
63
+ @facebook_session.secure!
64
+ session['facebook_session'] = @facebook_session
65
+ end
66
+ end
67
+
68
+ def secure_with_facebook_params!
69
+ return unless request_is_for_a_facebook_canvas?
70
+
71
+ if ['user', 'session_key'].all? {|element| facebook_params[element]}
72
+ @facebook_session = new_facebook_session
73
+ @facebook_session.secure_with!(facebook_params['session_key'], facebook_params['user'], facebook_params['expires'])
74
+ session[:facebook_session] = @facebook_session
75
+ end
76
+ end
77
+
78
+ def create_new_facebook_session_and_redirect!
79
+ s = new_facebook_session
80
+ session['facebook_session'] = s
81
+ throw :halt, do_redirect(session['facebook_session'].login_url) unless @installation_required
82
+ end
83
+
84
+ def new_facebook_session
85
+ Facebooker::Session.create(Facebooker::Session.api_key, Facebooker::Session.secret_key)
86
+ end
87
+
88
+ def capture_facebook_friends_if_available!
89
+ return unless request_is_for_a_facebook_canvas?
90
+ if friends = facebook_params['friends']
91
+ facebook_session.user.friends = friends.map do |friend_uid|
92
+ User.new(friend_uid, facebook_session)
93
+ end
94
+ end
95
+ end
96
+
97
+ def blank?(value)
98
+ (value == '0' || value.nil? || value == '')
99
+ end
100
+
101
+ def verified_facebook_params
102
+ facebook_sig_params = params.inject({}) do |collection, pair|
103
+ collection[pair.first.sub(/^fb_sig_/, '')] = pair.last if pair.first[0,7] == 'fb_sig_'
104
+ collection
105
+ end
106
+ verify_signature(facebook_sig_params, params['fb_sig'])
107
+ facebook_sig_params.inject(Hash.new) do |collection, pair|
108
+ collection[pair.first] = facebook_parameter_conversions[pair.first].call(pair.last)
109
+ collection
110
+ end
111
+ end
112
+
113
+ # 48.hours.ago in sinatra
114
+ def earliest_valid_session
115
+ now = Time.now
116
+ now -= (60 * 60 * 48)
117
+ now
118
+ end
119
+
120
+ def verify_signature(facebook_sig_params,expected_signature)
121
+ raw_string = facebook_sig_params.map{ |*args| args.join('=') }.sort.join
122
+ actual_sig = Digest::MD5.hexdigest([raw_string, Facebooker::Session.secret_key].join)
123
+ raise Facebooker::Session::IncorrectSignature if actual_sig != expected_signature
124
+ raise Facebooker::Session::SignatureTooOld if Time.at(facebook_sig_params['time'].to_f) < earliest_valid_session
125
+ true
126
+ end
127
+
128
+ def facebook_parameter_conversions
129
+ @facebook_parameter_conversions ||= Hash.new do |hash, key|
130
+ lambda{|value| value}
131
+ end.merge(
132
+ 'time' => lambda{|value| Time.at(value.to_f)},
133
+ 'in_canvas' => lambda{|value| !blank?(value)},
134
+ 'added' => lambda{|value| !blank?(value)},
135
+ 'expires' => lambda{|value| blank?(value) ? nil : Time.at(value.to_f)},
136
+ 'friends' => lambda{|value| value.split(/,/)}
137
+ )
138
+ end
139
+
140
+ def do_redirect(*args)
141
+ if request_is_for_a_facebook_canvas?
142
+ fbml_redirect_tag(args[0])
143
+ else
144
+ redirect args[0]
145
+ end
146
+ end
147
+
148
+ def fbml_redirect_tag(url)
149
+ "<fb:redirect url=\"#{url}\" />"
150
+ end
151
+
152
+ def request_is_for_a_facebook_canvas?
153
+ return false if !params["fb_sig_in_canvas"]
154
+ !params["fb_sig_in_canvas"].blank?
155
+ end
156
+
157
+ def application_is_installed?
158
+ facebook_params['added']
159
+ end
160
+
161
+ def ensure_authenticated_to_facebook
162
+ set_facebook_session || create_new_facebook_session_and_redirect!
163
+ end
164
+
165
+ def ensure_application_is_installed_by_facebook_user
166
+ @installation_required = true
167
+ authenticated_and_installed = ensure_authenticated_to_facebook && application_is_installed?
168
+ application_is_not_installed_by_facebook_user unless authenticated_and_installed
169
+ authenticated_and_installed
170
+ end
171
+
172
+ def application_is_not_installed_by_facebook_user
173
+ throw :halt, do_redirect(session['facebook_session'].install_url)
174
+ end
175
+
176
+ def set_fbml_format
177
+ params['format']="fbml" if request_is_for_a_facebook_canvas?
178
+ end
179
+
180
+ end
181
+
182
+ end
183
+
184
+ # extend sinatra with frankie methods
185
+ Sinatra::EventContext.send(:include, Frankie::EventContext)
186
+ include Frankie::Loader
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ context "frankie" do
4
+ it "should be a placeholder for a real test"
5
+ end
6
+
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frankie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ron Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.0
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: facebooker
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.9.5
32
+ version:
33
+ description: Easy creation of Facebook applications in Ruby using plugin for Sinatra web framework that integrates with Facebooker gem.
34
+ email: ""
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - CHANGELOG
41
+ - lib/frankie.rb
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - CHANGELOG
46
+ - lib/frankie.rb
47
+ - LICENSE
48
+ - Manifest
49
+ - Rakefile
50
+ - README.rdoc
51
+ - test/frankie_test.rb
52
+ - frankie.gemspec
53
+ has_rdoc: true
54
+ homepage: http://facethesinatra.com/
55
+ post_install_message: "*** Frankie was installed ***"
56
+ rdoc_options:
57
+ - --line-numbers
58
+ - --inline-source
59
+ - --title
60
+ - Frankie
61
+ - --main
62
+ - README.rdoc
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project: frankie
80
+ rubygems_version: 1.1.1
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: Easy creation of Facebook applications in Ruby using plugin for Sinatra web framework that integrates with Facebooker gem.
84
+ test_files:
85
+ - test/frankie_test.rb