merb_facebooker 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +15 -0
- data/Rakefile +22 -0
- data/TODO +5 -0
- data/lib/merb_facebooker/controller.rb +228 -0
- data/lib/merb_facebooker/helpers.rb +111 -0
- data/lib/merb_facebooker/merbtasks.rb +50 -0
- data/lib/merb_facebooker/version.rb +5 -0
- data/lib/merb_facebooker.rb +35 -0
- data/spec/merb_facebooker_spec.rb +53 -0
- data/spec/spec_helper.rb +26 -0
- metadata +102 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 YOUR NAME
|
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,15 @@
|
|
1
|
+
merb_facebooker
|
2
|
+
===============
|
3
|
+
|
4
|
+
A plugin for Merb that hooks up the facebooker gem. Currently it just mixes some good stuff into Merb::Controller... the helpers are missing along with the CGI extentions. These should be easily ported from the rails plugin portion of facebooker... I just haven't needed it yet.
|
5
|
+
|
6
|
+
Finnaly facebook comes to Merb :)
|
7
|
+
|
8
|
+
Installation
|
9
|
+
==============
|
10
|
+
|
11
|
+
git clone git://github.com/vanpelt/merb_facebooker.git
|
12
|
+
cd merb_facebooker
|
13
|
+
rake gem
|
14
|
+
cd ../your_merb_app
|
15
|
+
gem install -i gems ../merb_facebooker/pkg/merb_facebooker-*.gem
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
NAME = 'merb_facebooker'.freeze
|
4
|
+
|
5
|
+
desc "Builds gem"
|
6
|
+
task :build do
|
7
|
+
sh %{gem build #{NAME}.gemspec}
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Installs gem"
|
11
|
+
task :install => [:package] do
|
12
|
+
sh %{sudo gem install pkg/#{NAME}-#{Facebooker::Merb::VERSION}}
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :jruby do
|
16
|
+
|
17
|
+
desc "Run :package and install the resulting .gem with jruby"
|
18
|
+
task :install => :package do
|
19
|
+
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Facebooker::Merb::VERSION}.gem --no-rdoc --no-ri}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
module Facebooker
|
2
|
+
module Merb
|
3
|
+
module Controller
|
4
|
+
|
5
|
+
def self.included(controller)
|
6
|
+
controller.extend(ClassMethods)
|
7
|
+
controller.before :set_fbml_format
|
8
|
+
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# Just returns the @facebook_session instance variable
|
12
|
+
#
|
13
|
+
def facebook_session
|
14
|
+
@facebook_session
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Tries to secure the facebook_session, if it is not secured already, it tries to secure it
|
19
|
+
# via the request parameter 'auth_token', if that doesn't work, it tries to use the parameters
|
20
|
+
# from facebook (this could be in the request or via cookies [cookies in case of FBConnect]).
|
21
|
+
#
|
22
|
+
def set_facebook_session
|
23
|
+
session_set = session_already_secured? || secure_with_token! || secure_with_facebook_params!
|
24
|
+
if session_set
|
25
|
+
capture_facebook_friends_if_available!
|
26
|
+
Session.current = facebook_session
|
27
|
+
end
|
28
|
+
session_set
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# initializes the @facebook_params instance using the method verified_facebook_params
|
33
|
+
#
|
34
|
+
def facebook_params
|
35
|
+
@facebook_params ||= verified_facebook_params
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
#
|
41
|
+
# Ensures there is an existing facebook session, and if so, it ask if it is secured.
|
42
|
+
#
|
43
|
+
def session_already_secured?
|
44
|
+
(@facebook_session = session[:facebook_session]) && session[:facebook_session].secured?
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Use auth_token parameter for the creation of a facebook_session
|
49
|
+
#
|
50
|
+
def secure_with_token!
|
51
|
+
if params['auth_token']
|
52
|
+
@facebook_session = new_facebook_session
|
53
|
+
@facebook_session.auth_token = params['auth_token']
|
54
|
+
@facebook_session.secure!
|
55
|
+
session[:facebook_session] = @facebook_session
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# If the request is made from a facebook canvas, then it checks for the session key and the user
|
61
|
+
# from the facebook_params hash key
|
62
|
+
#
|
63
|
+
def secure_with_facebook_params!
|
64
|
+
debugger
|
65
|
+
return if !request_is_for_a_facebook_canvas? && !using_facebook_connect?
|
66
|
+
|
67
|
+
if ['user', 'session_key'].all? {|element| facebook_params[element]}
|
68
|
+
@facebook_session = new_facebook_session
|
69
|
+
@facebook_session.secure_with!(facebook_params['session_key'], facebook_params['user'], facebook_params['expires'])
|
70
|
+
session[:facebook_session] = @facebook_session
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Resets the facebook_session
|
76
|
+
#
|
77
|
+
def create_new_facebook_session_and_redirect!
|
78
|
+
session[:facebook_session] = new_facebook_session
|
79
|
+
throw :halt, redirect(session[:facebook_session].login_url) unless @installation_required
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Facebooker Session Factory
|
84
|
+
#
|
85
|
+
def new_facebook_session
|
86
|
+
Facebooker::Session.create(Facebooker::Session.api_key, Facebooker::Session.secret_key)
|
87
|
+
end
|
88
|
+
|
89
|
+
def capture_facebook_friends_if_available!
|
90
|
+
return unless request_is_for_a_facebook_canvas?
|
91
|
+
if friends = facebook_params['friends']
|
92
|
+
facebook_session.user.friends = friends.map do |friend_uid|
|
93
|
+
User.new(friend_uid, facebook_session)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# Helper method (acts as ActiveSupport's blank? method)
|
100
|
+
#
|
101
|
+
def blank?(value)
|
102
|
+
(value == '0' || value.nil? || value == '')
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Get all the parameters from facebook via the request or cookies...
|
107
|
+
# (Cookies have more presedence)
|
108
|
+
#
|
109
|
+
def verified_facebook_params
|
110
|
+
if !request.cookies[Facebooker::Session.api_key].blank?
|
111
|
+
facebook_sig_params = request.cookies.inject({}) do |collection, pair|
|
112
|
+
if pair.first =~ /^#{Facebooker::Session.api_key}_(.+)/
|
113
|
+
collection[$1] = pair.last
|
114
|
+
end
|
115
|
+
collection
|
116
|
+
end
|
117
|
+
else
|
118
|
+
# same ol...
|
119
|
+
facebook_sig_params = params.inject({}) do |collection, pair|
|
120
|
+
collection[pair.first.sub(/^fb_sig_/, '')] = pair.last if pair.first[0,7] == 'fb_sig_'
|
121
|
+
collection
|
122
|
+
end
|
123
|
+
verify_signature(facebook_sig_params, params['fb_sig'])
|
124
|
+
end
|
125
|
+
|
126
|
+
facebook_sig_params.inject(Mash.new) do |collection, pair|
|
127
|
+
collection[pair.first] = facebook_parameter_conversions[pair.first].call(pair.last)
|
128
|
+
collection
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Session timeout value
|
134
|
+
#
|
135
|
+
def earliest_valid_session
|
136
|
+
48.hours.ago
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
#
|
141
|
+
# Checks if the signature matches the hash made from the parameters (does not apply on FBConnect)
|
142
|
+
#
|
143
|
+
def verify_signature(facebook_sig_params,expected_signature)
|
144
|
+
raw_string = facebook_sig_params.map{ |*args| args.join('=') }.sort.join
|
145
|
+
actual_sig = Digest::MD5.hexdigest([raw_string, Facebooker::Session.secret_key].join)
|
146
|
+
raise Facebooker::Session::IncorrectSignature if actual_sig != expected_signature
|
147
|
+
raise Facebooker::Session::SignatureTooOld if Time.at(facebook_sig_params['time'].to_f) < earliest_valid_session
|
148
|
+
true
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Parses the values from facebook_parameters
|
153
|
+
#
|
154
|
+
def facebook_parameter_conversions
|
155
|
+
@facebook_parameter_conversions ||= Hash.new do |hash, key|
|
156
|
+
lambda{|value| value}
|
157
|
+
end.merge(
|
158
|
+
'time' => lambda{|value| Time.at(value.to_f)},
|
159
|
+
'in_canvas' => lambda{|value| !blank?(value)},
|
160
|
+
'added' => lambda{|value| !blank?(value)},
|
161
|
+
'expires' => lambda{|value| blank?(value) ? nil : Time.at(value.to_f)},
|
162
|
+
'friends' => lambda{|value| value.split(/,/)}
|
163
|
+
)
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Overwrite of the redirect method, if it is to a canvas, then use an fbml_redirect_tag
|
168
|
+
#
|
169
|
+
def redirect(*args)
|
170
|
+
if request_is_for_a_facebook_canvas?
|
171
|
+
fbml_redirect_tag(*args)
|
172
|
+
else
|
173
|
+
super
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def fbml_redirect_tag(url)
|
178
|
+
puts url
|
179
|
+
"<fb:redirect url=\"#{url}\" />"
|
180
|
+
end
|
181
|
+
|
182
|
+
def request_is_for_a_facebook_canvas?
|
183
|
+
!params['fb_sig_in_canvas'].blank?
|
184
|
+
end
|
185
|
+
|
186
|
+
def using_facebook_connect?
|
187
|
+
!cookies[Facebooker::Session.api_key].blank?
|
188
|
+
end
|
189
|
+
|
190
|
+
def application_is_installed?
|
191
|
+
facebook_params['added']
|
192
|
+
end
|
193
|
+
|
194
|
+
def ensure_authenticated_to_facebook
|
195
|
+
set_facebook_session || create_new_facebook_session_and_redirect!
|
196
|
+
end
|
197
|
+
|
198
|
+
def ensure_application_is_installed_by_facebook_user
|
199
|
+
@installation_required = true
|
200
|
+
authenticated_and_installed = ensure_authenticated_to_facebook && application_is_installed?
|
201
|
+
application_is_not_installed_by_facebook_user unless authenticated_and_installed
|
202
|
+
authenticated_and_installed
|
203
|
+
end
|
204
|
+
|
205
|
+
def application_is_not_installed_by_facebook_user
|
206
|
+
throw :halt, redirect(session[:facebook_session].install_url)
|
207
|
+
end
|
208
|
+
|
209
|
+
def set_fbml_format
|
210
|
+
params[:format] = "fbml" if request_is_for_a_facebook_canvas?
|
211
|
+
end
|
212
|
+
|
213
|
+
module ClassMethods
|
214
|
+
#
|
215
|
+
# Creates a filter which reqires a user to have already authenticated to
|
216
|
+
# Facebook before executing actions. Accepts the same optional options hash which
|
217
|
+
# before_filter and after_filter accept.
|
218
|
+
def ensure_authenticated_to_facebook(options = {})
|
219
|
+
before :ensure_authenticated_to_facebook, options
|
220
|
+
end
|
221
|
+
|
222
|
+
def ensure_application_is_installed_by_facebook_user(options = {})
|
223
|
+
before :ensure_application_is_installed_by_facebook_user, options
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Facebooker
|
2
|
+
module Merb
|
3
|
+
module Helpers
|
4
|
+
#const
|
5
|
+
VALID_FB_SHARED_PHOTO_SIZES = [:thumb, :small, :normal, :square]
|
6
|
+
VALID_FB_PHOTO_SIZES = VALID_FB_SHARED_PHOTO_SIZES
|
7
|
+
VALID_FB_PROFILE_PIC_SIZES = VALID_FB_SHARED_PHOTO_SIZES
|
8
|
+
|
9
|
+
VALID_FB_SHARED_ALIGN_VALUES = [:left, :right]
|
10
|
+
VALID_FB_PHOTO_ALIGN_VALUES = VALID_FB_SHARED_ALIGN_VALUES
|
11
|
+
VALID_FB_TAB_ITEM_ALIGN_VALUES = VALID_FB_SHARED_ALIGN_VALUES
|
12
|
+
|
13
|
+
FB_PHOTO_VALID_OPTION_KEYS = [:uid, :size, :align]
|
14
|
+
|
15
|
+
# Create an fb:request-form without a selector
|
16
|
+
#
|
17
|
+
# The block passed to this tag is used as the content of the form
|
18
|
+
#
|
19
|
+
# The message param is the name sent to content_for that specifies the body of the message
|
20
|
+
#
|
21
|
+
# For example,
|
22
|
+
#
|
23
|
+
# <% content_for("invite_message") do %>
|
24
|
+
# This gets sent in the invite. <%= fb_req_choice("with a button!",new_poke_path) %>
|
25
|
+
# <% end %>
|
26
|
+
# <% fb_request_form("Poke","invite_message",create_poke_path) do %>
|
27
|
+
# Send a poke to: <%= fb_friend_selector %> <br />
|
28
|
+
# <%= fb_request_form_submit %>
|
29
|
+
# <% end %>
|
30
|
+
|
31
|
+
def fb_request_form(type ,message_param,url,&block)
|
32
|
+
content = capture(&block)
|
33
|
+
message = @_caught_content[message_param]
|
34
|
+
concat(tag("fb:request-form", content,
|
35
|
+
{:action=>url,:method=>"post",:invite=>true,:type=>type,:content=>message}),
|
36
|
+
block.binding)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Provides a FBML fb_profile_pic tag with the provided uid
|
41
|
+
# ==== Parameters
|
42
|
+
# user<OrmObject>:: The user object
|
43
|
+
# options<Hash>:: specify the users picture size
|
44
|
+
#
|
45
|
+
# === Options (options)
|
46
|
+
# :size<Symbol>:: The size of the profile picture :small, :normal and :square
|
47
|
+
#
|
48
|
+
# ==== Returns
|
49
|
+
# String:: The fbml tag defaulting with thumb picture
|
50
|
+
#
|
51
|
+
# ==== Example
|
52
|
+
# <%= fb_profile_pic(@user) %>
|
53
|
+
def fb_profile_pic(user, options = {})
|
54
|
+
validate_fb_profile_pic_size(options)
|
55
|
+
options.merge!(:uid => cast_to_facebook_id(user))
|
56
|
+
self_closing_tag("fb:profile-pic", options)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# Provides a FBML fb_photo tag with the a facebook photo
|
62
|
+
# ==== Parameters
|
63
|
+
# photo<Facebooker::Photo>:: The photo object Or Objec that respond to photo_id
|
64
|
+
# options<Hash>:: specify the pic size and
|
65
|
+
#
|
66
|
+
# === Options (options)
|
67
|
+
# <em> See: </em> http://wiki.developers.facebook.com/index.php/Fb:photo for complete list of options
|
68
|
+
#
|
69
|
+
# ==== Returns
|
70
|
+
# String:: The fbml photo tag defaulting with thumb picture
|
71
|
+
#
|
72
|
+
# ==== Example
|
73
|
+
# <%= fb_profile_pic(@user) %>
|
74
|
+
def fb_photo(photo, options = {})
|
75
|
+
# options.assert_valid_keys(FB_PHOTO_VALID_OPTION_KEYS) # TODO asserts
|
76
|
+
options.merge!(:pid => cast_to_photo_id(photo))
|
77
|
+
validate_fb_photo_size(options)
|
78
|
+
validate_fb_photo_align_value(options)
|
79
|
+
self_closing_tag("fb:photo", options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def cast_to_photo_id(object)
|
83
|
+
object.respond_to?(:photo_id) ? object.photo_id : object
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
def validate_fb_photo_align_value(options)
|
88
|
+
if options.has_key?(:align) && !VALID_FB_PHOTO_ALIGN_VALUES.include?(options[:align].to_sym)
|
89
|
+
raise(ArgumentError, "Unkown value for align: #{options[:align]}")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def cast_to_facebook_id(object)
|
94
|
+
Facebooker::User.cast_to_facebook_id(object)
|
95
|
+
end
|
96
|
+
|
97
|
+
def validate_fb_photo_size(options)
|
98
|
+
if options.has_key?(:size) && !VALID_FB_PHOTO_SIZES.include?(options[:size].to_sym)
|
99
|
+
raise(ArgumentError, "Unkown value for size: #{options[:size]}")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def validate_fb_profile_pic_size(options)
|
104
|
+
if options.has_key?(:size) && !VALID_FB_PROFILE_PIC_SIZES.include?(options[:size].to_sym)
|
105
|
+
raise(ArgumentError, "Unkown value for size: #{options[:size]}")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end # Helpers
|
110
|
+
end # Merb
|
111
|
+
end # Facebooker
|
@@ -0,0 +1,50 @@
|
|
1
|
+
namespace :facebooker do
|
2
|
+
|
3
|
+
desc "Create a basic facebooker.yml configuration file"
|
4
|
+
task :setup do
|
5
|
+
facebook_config = File.join(Merb.root,"config","facebooker.yml")
|
6
|
+
unless File.exist?(facebook_config)
|
7
|
+
cp File.dirname(__FILE__) + '/../../templates/config/facebooker.yml', facebook_config
|
8
|
+
puts "Configuration created in #{Merb.root}/config/facebooker.yml"
|
9
|
+
else
|
10
|
+
puts "#{Merb.root}/config/facebooker.yml already exists"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :tunnel do
|
15
|
+
# Courtesy of Christopher Haupt
|
16
|
+
# http://www.BuildingWebApps.com
|
17
|
+
# http://www.LearningRails.com
|
18
|
+
desc "Create a reverse ssh tunnel from a public server to a private development server."
|
19
|
+
task :start => [ :config ] do
|
20
|
+
puts "Starting tunnel #{@public_host}:#{@public_port} to 0.0.0.0:#{@local_port}"
|
21
|
+
exec "ssh -nNT -g -R *:#{@public_port}:0.0.0.0:#{@local_port} #{@public_host_username}@#{@public_host}"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Create a reverse ssh tunnel in the background. Requires ssh keys to be setup."
|
25
|
+
task :background_start => [ :config ] do
|
26
|
+
puts "Starting tunnel #{@public_host}:#{@public_port} to 0.0.0.0:#{@local_port}"
|
27
|
+
exec "ssh -nNT -g -R *:#{@public_port}:0.0.0.0:#{@local_port} #{@public_host_username}@#{@public_host} > /dev/null 2>&1 &"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Adapted from Evan Weaver: http://blog.evanweaver.com/articles/2007/07/13/developing-a-facebook-app-locally/
|
31
|
+
desc "Check if reverse tunnel is running"
|
32
|
+
task :status => [ :config ] do
|
33
|
+
if `ssh #{@public_host} -l #{@public_host_username} netstat -an |
|
34
|
+
egrep "tcp.*:#{@public_port}.*LISTEN" | wc`.to_i > 0
|
35
|
+
puts "Seems ok"
|
36
|
+
else
|
37
|
+
puts "Down"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :config do
|
42
|
+
facebook_config = File.join(Merb.root,"config","facebooker.yml")
|
43
|
+
FACEBOOKER = YAML.load_file(facebook_config)[Merb.environment]
|
44
|
+
@public_host_username = FACEBOOKER['tunnel']['public_host_username']
|
45
|
+
@public_host = FACEBOOKER['tunnel']['public_host']
|
46
|
+
@public_port = FACEBOOKER['tunnel']['public_port']
|
47
|
+
@local_port = FACEBOOKER['tunnel']['local_port']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# make sure we're running inside Merb
|
2
|
+
require 'facebooker'
|
3
|
+
require 'yaml'
|
4
|
+
require 'merb_facebooker/controller'
|
5
|
+
require 'merb_facebooker/helpers'
|
6
|
+
|
7
|
+
if defined?(Merb::Plugins)
|
8
|
+
|
9
|
+
# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
|
10
|
+
facebook_config = "#{Merb.root}/config/facebooker.yml"
|
11
|
+
if File.exist?(facebook_config)
|
12
|
+
Merb::Plugins.config[:merb_facebooker] = YAML.load_file(facebook_config)[Merb.environment]
|
13
|
+
ENV['FACEBOOK_API_KEY'] = Merb::Plugins.config[:merb_facebooker]['api_key']
|
14
|
+
ENV['FACEBOOK_SECRET_KEY'] = Merb::Plugins.config[:merb_facebooker]['secret_key']
|
15
|
+
ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = Merb::Plugins.config[:merb_facebooker]['canvas_page_name']
|
16
|
+
#ActionController::Base.asset_host = FACEBOOKER['callback_url']
|
17
|
+
end
|
18
|
+
|
19
|
+
Merb.add_mime_type(:fbml, :to_fbml, %w[application/fbml text/fbml], :encoding => "UTF-8")
|
20
|
+
Merb::Request.http_method_overrides.push(
|
21
|
+
proc { |c| c.params[:fb_sig_request_method].clone if c.params[:fb_sig_request_method]}
|
22
|
+
)
|
23
|
+
|
24
|
+
Merb::BootLoader.before_app_loads do
|
25
|
+
Merb::Controller.send(:include, Facebooker::Merb::Controller)
|
26
|
+
Merb::Controller.send(:include, Facebooker::Merb::Helpers)
|
27
|
+
# require code that must be loaded before the application
|
28
|
+
end
|
29
|
+
|
30
|
+
Merb::BootLoader.after_app_loads do
|
31
|
+
# code that can be required after the application loads
|
32
|
+
end
|
33
|
+
|
34
|
+
Merb::Plugins.add_rakefiles "merb_facebooker/merbtasks"
|
35
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
Merb::Config.use { |c|
|
4
|
+
c[:framework] = {},
|
5
|
+
c[:session_store] = 'none',
|
6
|
+
c[:exception_details] = true
|
7
|
+
}
|
8
|
+
|
9
|
+
# ok lets start with the helpers and go from there
|
10
|
+
describe "Controller With Facebooker Helpers" do
|
11
|
+
before(:all) do
|
12
|
+
@controller = FacebookerHelpers.new(fake_request)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "calling fb_profile(@user, options) given user has facebook_id=1234" do
|
16
|
+
before(:all) do
|
17
|
+
@user = stub("User", :facebook_id => 1234)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to call" do
|
21
|
+
@controller.should respond_to(:fb_profile_pic)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should equal <fb:profile-pic uid='1234' /> when calling with @user" do
|
25
|
+
@controller.fb_profile_pic(@user).should == "<fb:profile-pic uid=\"1234\"/>"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should equal <fb:profile-pic uid='1234' size='small'/> when calling with @user, :size => :small" do
|
29
|
+
@controller.fb_profile_pic(@user, :size => :small).should == "<fb:profile-pic uid=\"1234\" size=\"small\"/>"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should raise Argument Error is the incorrect size is given when calling @user, :size => :egg" do
|
33
|
+
lambda{@controller.fb_profile_pic(@user, :size => :egg)}.should raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
describe "calling fb_photo where given photo has an photo_id = 1234" do
|
39
|
+
before(:all) do
|
40
|
+
@photo = stub("Photo", :photo_id => 1234)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be able to call" do
|
44
|
+
@controller.should respond_to(:fb_photo)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should equal <fb:photo pid=\"1234\" /> with parameter @photo" do
|
48
|
+
@photo.stub!(:photo_id).and_return(1234) # DONT ASK
|
49
|
+
@controller.fb_photo(@photo).should == "<fb:photo pid=\"1234\"/>"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$TESTING=true
|
2
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
|
4
|
+
# going to be specing for Merb so lets just do that shall we
|
5
|
+
require 'rubygems'
|
6
|
+
require 'merb-core'
|
7
|
+
require 'merb_facebooker'
|
8
|
+
require 'spec'
|
9
|
+
|
10
|
+
Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
config.include(Merb::Test::ViewHelper)
|
14
|
+
config.include(Merb::Test::RouteHelper)
|
15
|
+
config.include(Merb::Test::ControllerHelper)
|
16
|
+
end
|
17
|
+
|
18
|
+
Merb::Router.prepare do
|
19
|
+
match('/').to(:controller => 'facebook_helpers', :action =>'index')
|
20
|
+
end
|
21
|
+
|
22
|
+
class FacebookerHelpers < Merb::Controller
|
23
|
+
def index
|
24
|
+
"hi"
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb_facebooker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Chris Van Pelt
|
13
|
+
- Pavel Kunc
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-04-04 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: merb-helpers
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: 1.1.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: facebooker
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 50
|
46
|
+
version: 1.0.50
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Merb plugin that makes facebooker work with merb...
|
50
|
+
email: vanpelt@doloreslabs.com, pavel.kunc@gmail.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README
|
57
|
+
- LICENSE
|
58
|
+
- TODO
|
59
|
+
files:
|
60
|
+
- Rakefile
|
61
|
+
- lib/merb_facebooker/controller.rb
|
62
|
+
- lib/merb_facebooker/helpers.rb
|
63
|
+
- lib/merb_facebooker/merbtasks.rb
|
64
|
+
- lib/merb_facebooker/version.rb
|
65
|
+
- lib/merb_facebooker.rb
|
66
|
+
- spec/merb_facebooker_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- README
|
69
|
+
- LICENSE
|
70
|
+
- TODO
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://merb-plugins.rubyforge.org/merb_facebooker/
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Merb plugin that makes facebooker work with merb...
|
101
|
+
test_files: []
|
102
|
+
|