mmangino-facebooker 1.0.16 → 1.0.19
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +6 -4
- data/README +1 -1
- data/README.txt +1 -0
- data/Rakefile +8 -1
- data/init.rb +12 -61
- data/lib/facebooker/admin.rb +2 -2
- data/lib/facebooker/mobile.rb +20 -0
- data/lib/facebooker/models/user.rb +3 -3
- data/lib/facebooker/parser.rb +15 -1
- data/lib/facebooker/rails/controller.rb +1 -2
- data/lib/facebooker/rails/cucumber.rb +5 -7
- data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
- data/lib/facebooker/rails/extensions/rack_setup.rb +2 -0
- data/lib/facebooker/rails/extensions/routing.rb +15 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +19 -11
- data/lib/facebooker/rails/facebook_url_rewriting.rb +12 -4
- data/lib/facebooker/rails/integration_session.rb +4 -6
- data/lib/facebooker/rails/publisher.rb +7 -3
- data/lib/facebooker/session.rb +5 -1
- data/lib/facebooker/version.rb +1 -1
- data/lib/facebooker.rb +3 -2
- data/lib/rack/facebook.rb +76 -0
- data/test/facebooker/mobile_test.rb +45 -0
- data/test/facebooker/models/user_test.rb +3 -3
- data/test/facebooker/rails/publisher_test.rb +16 -0
- data/test/facebooker/rails_integration_test.rb +215 -204
- data/test/rails_test_helper.rb +2 -0
- data/test/test_helper.rb +6 -0
- metadata +8 -6
data/Manifest.txt
CHANGED
@@ -49,6 +49,7 @@ lib/facebooker/batch_request.rb
|
|
49
49
|
lib/facebooker/data.rb
|
50
50
|
lib/facebooker/feed.rb
|
51
51
|
lib/facebooker/logging.rb
|
52
|
+
lib/facebooker/mobile.rb
|
52
53
|
lib/facebooker/mock/service.rb
|
53
54
|
lib/facebooker/mock/session.rb
|
54
55
|
lib/facebooker/model.rb
|
@@ -69,14 +70,15 @@ lib/facebooker/models/page.rb
|
|
69
70
|
lib/facebooker/models/photo.rb
|
70
71
|
lib/facebooker/models/tag.rb
|
71
72
|
lib/facebooker/models/user.rb
|
72
|
-
lib/facebooker/models/user.rb.orig
|
73
|
-
lib/facebooker/models/user.rb.rej
|
74
73
|
lib/facebooker/models/video.rb
|
75
74
|
lib/facebooker/models/work_info.rb
|
76
75
|
lib/facebooker/parser.rb
|
77
76
|
lib/facebooker/rails/controller.rb
|
78
77
|
lib/facebooker/rails/cucumber/world.rb
|
79
78
|
lib/facebooker/rails/cucumber.rb
|
79
|
+
lib/facebooker/rails/extensions/action_controller.rb
|
80
|
+
lib/facebooker/rails/extensions/rack_setup.rb
|
81
|
+
lib/facebooker/rails/extensions/routing.rb
|
80
82
|
lib/facebooker/rails/facebook_form_builder.rb
|
81
83
|
lib/facebooker/rails/facebook_pretty_errors.rb
|
82
84
|
lib/facebooker/rails/facebook_request_fix.rb
|
@@ -94,11 +96,10 @@ lib/facebooker/rails/utilities.rb
|
|
94
96
|
lib/facebooker/server_cache.rb
|
95
97
|
lib/facebooker/service.rb
|
96
98
|
lib/facebooker/session.rb
|
97
|
-
lib/facebooker/session.rb.orig
|
98
|
-
lib/facebooker/session.rb.rej
|
99
99
|
lib/facebooker/version.rb
|
100
100
|
lib/facebooker.rb
|
101
101
|
lib/net/http_multipart_post.rb
|
102
|
+
lib/rack/facebook.rb
|
102
103
|
lib/tasks/facebooker.rake
|
103
104
|
lib/tasks/tunnel.rake
|
104
105
|
rails/init.rb
|
@@ -123,3 +124,4 @@ test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt
|
|
123
124
|
test/net/http_multipart_post_test.rb
|
124
125
|
test/rails_test_helper.rb
|
125
126
|
test/test_helper.rb
|
127
|
+
test/facebooker/mobile_test.rb
|
data/README
CHANGED
@@ -42,5 +42,5 @@ I'm not saying it meets its goals fully yet. Please help. I'm especially inter
|
|
42
42
|
|
43
43
|
== Contribute
|
44
44
|
|
45
|
-
Please visit the {
|
45
|
+
Please visit the {GitHub page}[http://github.com/mmangino/facebooker/tree/] to get the latest source via svn, write some tests, add/fix features, and submit a patch via the tracker. If you submit a good patch, it's likely that I'll add you to the project for commit access if you want to be added.
|
46
46
|
|
data/README.txt
CHANGED
@@ -22,6 +22,7 @@ Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[h
|
|
22
22
|
== SYNOPSIS:
|
23
23
|
|
24
24
|
View David Clements' {excellent tutorial}[http://apps.facebook.com/facebooker_tutorial] at {http://apps.facebook.com/facebooker_tutorial/}[http://apps.facebook.com/facebooker_tutorial] or check out {Developing Facebook Platform Applications with Rails}[http://www.pragprog.com/titles/mmfacer].
|
25
|
+
{Join the Mailing List}:[groups.google.com/group/facebooker]
|
25
26
|
|
26
27
|
== REQUIREMENTS:
|
27
28
|
|
data/Rakefile
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
ENV['RUBY_FLAGS']="-I#{%w(lib ext bin test).join(File::PATH_SEPARATOR)}"
|
5
5
|
require 'hoe'
|
6
|
+
begin
|
7
|
+
require 'load_multi_rails_rake_tasks'
|
8
|
+
rescue LoadError
|
9
|
+
$stderr.puts "Install the multi_rails gem to run tests against multiple versions of Rails"
|
10
|
+
end
|
11
|
+
|
6
12
|
$: << File.dirname(__FILE__) + '/lib'
|
7
13
|
require './lib/facebooker.rb'
|
8
14
|
|
@@ -29,9 +35,10 @@ namespace :test do
|
|
29
35
|
desc 'Aggregate code coverage for unit, functional and integration tests'
|
30
36
|
Rcov::RcovTask.new(:coverage) do |t|
|
31
37
|
t.libs << "test"
|
32
|
-
t.test_files = FileList["test
|
38
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
33
39
|
t.output_dir = "coverage/"
|
34
40
|
t.verbose = true
|
41
|
+
t.rcov_opts = ['--exclude', 'test,/usr/lib/ruby,/Library/Ruby,/System/Library', '--sort', 'coverage']
|
35
42
|
end
|
36
43
|
end
|
37
44
|
|
data/init.rb
CHANGED
@@ -9,64 +9,15 @@ FACEBOOKER = Facebooker.load_configuration(facebook_config)
|
|
9
9
|
Facebooker.logger = RAILS_DEFAULT_LOGGER if Object.const_defined? :RAILS_DEFAULT_LOGGER
|
10
10
|
|
11
11
|
require 'net/http_multipart_post'
|
12
|
-
|
13
|
-
require 'facebooker/rails/
|
14
|
-
require 'facebooker/rails/
|
15
|
-
require 'facebooker/rails/
|
16
|
-
require 'facebooker/rails/
|
17
|
-
require 'facebooker/rails/
|
18
|
-
require 'facebooker/rails/
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
subclass.send(:include,Facebooker::Rails::Controller)
|
25
|
-
subclass.helper Facebooker::Rails::Helpers
|
26
|
-
end
|
27
|
-
end
|
28
|
-
class << self
|
29
|
-
alias_method_chain :inherited, :facebooker
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class ActionController::Routing::Route
|
35
|
-
def recognition_conditions_with_facebooker
|
36
|
-
defaults = recognition_conditions_without_facebooker
|
37
|
-
defaults << " env[:canvas] == conditions[:canvas] " if conditions[:canvas]
|
38
|
-
defaults
|
39
|
-
end
|
40
|
-
alias_method_chain :recognition_conditions, :facebooker
|
41
|
-
end
|
42
|
-
|
43
|
-
# When making get requests, Facebook sends fb_sig parameters both in the query string
|
44
|
-
# and also in the post body. We want to ignore the query string ones because they are one
|
45
|
-
# request out of date
|
46
|
-
# We only do thise when there are POST parameters so that IFrame linkage still works
|
47
|
-
class ActionController::AbstractRequest
|
48
|
-
def query_parameters_with_facebooker
|
49
|
-
if request_parameters.blank?
|
50
|
-
query_parameters_without_facebooker
|
51
|
-
else
|
52
|
-
(query_parameters_without_facebooker||{}).reject {|key,value| key.to_s =~ /^fb_sig/}
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
alias_method_chain :query_parameters, :facebooker
|
57
|
-
end
|
58
|
-
|
59
|
-
# We turn off route optimization to make named routes use our code for figuring out if they should go to the session
|
60
|
-
# If this fails, it means we're on rails 1.2, we can ignore it
|
61
|
-
begin
|
62
|
-
ActionController::Base::optimise_named_routes = false
|
63
|
-
rescue NoMethodError=>e
|
64
|
-
nil
|
65
|
-
end
|
66
|
-
|
67
|
-
# pull :canvas=> into env in routing to allow for conditions
|
68
|
-
ActionController::Routing::RouteSet.send :include, Facebooker::Rails::Routing::RouteSetExtensions
|
69
|
-
ActionController::Routing::RouteSet::Mapper.send :include, Facebooker::Rails::Routing::MapperExtensions
|
70
|
-
|
71
|
-
Mime::Type.register_alias "text/html", :fbml
|
72
|
-
Mime::Type.register_alias "text/javascript", :fbjs
|
12
|
+
if defined? Rails
|
13
|
+
require 'facebooker/rails/controller'
|
14
|
+
require 'facebooker/rails/facebook_url_rewriting'
|
15
|
+
require 'facebooker/rails/facebook_session_handling' if Rails.version < '2.3'
|
16
|
+
require 'facebooker/rails/facebook_request_fix' if Rails.version < '2.3'
|
17
|
+
require 'facebooker/rails/routing'
|
18
|
+
require 'facebooker/rails/facebook_pretty_errors' rescue nil
|
19
|
+
require 'facebooker/rails/facebook_url_helper'
|
20
|
+
require 'facebooker/rails/extensions/rack_setup' if Rails.version > '2.3'
|
21
|
+
require 'facebooker/rails/extensions/action_controller'
|
22
|
+
require 'facebooker/rails/extensions/routing'
|
23
|
+
end
|
data/lib/facebooker/admin.rb
CHANGED
@@ -15,7 +15,7 @@ module Facebooker
|
|
15
15
|
# +properties+: Hash of properties you want to view.
|
16
16
|
def get_app_properties(*properties)
|
17
17
|
json = @session.post('facebook.admin.getAppProperties', :properties => properties.to_json)
|
18
|
-
hash =
|
18
|
+
hash = Facebooker.json_decode(CGI.unescapeHTML(json))
|
19
19
|
@properties = ApplicationProperties.from_hash(hash)
|
20
20
|
end
|
21
21
|
|
@@ -29,7 +29,7 @@ module Facebooker
|
|
29
29
|
# ** BETA ***
|
30
30
|
def get_restriction_info(*restrictions)
|
31
31
|
json = @session.post('facebook.admin.getRestrictionInfo')
|
32
|
-
hash =
|
32
|
+
hash = Facebooker.json_decode(CGI.unescapeHTML(json))
|
33
33
|
@restrictions = ApplicationRestrictions.from_hash(hash)
|
34
34
|
end
|
35
35
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Facebooker
|
2
|
+
class Mobile
|
3
|
+
def initialize(session)
|
4
|
+
@session = session
|
5
|
+
end
|
6
|
+
|
7
|
+
# Used to determine whether the user identified by "uid" has enabled SMS for this application.
|
8
|
+
def can_send(user)
|
9
|
+
@session.post('facebook.sms.canSend', :uid => User.cast_to_facebook_id(user))
|
10
|
+
end
|
11
|
+
|
12
|
+
# Send the given message to the user.
|
13
|
+
# See http://wiki.developers.facebook.com/index.php/Mobile
|
14
|
+
def send(user, message)
|
15
|
+
@session.post('facebook.sms.send',
|
16
|
+
{:uid => User.cast_to_facebook_id(user),
|
17
|
+
:message => message}, false)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -245,17 +245,17 @@ module Facebooker
|
|
245
245
|
#
|
246
246
|
# This does not set profile actions, that should be done with profile_action=
|
247
247
|
def profile_fbml=(markup)
|
248
|
-
set_profile_fbml(markup, nil, nil)
|
248
|
+
set_profile_fbml(markup, nil, nil, nil)
|
249
249
|
end
|
250
250
|
|
251
251
|
##
|
252
252
|
# Set the mobile profile FBML
|
253
253
|
def mobile_fbml=(markup)
|
254
|
-
set_profile_fbml(nil, markup, nil)
|
254
|
+
set_profile_fbml(nil, markup, nil,nil)
|
255
255
|
end
|
256
256
|
|
257
257
|
def profile_action=(markup)
|
258
|
-
set_profile_fbml(nil, nil, markup)
|
258
|
+
set_profile_fbml(nil, nil, markup,nil)
|
259
259
|
end
|
260
260
|
|
261
261
|
def profile_main=(markup)
|
data/lib/facebooker/parser.rb
CHANGED
@@ -462,6 +462,18 @@ module Facebooker
|
|
462
462
|
end
|
463
463
|
end
|
464
464
|
|
465
|
+
class SmsSend < Parser#:nodoc:
|
466
|
+
def self.process(data)
|
467
|
+
element('sms_send_response', data).text_value == '0'
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
class SmsCanSend < Parser#:nodoc:
|
472
|
+
def self.process(data)
|
473
|
+
element('sms_canSend_response', data).text_value
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
465
477
|
class Errors < Parser#:nodoc:
|
466
478
|
EXCEPTIONS = {
|
467
479
|
1 => Facebooker::Session::UnknownError,
|
@@ -569,7 +581,9 @@ module Facebooker
|
|
569
581
|
'facebook.notifications.sendEmail' => NotificationsSendEmail,
|
570
582
|
'facebook.data.getUserPreference' => GetPreference,
|
571
583
|
'facebook.data.setUserPreference' => SetPreference,
|
572
|
-
'facebook.video.upload' => UploadVideo
|
584
|
+
'facebook.video.upload' => UploadVideo,
|
585
|
+
'facebook.sms.send' => SmsSend,
|
586
|
+
'facebook.sms.canSend' => SmsCanSend
|
573
587
|
}
|
574
588
|
end
|
575
589
|
end
|
@@ -104,8 +104,7 @@ module Facebooker
|
|
104
104
|
|
105
105
|
#returning gracefully if the cookies aren't set or have expired
|
106
106
|
return unless parsed['session_key'] && parsed['user'] && parsed['expires'] && parsed['ss']
|
107
|
-
return unless Time.at(parsed['expires'].to_f) > Time.now || (parsed['expires'] == "0")
|
108
|
-
|
107
|
+
return unless Time.at(parsed['expires'].to_s.to_f) > Time.now || (parsed['expires'] == "0")
|
109
108
|
#if we have the unexpired cookies, we'll throw an exception if the sig doesn't verify
|
110
109
|
verify_signature(parsed,cookies[Facebooker.api_key])
|
111
110
|
|
@@ -4,13 +4,6 @@ require 'facebooker/mock/service'
|
|
4
4
|
|
5
5
|
Facebooker::MockService.fixture_path = File.join(RAILS_ROOT, 'features', 'support', 'facebook')
|
6
6
|
|
7
|
-
Facebooker::Session.current = Facebooker::MockSession.create
|
8
|
-
class ApplicationController
|
9
|
-
def facebook_session
|
10
|
-
Facebooker::Session.current
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
7
|
module Facebooker
|
15
8
|
class << self
|
16
9
|
# prevent Facebooker from adding canvas name as prefix to URLs
|
@@ -25,6 +18,11 @@ module Facebooker
|
|
25
18
|
def redirect_to(*args)
|
26
19
|
super
|
27
20
|
end
|
21
|
+
|
22
|
+
# Return the mock session
|
23
|
+
def new_facebook_session
|
24
|
+
Facebooker::MockSession.create
|
25
|
+
end
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ::ActionController
|
2
|
+
class Base
|
3
|
+
def self.inherited_with_facebooker(subclass)
|
4
|
+
inherited_without_facebooker(subclass)
|
5
|
+
if subclass.to_s == "ApplicationController"
|
6
|
+
subclass.send(:include,Facebooker::Rails::Controller)
|
7
|
+
subclass.helper Facebooker::Rails::Helpers
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class << self
|
11
|
+
alias_method_chain :inherited, :facebooker
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# When making get requests, Facebook sends fb_sig parameters both in the query string
|
18
|
+
# and also in the post body. We want to ignore the query string ones because they are one
|
19
|
+
# request out of date
|
20
|
+
# We only do thise when there are POST parameters so that IFrame linkage still works
|
21
|
+
if Rails.version < '2.3'
|
22
|
+
class ActionController::AbstractRequest
|
23
|
+
def query_parameters_with_facebooker
|
24
|
+
if request_parameters.blank?
|
25
|
+
query_parameters_without_facebooker
|
26
|
+
else
|
27
|
+
(query_parameters_without_facebooker||{}).reject {|key,value| key.to_s =~ /^fb_sig/}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method_chain :query_parameters, :facebooker
|
32
|
+
end
|
33
|
+
else
|
34
|
+
class ActionController::Request
|
35
|
+
def query_parameters_with_facebooker
|
36
|
+
if request_parameters.blank?
|
37
|
+
query_parameters_without_facebooker
|
38
|
+
else
|
39
|
+
(query_parameters_without_facebooker||{}).reject {|key,value| key.to_s =~ /^fb_sig/}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method_chain :query_parameters, :facebooker
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Mime::Type.register_alias "text/html", :fbml
|
48
|
+
Mime::Type.register_alias "text/javascript", :fbjs
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ActionController::Routing::Route
|
2
|
+
def recognition_conditions_with_facebooker
|
3
|
+
defaults = recognition_conditions_without_facebooker
|
4
|
+
defaults << " env[:canvas] == conditions[:canvas] " if conditions[:canvas]
|
5
|
+
defaults
|
6
|
+
end
|
7
|
+
alias_method_chain :recognition_conditions, :facebooker
|
8
|
+
end
|
9
|
+
|
10
|
+
# We turn off route optimization to make named routes use our code for figuring out if they should go to the session
|
11
|
+
ActionController::Base::optimise_named_routes = false
|
12
|
+
|
13
|
+
# pull :canvas=> into env in routing to allow for conditions
|
14
|
+
ActionController::Routing::RouteSet.send :include, Facebooker::Rails::Routing::RouteSetExtensions
|
15
|
+
ActionController::Routing::RouteSet::Mapper.send :include, Facebooker::Rails::Routing::MapperExtensions
|
@@ -1,14 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class ActionController::Base
|
2
|
+
def rescues_path_with_facebooker(template_name)
|
3
|
+
t = "#{RAILS_ROOT}/vendor/plugins/facebooker/templates/#{template_name}.erb"
|
4
|
+
if pretty_facebook_errors? && File.exist?(t)
|
5
|
+
t
|
6
|
+
else
|
7
|
+
rescues_path_without_facebooker(template_name)
|
6
8
|
end
|
9
|
+
end
|
10
|
+
alias_method_chain :rescues_path, :facebooker
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def response_code_for_rescue_with_facebooker(exception)
|
13
|
+
pretty_facebook_errors? ? 200 : response_code_for_rescue_without_facebooker(exception)
|
14
|
+
end
|
15
|
+
alias_method_chain :response_code_for_rescue, :facebooker
|
16
|
+
|
17
|
+
|
18
|
+
def pretty_facebook_errors?
|
19
|
+
Facebooker.facebooker_config['pretty_errors'] ||
|
20
|
+
(Facebooker.facebooker_config['pretty_errors'].nil? && RAILS_ENV=="development")
|
13
21
|
end
|
14
|
-
end
|
22
|
+
end
|
@@ -1,8 +1,16 @@
|
|
1
1
|
module ::ActionController
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
if Rails.version < '2.3'
|
3
|
+
class AbstractRequest
|
4
|
+
def relative_url_root
|
5
|
+
Facebooker.path_prefix
|
6
|
+
end
|
7
|
+
end
|
8
|
+
else
|
9
|
+
class Request
|
10
|
+
def relative_url_root
|
11
|
+
Facebooker.path_prefix
|
12
|
+
end
|
13
|
+
end
|
6
14
|
end
|
7
15
|
|
8
16
|
class Base
|
@@ -17,24 +17,22 @@ class Facebooker::Rails::IntegrationSession < ActionController::Integration::Ses
|
|
17
17
|
super
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def get(path, parameters = nil, headers = nil)
|
21
21
|
if canvas
|
22
22
|
post path, (parameters || {}).merge('fb_sig_request_method' => 'GET'), headers
|
23
23
|
else
|
24
|
-
|
24
|
+
super path, parameters, headers
|
25
25
|
end
|
26
26
|
end
|
27
|
-
alias_method_chain :get, :canvas
|
28
27
|
|
29
28
|
%w(put delete).each do |method|
|
30
|
-
define_method
|
29
|
+
define_method method do |*args|
|
31
30
|
if canvas
|
32
31
|
path, parameters, headers = *args
|
33
32
|
post path, (parameters || {}).merge('_method' => method.upcase), headers
|
34
33
|
else
|
35
|
-
|
34
|
+
super *args
|
36
35
|
end
|
37
36
|
end
|
38
|
-
alias_method_chain method, :canvas
|
39
37
|
end
|
40
38
|
end
|
@@ -224,6 +224,7 @@ module Facebooker
|
|
224
224
|
attr_accessor :template_id
|
225
225
|
attr_accessor :template_name
|
226
226
|
attr_accessor :story_size
|
227
|
+
|
227
228
|
def target_ids=(val)
|
228
229
|
@target_ids = val.is_a?(Array) ? val.join(",") : val
|
229
230
|
end
|
@@ -320,7 +321,7 @@ module Facebooker
|
|
320
321
|
self.href=href
|
321
322
|
end
|
322
323
|
|
323
|
-
def to_json
|
324
|
+
def to_json(*args)
|
324
325
|
"{\"src\":#{src.to_json}, \"href\":#{href.to_json}}"
|
325
326
|
end
|
326
327
|
end
|
@@ -404,7 +405,10 @@ module Facebooker
|
|
404
405
|
#only do this on Rails 2.1
|
405
406
|
if ActionController::Base.respond_to?(:append_view_path)
|
406
407
|
# only add the view path once
|
407
|
-
|
408
|
+
unless ActionController::Base.view_paths.include?(controller_root)
|
409
|
+
ActionController::Base.append_view_path(controller_root)
|
410
|
+
ActionController::Base.append_view_path(controller_root+"/..")
|
411
|
+
end
|
408
412
|
end
|
409
413
|
returning ActionView::Base.new([template_root,controller_root], assigns, self) do |template|
|
410
414
|
template.controller=self
|
@@ -471,7 +475,7 @@ module Facebooker
|
|
471
475
|
case publisher._body
|
472
476
|
when UserAction
|
473
477
|
publisher._body.template_name = method
|
474
|
-
publisher._body.template_id
|
478
|
+
publisher._body.template_id ||= FacebookTemplate.bundle_id_for_class_and_method(self,method)
|
475
479
|
end
|
476
480
|
|
477
481
|
should_send ? publisher.send_message(method) : publisher._body
|
data/lib/facebooker/session.rb
CHANGED
@@ -273,6 +273,10 @@ module Facebooker
|
|
273
273
|
Facebooker::Admin.new(self)
|
274
274
|
end
|
275
275
|
|
276
|
+
def mobile
|
277
|
+
Facebooker::Mobile.new(self)
|
278
|
+
end
|
279
|
+
|
276
280
|
#
|
277
281
|
# Given an array like:
|
278
282
|
# [[userid, otheruserid], [yetanotherid, andanotherid]]
|
@@ -512,7 +516,7 @@ module Facebooker
|
|
512
516
|
base = params.delete(:base)
|
513
517
|
Logging.log_fb_api(method, params) do
|
514
518
|
add_facebook_params(params, method)
|
515
|
-
@session_key && params[:session_key] ||= @session_key
|
519
|
+
@session_key && params[:session_key] ||= @session_key unless params[:uid]
|
516
520
|
service.post_file(params.merge(:base => base, :sig => signature_for(params.reject{|key, value| key.nil?})))
|
517
521
|
end
|
518
522
|
end
|
data/lib/facebooker/version.rb
CHANGED
data/lib/facebooker.rb
CHANGED
@@ -147,6 +147,7 @@ require 'facebooker/service'
|
|
147
147
|
require 'facebooker/server_cache'
|
148
148
|
require 'facebooker/data'
|
149
149
|
require 'facebooker/admin'
|
150
|
+
require 'facebooker/mobile'
|
150
151
|
require 'facebooker/session'
|
151
152
|
require 'facebooker/version'
|
152
153
|
require 'facebooker/models/location'
|
@@ -166,8 +167,8 @@ require 'facebooker/models/tag'
|
|
166
167
|
require 'facebooker/models/user'
|
167
168
|
require 'facebooker/models/info_item'
|
168
169
|
require 'facebooker/models/info_section'
|
170
|
+
require 'facebooker/models/friend_list'
|
171
|
+
require 'facebooker/models/video'
|
169
172
|
require 'facebooker/adapters/adapter_base'
|
170
173
|
require 'facebooker/adapters/facebook_adapter'
|
171
174
|
require 'facebooker/adapters/bebo_adapter'
|
172
|
-
require 'facebooker/models/friend_list'
|
173
|
-
require 'facebooker/models/video'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Rack
|
2
|
+
# This Rack middleware checks the signature of Facebook params, and
|
3
|
+
# converts them to Ruby objects when appropiate. Also, it converts
|
4
|
+
# the request method from the Facebook POST to the original HTTP
|
5
|
+
# method used by the client.
|
6
|
+
#
|
7
|
+
# If the signature is wrong, it returns a "400 Invalid Facebook Signature".
|
8
|
+
#
|
9
|
+
# Optionally, it can take a block that receives the Rack environment
|
10
|
+
# and returns a value that evaluates to true when we want the middleware to
|
11
|
+
# be executed for the specific request.
|
12
|
+
#
|
13
|
+
# == Usage
|
14
|
+
#
|
15
|
+
# In your config.ru:
|
16
|
+
#
|
17
|
+
# require 'rack/facebook'
|
18
|
+
# use Rack::Facebook, "my_facebook_secret_key"
|
19
|
+
#
|
20
|
+
# Using a block condition:
|
21
|
+
#
|
22
|
+
# use Rack::Facebook, "my_facebook_secret_key" do |env|
|
23
|
+
# env['REQUEST_URI'] =~ /^\/facebook_only/
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
class Facebook
|
27
|
+
def initialize(app, secret_key, &condition)
|
28
|
+
@app = app
|
29
|
+
@secret_key = secret_key
|
30
|
+
@condition = condition
|
31
|
+
end
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
if @condition.nil? || @condition.call(env)
|
35
|
+
request = Rack::Request.new(env)
|
36
|
+
fb_params = extract_fb_sig_params(request.POST)
|
37
|
+
unless fb_params.empty?
|
38
|
+
unless signature_is_valid?(fb_params, request.POST['fb_sig'])
|
39
|
+
return Rack::Response.new(["Invalid Facebook signature"], 400).finish
|
40
|
+
end
|
41
|
+
env['REQUEST_METHOD'] = fb_params["request_method"] if fb_params["request_method"]
|
42
|
+
convert_parameters!(request.POST)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@app.call(env)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def extract_fb_sig_params(params)
|
51
|
+
params.inject({}) do |collection, (param, value)|
|
52
|
+
collection[param.sub(/^fb_sig_/, '')] = value if param[0,7] == 'fb_sig_'
|
53
|
+
collection
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def signature_is_valid?(fb_params, actual_sig)
|
58
|
+
raw_string = fb_params.map{ |*args| args.join('=') }.sort.join
|
59
|
+
expected_signature = Digest::MD5.hexdigest([raw_string, @secret_key].join)
|
60
|
+
actual_sig == expected_signature
|
61
|
+
end
|
62
|
+
|
63
|
+
def convert_parameters!(params)
|
64
|
+
params.each do |key, value|
|
65
|
+
case key
|
66
|
+
when 'fb_sig_added', 'fb_sig_in_canvas', 'fb_sig_in_new_facebook', 'fb_sig_position_fix'
|
67
|
+
params[key] = value == "1"
|
68
|
+
when 'fb_sig_expires', 'fb_sig_profile_update_time', 'fb_sig_time'
|
69
|
+
params[key] = value == "0" ? nil : Time.at(value.to_f)
|
70
|
+
when 'fb_sig_friends'
|
71
|
+
params[key] = value.split(',')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::MobileTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@session = Facebooker::Session.create('apikey', 'secretkey')
|
6
|
+
@user = Facebooker::User.new(1234, @session)
|
7
|
+
Facebooker.use_curl=false
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_can_send
|
11
|
+
expect_http_posts_with_responses(example_can_send_xml)
|
12
|
+
assert(@session.mobile.can_send(@user))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_send
|
16
|
+
expect_http_posts_with_responses(example_send_xml)
|
17
|
+
assert(@session.mobile.send(@user, "Some sort of message"))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def example_can_send_xml
|
22
|
+
<<-XML
|
23
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
24
|
+
<sms_canSend_response
|
25
|
+
xmlns="http://api.facebook.com/1.0/"
|
26
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
27
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
28
|
+
0
|
29
|
+
</sms_canSend_response>
|
30
|
+
XML
|
31
|
+
end
|
32
|
+
|
33
|
+
def example_send_xml
|
34
|
+
<<-XML
|
35
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
36
|
+
<sms_send_response
|
37
|
+
xmlns="http://api.facebook.com/1.0/"
|
38
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
39
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
40
|
+
0
|
41
|
+
</sms_send_response>
|
42
|
+
XML
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -76,15 +76,15 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def test_can_set_mobile_fbml
|
79
|
-
@user.expects(:set_profile_fbml).with(nil,"test",nil)
|
79
|
+
@user.expects(:set_profile_fbml).with(nil,"test",nil,nil)
|
80
80
|
@user.mobile_fbml="test"
|
81
81
|
end
|
82
82
|
def test_can_set_profile_action
|
83
|
-
@user.expects(:set_profile_fbml).with(nil,nil,"test")
|
83
|
+
@user.expects(:set_profile_fbml).with(nil,nil,"test",nil)
|
84
84
|
@user.profile_action="test"
|
85
85
|
end
|
86
86
|
def test_can_set_profile_fbml
|
87
|
-
@user.expects(:set_profile_fbml).with("test",nil,nil)
|
87
|
+
@user.expects(:set_profile_fbml).with("test",nil,nil,nil)
|
88
88
|
@user.profile_fbml="test"
|
89
89
|
end
|
90
90
|
|
@@ -108,6 +108,13 @@ class TestPublisher < Facebooker::Rails::Publisher
|
|
108
108
|
from user
|
109
109
|
data :friend=>"Mike"
|
110
110
|
end
|
111
|
+
|
112
|
+
def user_action_with_template_id(user)
|
113
|
+
send_as :user_action
|
114
|
+
from user
|
115
|
+
data :friend=>"Mike"
|
116
|
+
template_id 4
|
117
|
+
end
|
111
118
|
def user_action_with_story_size(user)
|
112
119
|
send_as :user_action
|
113
120
|
from user
|
@@ -335,6 +342,15 @@ class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
|
|
335
342
|
ua = TestPublisher.create_user_action(@from_user)
|
336
343
|
assert_equal "user_action", ua.template_name
|
337
344
|
end
|
345
|
+
def test_create_user_action_with_template_id
|
346
|
+
@from_user = Facebooker::User.new
|
347
|
+
@session = Facebooker::Session.new("","")
|
348
|
+
@from_user.stubs(:session).returns(@session)
|
349
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
350
|
+
with(TestPublisher,'user_action').never
|
351
|
+
ua = TestPublisher.create_user_action_with_template_id(@from_user)
|
352
|
+
assert_equal 4,ua.template_id
|
353
|
+
end
|
338
354
|
|
339
355
|
def test_publisher_user_action
|
340
356
|
@from_user = Facebooker::User.new
|
@@ -1,220 +1,220 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../rails_test_helper')
|
2
|
-
begin
|
3
|
-
ActionController::Routing::Routes.draw do |map|
|
4
|
-
map.connect '', :controller=>"facebook",:conditions=>{:canvas=>true}
|
5
|
-
map.connect '', :controller=>"plain_old_rails"
|
6
|
-
map.resources :comments, :controller=>"plain_old_rails"
|
7
|
-
map.connect 'require_auth/:action', :controller => "controller_which_requires_facebook_authentication"
|
8
|
-
map.connect 'require_install/:action', :controller => "controller_which_requires_application_installation"
|
9
|
-
map.connect ':controller/:action/:id', :controller => "plain_old_rails"
|
10
|
-
end
|
11
|
-
|
12
|
-
module FBConnectTestHelpers
|
13
|
-
def setup_fb_connect_cookies(params=cookie_hash_for_auth)
|
14
|
-
params.each {|k,v| @request.cookies[ENV['FACEBOOK_API_KEY']+k] = CGI::Cookie.new(ENV['FACEBOOK_API_KEY']+k,v)}
|
15
|
-
end
|
16
|
-
|
17
|
-
def expired_cookie_hash_for_auth
|
18
|
-
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.ago.to_i}"}
|
19
|
-
end
|
20
2
|
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
ActionController::Routing::Routes.draw do |map|
|
4
|
+
map.connect '', :controller=>"facebook",:conditions=>{:canvas=>true}
|
5
|
+
map.connect '', :controller=>"plain_old_rails"
|
6
|
+
map.resources :comments, :controller=>"plain_old_rails"
|
7
|
+
map.connect 'require_auth/:action', :controller => "controller_which_requires_facebook_authentication"
|
8
|
+
map.connect 'require_install/:action', :controller => "controller_which_requires_application_installation"
|
9
|
+
map.connect ':controller/:action/:id', :controller => "plain_old_rails"
|
10
|
+
end
|
11
|
+
|
12
|
+
module FBConnectTestHelpers
|
13
|
+
def setup_fb_connect_cookies(params=cookie_hash_for_auth)
|
14
|
+
params.each {|k,v| @request.cookies[ENV['FACEBOOK_API_KEY']+k] = CGI::Cookie.new(ENV['FACEBOOK_API_KEY']+k,v)}
|
24
15
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
|
17
|
+
def expired_cookie_hash_for_auth
|
18
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.ago.to_i}"}
|
28
19
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
20
|
+
|
21
|
+
def cookie_hash_for_auth
|
22
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.from_now.to_i}"}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class NoisyController < ActionController::Base
|
26
|
+
include Facebooker::Rails::Controller
|
27
|
+
def rescue_action(e) raise e end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
class ControllerWhichRequiresExtendedPermissions< NoisyController
|
32
|
+
ensure_authenticated_to_facebook
|
33
|
+
before_filter :ensure_has_status_update
|
34
|
+
before_filter :ensure_has_photo_upload
|
35
|
+
before_filter :ensure_has_video_upload
|
36
|
+
before_filter :ensure_has_create_listing
|
37
|
+
def index
|
38
|
+
render :text => 'score!'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class FBConnectController < NoisyController
|
43
|
+
before_filter :create_facebook_session
|
44
|
+
def index
|
45
|
+
render :text => 'score!'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class ControllerWhichRequiresFacebookAuthentication < NoisyController
|
50
|
+
ensure_authenticated_to_facebook
|
51
|
+
def index
|
52
|
+
render :text => 'score!'
|
53
|
+
end
|
54
|
+
def link_test
|
55
|
+
options = {}
|
56
|
+
options[:canvas] = true if params[:canvas] == true
|
57
|
+
options[:canvas] = false if params[:canvas] == false
|
58
|
+
render :text=>url_for(options)
|
40
59
|
end
|
41
60
|
|
42
|
-
|
43
|
-
|
44
|
-
def index
|
45
|
-
render :text => 'score!'
|
46
|
-
end
|
61
|
+
def named_route_test
|
62
|
+
render :text=>comments_url()
|
47
63
|
end
|
48
64
|
|
49
|
-
|
50
|
-
|
51
|
-
def index
|
52
|
-
render :text => 'score!'
|
53
|
-
end
|
54
|
-
def link_test
|
55
|
-
options = {}
|
56
|
-
options[:canvas] = true if params[:canvas] == true
|
57
|
-
options[:canvas] = false if params[:canvas] == false
|
58
|
-
render :text=>url_for(options)
|
59
|
-
end
|
60
|
-
|
61
|
-
def named_route_test
|
62
|
-
render :text=>comments_url()
|
63
|
-
end
|
64
|
-
|
65
|
-
def image_test
|
66
|
-
render :inline=>"<%=image_tag 'image.png'%>"
|
67
|
-
end
|
68
|
-
|
69
|
-
def fb_params_test
|
70
|
-
render :text=>facebook_params['user']
|
71
|
-
end
|
72
|
-
|
73
|
-
def publisher_test
|
74
|
-
if wants_interface?
|
75
|
-
render :text=>"interface"
|
76
|
-
else
|
77
|
-
render :text=>"not interface"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def publisher_test_interface
|
82
|
-
render_publisher_interface("This is a test",false,true)
|
83
|
-
end
|
84
|
-
|
85
|
-
def publisher_test_response
|
86
|
-
ua=Facebooker::Rails::Publisher::UserAction.new
|
87
|
-
ua.data = {:params=>true}
|
88
|
-
ua.template_name = "template_name"
|
89
|
-
ua.template_id = 1234
|
90
|
-
render_publisher_response(ua)
|
91
|
-
end
|
92
|
-
|
93
|
-
def publisher_test_error
|
94
|
-
render_publisher_error("Title","Body")
|
95
|
-
end
|
96
|
-
|
65
|
+
def image_test
|
66
|
+
render :inline=>"<%=image_tag 'image.png'%>"
|
97
67
|
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
render :text => 'installed!'
|
102
|
-
end
|
68
|
+
|
69
|
+
def fb_params_test
|
70
|
+
render :text=>facebook_params['user']
|
103
71
|
end
|
104
|
-
|
105
|
-
|
72
|
+
|
73
|
+
def publisher_test
|
74
|
+
if wants_interface?
|
75
|
+
render :text=>"interface"
|
76
|
+
else
|
77
|
+
render :text=>"not interface"
|
106
78
|
end
|
107
79
|
end
|
108
80
|
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
def link_test
|
113
|
-
options = {}
|
114
|
-
options[:canvas] = true if params[:canvas] == true
|
115
|
-
options[:canvas] = false if params[:canvas] == false
|
116
|
-
render :text => url_for(options)
|
117
|
-
end
|
118
|
-
|
119
|
-
def named_route_test
|
120
|
-
render :text=>comments_url()
|
121
|
-
end
|
122
|
-
def canvas_false_test
|
123
|
-
render :text=>comments_url(:canvas=>false)
|
124
|
-
end
|
125
|
-
def canvas_true_test
|
126
|
-
render :text=>comments_url(:canvas=>true)
|
127
|
-
end
|
81
|
+
def publisher_test_interface
|
82
|
+
render_publisher_interface("This is a test",false,true)
|
128
83
|
end
|
129
84
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
85
|
+
def publisher_test_response
|
86
|
+
ua=Facebooker::Rails::Publisher::UserAction.new
|
87
|
+
ua.data = {:params=>true}
|
88
|
+
ua.template_name = "template_name"
|
89
|
+
ua.template_id = 1234
|
90
|
+
render_publisher_response(ua)
|
137
91
|
end
|
138
92
|
|
139
|
-
|
140
|
-
|
93
|
+
def publisher_test_error
|
94
|
+
render_publisher_error("Title","Body")
|
141
95
|
end
|
142
96
|
|
97
|
+
end
|
98
|
+
class ControllerWhichRequiresApplicationInstallation < NoisyController
|
99
|
+
ensure_application_is_installed_by_facebook_user
|
100
|
+
def index
|
101
|
+
render :text => 'installed!'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
class FacebookController < ActionController::Base
|
105
|
+
def index
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class PlainOldRailsController < ActionController::Base
|
110
|
+
def index
|
111
|
+
end
|
112
|
+
def link_test
|
113
|
+
options = {}
|
114
|
+
options[:canvas] = true if params[:canvas] == true
|
115
|
+
options[:canvas] = false if params[:canvas] == false
|
116
|
+
render :text => url_for(options)
|
117
|
+
end
|
143
118
|
|
144
|
-
|
145
|
-
|
146
|
-
|
119
|
+
def named_route_test
|
120
|
+
render :text=>comments_url()
|
121
|
+
end
|
122
|
+
def canvas_false_test
|
123
|
+
render :text=>comments_url(:canvas=>false)
|
124
|
+
end
|
125
|
+
def canvas_true_test
|
126
|
+
render :text=>comments_url(:canvas=>true)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class Test::Unit::TestCase
|
131
|
+
include Facebooker::Rails::TestHelpers
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
# you can't use asset_recognize, because it can't pass parameters in to the requests
|
136
|
+
class UrlRecognitionTests < Test::Unit::TestCase
|
137
|
+
def test_detects_in_canvas
|
138
|
+
if Rails.version < '2.3'
|
147
139
|
request = ActionController::TestRequest.new({"fb_sig_in_canvas"=>"1"}, {}, nil)
|
148
|
-
|
149
|
-
ActionController::
|
150
|
-
|
140
|
+
else
|
141
|
+
request = ActionController::TestRequest.new
|
142
|
+
request.query_parameters[:fb_sig_in_canvas] = "1"
|
151
143
|
end
|
152
|
-
|
153
|
-
|
144
|
+
request.path = "/"
|
145
|
+
ActionController::Routing::Routes.recognize(request)
|
146
|
+
assert_equal({"controller"=>"facebook","action"=>"index"},request.path_parameters)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_routes_when_not_in_canvas
|
150
|
+
if Rails.version < '2.3'
|
154
151
|
request = ActionController::TestRequest.new({}, {}, nil)
|
155
|
-
|
156
|
-
ActionController::
|
157
|
-
assert_equal({"controller"=>"plain_old_rails","action"=>"index"},request.path_parameters)
|
152
|
+
else
|
153
|
+
request = ActionController::TestRequest.new
|
158
154
|
end
|
155
|
+
request.path = "/"
|
156
|
+
ActionController::Routing::Routes.recognize(request)
|
157
|
+
assert_equal({"controller"=>"plain_old_rails","action"=>"index"},request.path_parameters)
|
159
158
|
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class RailsIntegrationTestForFBConnect < Test::Unit::TestCase
|
162
|
+
include FBConnectTestHelpers
|
160
163
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
@response = ActionController::TestResponse.new
|
171
|
-
@controller.stubs(:verify_signature).returns(true)
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_doesnt_set_cookie_but_facebook_session_is_available
|
176
|
-
setup_fb_connect_cookies
|
177
|
-
get :index
|
178
|
-
assert_not_nil @controller.facebook_session
|
179
|
-
assert_nil @response.cookies[:facebook_session]
|
180
|
-
|
181
|
-
end
|
164
|
+
def setup
|
165
|
+
ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
|
166
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
167
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
168
|
+
@controller = FBConnectController.new
|
169
|
+
@request = ActionController::TestRequest.new
|
170
|
+
@response = ActionController::TestResponse.new
|
171
|
+
@controller.stubs(:verify_signature).returns(true)
|
172
|
+
|
182
173
|
end
|
183
174
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
@controller = PlainOldRailsController.new
|
190
|
-
@request = ActionController::TestRequest.new
|
191
|
-
@response = ActionController::TestResponse.new
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_url_for_links_to_callback_if_canvas_is_false_and_in_canvas
|
195
|
-
get :link_test
|
196
|
-
assert_match /test.host/,@response.body
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_named_route_doesnt_include_canvas_path_when_not_in_canvas
|
200
|
-
get :named_route_test
|
201
|
-
assert_equal "http://test.host/comments",@response.body
|
202
|
-
end
|
203
|
-
def test_named_route_includes_canvas_path_when_in_canvas
|
204
|
-
get :named_route_test, facebook_params
|
205
|
-
assert_equal "http://apps.facebook.com/facebook_app_name/comments",@response.body
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_named_route_doesnt_include_canvas_path_when_in_canvas_with_canvas_equals_false
|
209
|
-
get :canvas_false_test, facebook_params
|
210
|
-
assert_equal "http://test.host/comments",@response.body
|
211
|
-
end
|
212
|
-
def test_named_route_does_include_canvas_path_when_not_in_canvas_with_canvas_equals_true
|
213
|
-
get :canvas_true_test
|
214
|
-
assert_equal "http://apps.facebook.com/facebook_app_name/comments",@response.body
|
215
|
-
end
|
175
|
+
def test_doesnt_set_cookie_but_facebook_session_is_available
|
176
|
+
setup_fb_connect_cookies
|
177
|
+
get :index
|
178
|
+
assert_not_nil @controller.facebook_session
|
179
|
+
assert_nil @response.cookies[:facebook_session]
|
216
180
|
|
217
181
|
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class RailsIntegrationTestForNonFacebookControllers < Test::Unit::TestCase
|
185
|
+
def setup
|
186
|
+
ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
|
187
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
188
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
189
|
+
@controller = PlainOldRailsController.new
|
190
|
+
@request = ActionController::TestRequest.new
|
191
|
+
@response = ActionController::TestResponse.new
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_url_for_links_to_callback_if_canvas_is_false_and_in_canvas
|
195
|
+
get :link_test
|
196
|
+
assert_match /test.host/,@response.body
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_named_route_doesnt_include_canvas_path_when_not_in_canvas
|
200
|
+
get :named_route_test
|
201
|
+
assert_equal "http://test.host/comments",@response.body
|
202
|
+
end
|
203
|
+
def test_named_route_includes_canvas_path_when_in_canvas
|
204
|
+
get :named_route_test, facebook_params
|
205
|
+
assert_equal "http://apps.facebook.com/facebook_app_name/comments",@response.body
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_named_route_doesnt_include_canvas_path_when_in_canvas_with_canvas_equals_false
|
209
|
+
get :canvas_false_test, facebook_params
|
210
|
+
assert_equal "http://test.host/comments",@response.body
|
211
|
+
end
|
212
|
+
def test_named_route_does_include_canvas_path_when_not_in_canvas_with_canvas_equals_true
|
213
|
+
get :canvas_true_test
|
214
|
+
assert_equal "http://apps.facebook.com/facebook_app_name/comments",@response.body
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
218
|
|
219
219
|
class RailsIntegrationTestForExtendedPermissions < Test::Unit::TestCase
|
220
220
|
def setup
|
@@ -478,17 +478,17 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
478
478
|
|
479
479
|
def test_publisher_test_error
|
480
480
|
get :publisher_test_error, facebook_params
|
481
|
-
assert_equal
|
481
|
+
assert_equal Facebooker.json_decode("{\"errorCode\": 1, \"errorTitle\": \"Title\", \"errorMessage\": \"Body\"}"), Facebooker.json_decode(@response.body)
|
482
482
|
end
|
483
483
|
|
484
484
|
def test_publisher_test_interface
|
485
485
|
get :publisher_test_interface, facebook_params
|
486
|
-
assert_equal
|
486
|
+
assert_equal Facebooker.json_decode("{\"method\": \"publisher_getInterface\", \"content\": {\"fbml\": \"This is a test\", \"publishEnabled\": false, \"commentEnabled\": true}}"), Facebooker.json_decode(@response.body)
|
487
487
|
end
|
488
488
|
|
489
489
|
def test_publisher_test_reponse
|
490
490
|
get :publisher_test_response, facebook_params
|
491
|
-
assert_equal
|
491
|
+
assert_equal Facebooker.json_decode("{\"method\": \"publisher_getFeedStory\", \"content\": {\"feed\": {\"template_data\": {\"params\": true}, \"template_id\": 1234}}}"), Facebooker.json_decode(@response.body)
|
492
492
|
|
493
493
|
end
|
494
494
|
|
@@ -1104,26 +1104,42 @@ class RailsFacebookFormbuilderTest < Test::Unit::TestCase
|
|
1104
1104
|
end
|
1105
1105
|
|
1106
1106
|
class RailsPrettyErrorsTest < Test::Unit::TestCase
|
1107
|
+
class ControllerWhichFails < ActionController::Base
|
1108
|
+
def pass
|
1109
|
+
render :text=>''
|
1110
|
+
end
|
1111
|
+
def fail
|
1112
|
+
raise "I'm failing"
|
1113
|
+
end
|
1114
|
+
end
|
1115
|
+
|
1107
1116
|
def setup
|
1108
|
-
ENV['FACEBOOK_API_KEY'] = '1234567'
|
1109
|
-
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
1110
1117
|
@controller = ControllerWhichFails.new
|
1111
1118
|
@request = ActionController::TestRequest.new
|
1112
1119
|
@response = ActionController::TestResponse.new
|
1113
|
-
@controller.stubs(:verify_signature).returns(true)
|
1114
1120
|
end
|
1115
1121
|
|
1116
|
-
def
|
1117
|
-
Facebooker.facebooker_config.stubs(:pretty_errors).returns(false)
|
1122
|
+
def test_pretty_errors_disabled_success
|
1123
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(false)
|
1118
1124
|
post :pass, facebook_params
|
1119
|
-
assert_response
|
1125
|
+
assert_response 200
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
def test_pretty_errors_disabled_error
|
1129
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(false)
|
1120
1130
|
post :fail, facebook_params
|
1121
1131
|
assert_response :error
|
1122
|
-
|
1132
|
+
end
|
1133
|
+
|
1134
|
+
def test_pretty_errors_enabled_success
|
1135
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(true)
|
1123
1136
|
post :pass, facebook_params
|
1124
|
-
assert_response
|
1137
|
+
assert_response 200
|
1138
|
+
end
|
1139
|
+
def test_pretty_errors_enabled_error
|
1140
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(true)
|
1125
1141
|
post :fail, facebook_params
|
1126
|
-
assert_response
|
1142
|
+
assert_response 200
|
1127
1143
|
end
|
1128
1144
|
end
|
1129
1145
|
|
@@ -1303,8 +1319,3 @@ class RailsRequestFormatTest < Test::Unit::TestCase
|
|
1303
1319
|
end
|
1304
1320
|
|
1305
1321
|
end
|
1306
|
-
|
1307
|
-
# rescue LoadError
|
1308
|
-
# $stderr.puts "Couldn't find action controller. That's OK. We'll skip it."
|
1309
|
-
end
|
1310
|
-
|
data/test/rails_test_helper.rb
CHANGED
@@ -3,6 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
|
3
3
|
require 'action_controller'
|
4
4
|
require 'action_controller/test_process'
|
5
5
|
require 'active_record'
|
6
|
+
gem 'rails'
|
7
|
+
require 'initializer'
|
6
8
|
require File.dirname(__FILE__)+'/../init'
|
7
9
|
require 'facebooker/rails/controller'
|
8
10
|
require 'facebooker/rails/helpers/fb_connect'
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mmangino-facebooker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Fowler
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date:
|
15
|
+
date: 2009-03-26 00:00:00 -07:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/facebooker/data.rb
|
93
93
|
- lib/facebooker/feed.rb
|
94
94
|
- lib/facebooker/logging.rb
|
95
|
+
- lib/facebooker/mobile.rb
|
95
96
|
- lib/facebooker/mock/service.rb
|
96
97
|
- lib/facebooker/mock/session.rb
|
97
98
|
- lib/facebooker/model.rb
|
@@ -112,14 +113,15 @@ files:
|
|
112
113
|
- lib/facebooker/models/photo.rb
|
113
114
|
- lib/facebooker/models/tag.rb
|
114
115
|
- lib/facebooker/models/user.rb
|
115
|
-
- lib/facebooker/models/user.rb.orig
|
116
|
-
- lib/facebooker/models/user.rb.rej
|
117
116
|
- lib/facebooker/models/video.rb
|
118
117
|
- lib/facebooker/models/work_info.rb
|
119
118
|
- lib/facebooker/parser.rb
|
120
119
|
- lib/facebooker/rails/controller.rb
|
121
120
|
- lib/facebooker/rails/cucumber/world.rb
|
122
121
|
- lib/facebooker/rails/cucumber.rb
|
122
|
+
- lib/facebooker/rails/extensions/action_controller.rb
|
123
|
+
- lib/facebooker/rails/extensions/rack_setup.rb
|
124
|
+
- lib/facebooker/rails/extensions/routing.rb
|
123
125
|
- lib/facebooker/rails/facebook_form_builder.rb
|
124
126
|
- lib/facebooker/rails/facebook_pretty_errors.rb
|
125
127
|
- lib/facebooker/rails/facebook_request_fix.rb
|
@@ -137,11 +139,10 @@ files:
|
|
137
139
|
- lib/facebooker/server_cache.rb
|
138
140
|
- lib/facebooker/service.rb
|
139
141
|
- lib/facebooker/session.rb
|
140
|
-
- lib/facebooker/session.rb.orig
|
141
|
-
- lib/facebooker/session.rb.rej
|
142
142
|
- lib/facebooker/version.rb
|
143
143
|
- lib/facebooker.rb
|
144
144
|
- lib/net/http_multipart_post.rb
|
145
|
+
- lib/rack/facebook.rb
|
145
146
|
- lib/tasks/facebooker.rake
|
146
147
|
- lib/tasks/tunnel.rake
|
147
148
|
- rails/init.rb
|
@@ -166,6 +167,7 @@ files:
|
|
166
167
|
- test/net/http_multipart_post_test.rb
|
167
168
|
- test/rails_test_helper.rb
|
168
169
|
- test/test_helper.rb
|
170
|
+
- test/facebooker/mobile_test.rb
|
169
171
|
has_rdoc: true
|
170
172
|
homepage:
|
171
173
|
post_install_message:
|