facebook_rails 0.0.3 → 0.1.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.
- data/app/helpers/facebook_rails_helper.rb +6 -5
- data/lib/facebook_rails/engine.rb +1 -1
- data/lib/facebook_rails/test.rb +56 -0
- data/lib/facebook_rails/version.rb +1 -1
- data/lib/generators/facebook_rails/facebook_rails_generator.rb +8 -0
- data/lib/generators/facebook_rails/templates/f8_user_mocks/f8_user_mocks_info.txt +13 -0
- data/lib/generators/facebook_rails/templates/f8_user_mocks/probni.yml +41 -0
- data/lib/generators/facebook_rails/templates/f8_user_mocks/radan.yml +585 -0
- data/lib/generators/facebook_rails/templates/f8_user_mocks/required_f8_data.yml +7 -0
- data/lib/generators/facebook_rails/templates/f8_user_mocks/ruki.yml +708 -0
- data/lib/tasks/facebook_rails_tasks.rake +74 -0
- metadata +14 -8
@@ -8,8 +8,8 @@ module FacebookRailsHelper
|
|
8
8
|
'</script>'
|
9
9
|
end
|
10
10
|
|
11
|
-
def facebook_initialization
|
12
|
-
|
11
|
+
def facebook_initialization resize = :auto, app_id = FACEBOOK['app_id'], user_f8id = current_user_f8id
|
12
|
+
onload_resize = %{
|
13
13
|
var domLoaded = false;
|
14
14
|
var facebookLoaded = false;
|
15
15
|
var pageLoaded = false;
|
@@ -66,15 +66,16 @@ module FacebookRailsHelper
|
|
66
66
|
|
67
67
|
%{
|
68
68
|
<div id="fb-root"></div>
|
69
|
-
<script>
|
70
|
-
#{
|
69
|
+
<script type="text/javascript">
|
70
|
+
#{ onload_resize if resize == :onload }
|
71
71
|
window.fbAsyncInit = function() {
|
72
72
|
FB.init({ appId: '#{ app_id }',
|
73
73
|
status: true,
|
74
74
|
cookie: true,
|
75
75
|
xfbml: true });
|
76
76
|
$(document).trigger('facebook_init');
|
77
|
-
#{
|
77
|
+
#{ 'facebookLoaded = true; pageLoad();' if resize == :onload }
|
78
|
+
#{ 'FB.Canvas.setAutoGrow();' if resize == :auto }
|
78
79
|
#{ login_status }
|
79
80
|
};
|
80
81
|
|
@@ -33,7 +33,7 @@ module FacebookRails
|
|
33
33
|
end
|
34
34
|
|
35
35
|
initializer "facebook_rails.facebook_post_patch" do
|
36
|
-
|
36
|
+
Rails::Rack::Logger.class_eval do
|
37
37
|
def call_with_post_override(env)
|
38
38
|
if env["REQUEST_METHOD"]=="POST" and ((env["HTTP_REFERER"] and env["HTTP_REFERER"].to_s =~ /:\/\/[^\/]*facebook.com/) or
|
39
39
|
(env["HTTP_ORIGIN"] and env["HTTP_ORIGIN"].to_s =~ /:\/\/[^\/]*facebook.com/))
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#Additional security to be sure to never, ever run in production ... ever
|
2
|
+
if Rails.env != 'production'
|
3
|
+
|
4
|
+
#require 'koala_rails.rb'
|
5
|
+
|
6
|
+
class FacebookApiMock
|
7
|
+
|
8
|
+
def initialize(open_graph_data)
|
9
|
+
@open_graph_data = open_graph_data
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_object(object_id, options = {})
|
13
|
+
@open_graph_data[:objects][object_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_connections(object_id, connection_name, options = {})
|
17
|
+
@open_graph_data[:connections][object_id][connection_name]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
FacebookRailsController.module_eval do
|
23
|
+
|
24
|
+
def use_as_f8user(name)
|
25
|
+
if name.nil?
|
26
|
+
@test_user_data = nil
|
27
|
+
else
|
28
|
+
@test_user_data = YAML.load_file(Rails.root.join("spec/f8_user_mocks/#{name}.yml"))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def facebook_api
|
33
|
+
@facebook_api ||= FacebookApiMock.new(@test_user_data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def authenticated_by_facebook?
|
37
|
+
!@test_user_data.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
#Will only try to collect facebook credentials but it will let the user in even there aren't any
|
41
|
+
def try_facebook_authentication
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
|
45
|
+
#Will force user to authorize the application to access the current url
|
46
|
+
def ensure_authenticated_to_facebook
|
47
|
+
if @test_user_data.nil?
|
48
|
+
raise "Expected authorized facebook user but none was set, set one in spec using controller.use_as_f8user(name)!"
|
49
|
+
else
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -8,4 +8,12 @@ class FacebookRailsGenerator < Rails::Generators::Base
|
|
8
8
|
def copy_configuration
|
9
9
|
template 'facebook.yml', 'config/facebook.yml'
|
10
10
|
end
|
11
|
+
|
12
|
+
def copy_spec_files
|
13
|
+
directory 'f8_user_mocks', 'spec/f8_user_mocks'
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert_spec_helper
|
17
|
+
insert_into_file "spec/spec_helper.rb", "require 'facebook_rails/test'\n", :after => "require 'rspec/rails'\n"
|
18
|
+
end
|
11
19
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
You must create a yml file with users facebook data.
|
3
|
+
|
4
|
+
To do that go to Facebook Graph API Explorer (https://developers.facebook.com/tools/explorer/) and grab
|
5
|
+
an access token with all the necessary permissions.
|
6
|
+
|
7
|
+
After that run rake facebook_rails:mock_user name=*NAME OF USER* token=*ACCESS TOKEN YOU JUST OBTAINED*
|
8
|
+
|
9
|
+
That yml mock data can be used for testing:
|
10
|
+
|
11
|
+
Place this call in your test before invoking the controller:
|
12
|
+
|
13
|
+
controller.use_as_f8user "*NAME OF USER*"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
:objects:
|
3
|
+
me:
|
4
|
+
id: '1684464858'
|
5
|
+
name: Probni Drap
|
6
|
+
first_name: Probni
|
7
|
+
last_name: Drap
|
8
|
+
link: http://www.facebook.com/profile.php?id=1684464858
|
9
|
+
birthday: 03/15/1980
|
10
|
+
timezone: 2
|
11
|
+
locale: hr_HR
|
12
|
+
verified: true
|
13
|
+
updated_time: '2011-06-17T08:32:57+0000'
|
14
|
+
:connections:
|
15
|
+
me:
|
16
|
+
friends:
|
17
|
+
- name: Radan Skoric
|
18
|
+
id: '503642044'
|
19
|
+
- name: Davor Runje
|
20
|
+
id: '510969565'
|
21
|
+
- name: Ded Sirijus
|
22
|
+
id: '517054106'
|
23
|
+
- name: Josipa BlackNinja Račić
|
24
|
+
id: '628679728'
|
25
|
+
- name: Danijel Milišić
|
26
|
+
id: '694929176'
|
27
|
+
- name: Tomislav Gudlek
|
28
|
+
id: '756277172'
|
29
|
+
- name: Ivan Rukavina
|
30
|
+
id: '774777677'
|
31
|
+
- name: Lovro Zmak
|
32
|
+
id: '1075643189'
|
33
|
+
- name: Joško Oršulić
|
34
|
+
id: '1094436843'
|
35
|
+
- name: Josip Vujcic
|
36
|
+
id: '1393590137'
|
37
|
+
- name: Dumica Dumminigi
|
38
|
+
id: '1531090875'
|
39
|
+
- name: BlackNinja Inkognito
|
40
|
+
id: '100001056206200'
|
41
|
+
|