facebooker 0.9.5 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/History.txt +14 -0
  2. data/Manifest.txt +68 -14
  3. data/README +4 -2
  4. data/README.txt +22 -4
  5. data/Rakefile +42 -4
  6. data/TODO.txt +3 -9
  7. data/generators/facebook/facebook_generator.rb +14 -0
  8. data/{facebooker.yml.tpl → generators/facebook/templates/config/facebooker.yml} +12 -2
  9. data/generators/facebook/templates/public/javascripts/facebooker.js +106 -0
  10. data/generators/facebook_controller/USAGE +33 -0
  11. data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
  12. data/generators/facebook_controller/templates/controller.rb +7 -0
  13. data/generators/facebook_controller/templates/functional_test.rb +11 -0
  14. data/generators/facebook_controller/templates/helper.rb +2 -0
  15. data/generators/facebook_controller/templates/view.fbml.erb +2 -0
  16. data/generators/facebook_controller/templates/view.html.erb +2 -0
  17. data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
  18. data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
  19. data/generators/facebook_publisher/templates/publisher.rb +3 -0
  20. data/generators/facebook_scaffold/USAGE +27 -0
  21. data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
  22. data/generators/facebook_scaffold/templates/controller.rb +93 -0
  23. data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
  24. data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
  25. data/generators/facebook_scaffold/templates/helper.rb +2 -0
  26. data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
  27. data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
  28. data/generators/facebook_scaffold/templates/style.css +74 -0
  29. data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
  30. data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
  31. data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
  32. data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
  33. data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
  34. data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
  35. data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
  36. data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
  37. data/generators/publisher/publisher_generator.rb +14 -0
  38. data/generators/xd_receiver/templates/xd_receiver.html +10 -0
  39. data/generators/xd_receiver/xd_receiver_generator.rb +9 -0
  40. data/init.rb +30 -12
  41. data/install.rb +10 -3
  42. data/lib/facebooker.rb +139 -30
  43. data/lib/facebooker/adapters/adapter_base.rb +87 -0
  44. data/lib/facebooker/adapters/bebo_adapter.rb +75 -0
  45. data/lib/facebooker/adapters/facebook_adapter.rb +48 -0
  46. data/lib/facebooker/admin.rb +42 -0
  47. data/lib/facebooker/batch_request.rb +44 -0
  48. data/lib/facebooker/data.rb +24 -5
  49. data/lib/facebooker/feed.rb +18 -5
  50. data/lib/facebooker/logging.rb +51 -0
  51. data/lib/facebooker/model.rb +18 -1
  52. data/lib/facebooker/{affiliation.rb → models/affiliation.rb} +0 -0
  53. data/lib/facebooker/{album.rb → models/album.rb} +0 -0
  54. data/lib/facebooker/models/applicationproperties.rb +39 -0
  55. data/lib/facebooker/{cookie.rb → models/cookie.rb} +0 -0
  56. data/lib/facebooker/{education_info.rb → models/education_info.rb} +0 -0
  57. data/lib/facebooker/{event.rb → models/event.rb} +2 -0
  58. data/lib/facebooker/models/friend_list.rb +16 -0
  59. data/lib/facebooker/{group.rb → models/group.rb} +1 -0
  60. data/lib/facebooker/models/info_item.rb +10 -0
  61. data/lib/facebooker/models/info_section.rb +10 -0
  62. data/lib/facebooker/{location.rb → models/location.rb} +0 -0
  63. data/lib/facebooker/{notifications.rb → models/notifications.rb} +0 -0
  64. data/lib/facebooker/models/page.rb +27 -0
  65. data/lib/facebooker/{photo.rb → models/photo.rb} +4 -1
  66. data/lib/facebooker/{tag.rb → models/tag.rb} +0 -0
  67. data/lib/facebooker/models/user.rb +394 -0
  68. data/lib/facebooker/{work_info.rb → models/work_info.rb} +0 -0
  69. data/lib/facebooker/parser.rb +201 -19
  70. data/lib/facebooker/rails/controller.rb +129 -21
  71. data/lib/facebooker/rails/facebook_form_builder.rb +3 -3
  72. data/lib/facebooker/rails/facebook_pretty_errors.rb +14 -0
  73. data/lib/facebooker/rails/facebook_request_fix.rb +10 -0
  74. data/lib/facebooker/rails/facebook_session_handling.rb +12 -1
  75. data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
  76. data/lib/facebooker/rails/facebook_url_rewriting.rb +11 -3
  77. data/lib/facebooker/rails/helpers.rb +180 -34
  78. data/lib/facebooker/rails/helpers/fb_connect.rb +38 -0
  79. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  80. data/lib/facebooker/rails/publisher.rb +513 -0
  81. data/lib/facebooker/rails/routing.rb +1 -1
  82. data/lib/facebooker/rails/test_helpers.rb +75 -3
  83. data/lib/facebooker/server_cache.rb +3 -3
  84. data/lib/facebooker/service.rb +74 -7
  85. data/lib/facebooker/session.rb +245 -68
  86. data/lib/facebooker/version.rb +3 -3
  87. data/lib/tasks/facebooker.rake +4 -2
  88. data/lib/tasks/tunnel.rake +14 -7
  89. data/rails/init.rb +1 -0
  90. data/templates/layout.erb +24 -0
  91. data/test/adapters_test.rb +98 -0
  92. data/test/batch_request_test.rb +82 -0
  93. data/test/facebook_admin_test.rb +102 -0
  94. data/test/facebook_cache_test.rb +1 -0
  95. data/test/facebook_data_test.rb +36 -0
  96. data/test/facebooker_test.rb +221 -80
  97. data/test/logging_test.rb +43 -0
  98. data/test/model_test.rb +12 -0
  99. data/test/publisher_test.rb +458 -0
  100. data/test/rails_integration_test.rb +538 -33
  101. data/test/session_test.rb +223 -6
  102. data/test/test_helper.rb +8 -2
  103. data/test/user_test.rb +191 -2
  104. metadata +99 -18
  105. data/lib/facebooker/user.rb +0 -200
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+ require File.dirname(__FILE__)+'/../../vendor/plugins/facebooker/lib/facebooker/rails/test_helpers.rb'
3
+
4
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
5
+ include Facebooker::Rails::TestHelpers
6
+ def test_should_get_index_for_facebook
7
+ facebook_get :index
8
+ assert_response :success
9
+ assert_not_nil assigns(:<%= table_name %>)
10
+ end
11
+
12
+ def test_should_get_new_for_facebook
13
+ facebook_get :new
14
+ assert_response :success
15
+ end
16
+
17
+ def test_should_create_<%= file_name %>_for_facebook
18
+ assert_difference('<%= class_name %>.count') do
19
+ facebook_post :create, :<%= file_name %> => { }
20
+ end
21
+
22
+ assert_facebook_redirect_to <%= file_name %>_path(assigns(:<%= file_name %>))
23
+ end
24
+
25
+ def test_should_show_<%= file_name %>_for_facebook
26
+ facebook_get :show, :id => <%= table_name %>(:one).id
27
+ assert_response :success
28
+ end
29
+
30
+ def test_should_get_edit_for_facebook
31
+ facebook_get :edit, :id => <%= table_name %>(:one).id
32
+ assert_response :success
33
+ end
34
+
35
+ def test_should_update_<%= file_name %>_for_facebook
36
+ facebook_put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
37
+ assert_facebook_redirect_to <%= file_name %>_path(assigns(:<%= file_name %>))
38
+ end
39
+
40
+ def test_should_destroy_<%= file_name %>_for_facebook
41
+ assert_difference('<%= class_name %>.count', -1) do
42
+ facebook_delete :destroy, :id => <%= table_name %>(:one).id
43
+ end
44
+
45
+ assert_facebook_redirect_to <%= table_name %>_path
46
+ end
47
+
48
+ def test_should_get_index
49
+ get :index
50
+ assert_response :success
51
+ assert_not_nil assigns(:<%= table_name %>)
52
+ end
53
+
54
+ def test_should_get_new
55
+ get :new
56
+ assert_response :success
57
+ end
58
+
59
+ def test_should_create_<%= file_name %>
60
+ assert_difference('<%= class_name %>.count') do
61
+ post :create, :<%= file_name %> => { }
62
+ end
63
+
64
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
65
+ end
66
+
67
+ def test_should_show_<%= file_name %>
68
+ get :show, :id => <%= table_name %>(:one).id
69
+ assert_response :success
70
+ end
71
+
72
+ def test_should_get_edit
73
+ get :edit, :id => <%= table_name %>(:one).id
74
+ assert_response :success
75
+ end
76
+
77
+ def test_should_update_<%= file_name %>
78
+ put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
79
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
80
+ end
81
+
82
+ def test_should_destroy_<%= file_name %>
83
+ assert_difference('<%= class_name %>.count', -1) do
84
+ delete :destroy, :id => <%= table_name %>(:one).id
85
+ end
86
+
87
+ assert_redirected_to <%= table_name %>_path
88
+ end
89
+ end
@@ -0,0 +1,2 @@
1
+ module <%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,6 @@
1
+ <%%= stylesheet_link_tag 'facebook_scaffold' %>
2
+ <%%= facebook_messages %>
3
+
4
+ <div style="padding:10px">
5
+ <%%= yield %>
6
+ </div>
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <title><%= controller_class_name %>: <%%= controller.action_name %></title>
8
+ <%%= stylesheet_link_tag 'scaffold' %>
9
+ </head>
10
+ <body>
11
+
12
+ <p style="color: green"><%%= flash[:notice] %></p>
13
+
14
+ <%%= yield %>
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,74 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
55
+ div.uploadStatus {
56
+ margin: 5px;
57
+ }
58
+
59
+ div.progressBar {
60
+ margin: 5px;
61
+ }
62
+
63
+ div.progressBar div.border {
64
+ background-color: #fff;
65
+ border: 1px solid gray;
66
+ width: 100%;
67
+ }
68
+
69
+ div.progressBar div.background {
70
+ background-color: #333;
71
+ height: 18px;
72
+ width: 0%;
73
+ }
74
+
@@ -0,0 +1,13 @@
1
+ <h1>Editing <%= singular_name %></h1>
2
+
3
+ <%% facebook_form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
8
+ <% end -%>
9
+ <%%= f.buttons "Update" %>
10
+ <%% end %>
11
+
12
+ <%%= link_to 'Show', @<%= singular_name %> %> |
13
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,18 @@
1
+ <h1>Editing <%= singular_name %></h1>
2
+
3
+ <%% form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <p>
8
+ <%%= f.label :<%= attribute.name %> %><br />
9
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
10
+ </p>
11
+ <% end -%>
12
+ <p>
13
+ <%%= f.submit "Update" %>
14
+ </p>
15
+ <%% end %>
16
+
17
+ <%%= link_to 'Show', @<%= singular_name %> %> |
18
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,24 @@
1
+ <h1>Listing <%= plural_name %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <% for attribute in attributes -%>
6
+ <th><%= attribute.column.human_name %></th>
7
+ <% end -%>
8
+ </tr>
9
+
10
+ <%% for <%= singular_name %> in @<%= plural_name %> %>
11
+ <tr>
12
+ <% for attribute in attributes -%>
13
+ <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
14
+ <% end -%>
15
+ <td><%%= link_to 'Show', <%= singular_name %> %></td>
16
+ <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
17
+ <td><%%= button_to 'Destroy', <%= singular_name %>, :method => :delete %></td>
18
+ </tr>
19
+ <%% end %>
20
+ </table>
21
+
22
+ <br />
23
+
24
+ <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
@@ -0,0 +1,24 @@
1
+ <h1>Listing <%= plural_name %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <% for attribute in attributes -%>
6
+ <th><%= attribute.column.human_name %></th>
7
+ <% end -%>
8
+ </tr>
9
+
10
+ <%% for <%= singular_name %> in @<%= plural_name %> %>
11
+ <tr>
12
+ <% for attribute in attributes -%>
13
+ <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
14
+ <% end -%>
15
+ <td><%%= link_to 'Show', <%= singular_name %> %></td>
16
+ <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
17
+ <td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
18
+ </tr>
19
+ <%% end %>
20
+ </table>
21
+
22
+ <br />
23
+
24
+ <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
@@ -0,0 +1,12 @@
1
+ <h1>New <%= singular_name %></h1>
2
+
3
+ <%% facebook_form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
8
+ <% end -%>
9
+ <%%= f.buttons "Create" %>
10
+ <%% end %>
11
+
12
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,17 @@
1
+ <h1>New <%= singular_name %></h1>
2
+
3
+ <%% form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <p>
8
+ <%%= f.label :<%= attribute.name %> %><br />
9
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
10
+ </p>
11
+ <% end -%>
12
+ <p>
13
+ <%%= f.submit "Create" %>
14
+ </p>
15
+ <%% end %>
16
+
17
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,10 @@
1
+ <% for attribute in attributes -%>
2
+ <p>
3
+ <b><%= attribute.column.human_name %>:</b>
4
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+
9
+ <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
10
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,10 @@
1
+ <% for attribute in attributes -%>
2
+ <p>
3
+ <b><%= attribute.column.human_name %>:</b>
4
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+
9
+ <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
10
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,14 @@
1
+ class PublisherGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ puts banner
4
+ exit(1)
5
+ end
6
+
7
+ def banner
8
+ <<-EOM
9
+ This generator has been renamed to facebook_publisher
10
+ please run: #{$0} facebook_publisher
11
+ EOM
12
+ end
13
+
14
+ end
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" >
4
+ <head>
5
+ <title>Cross-Domain Receiver Page</title>
6
+ </head>
7
+ <body>
8
+ <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.debug.js" type="text/javascript"></script>
9
+ </body>
10
+ </html>
@@ -0,0 +1,9 @@
1
+ class XdReceiverGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.template "xd_receiver.html", "public/xd_receiver.html"
5
+ end
6
+ end
7
+
8
+
9
+ end
data/init.rb CHANGED
@@ -1,3 +1,13 @@
1
+ # Added support to the Facebooker.yml file for switching to the new profile design..
2
+ # Config parsing needs to happen before files are required.
3
+ facebook_config = "#{RAILS_ROOT}/config/facebooker.yml"
4
+
5
+ require 'facebooker'
6
+ FACEBOOKER = Facebooker.load_configuration(facebook_config)
7
+
8
+ # enable logger before including everything else, in case we ever want to log initialization
9
+ Facebooker.logger = RAILS_DEFAULT_LOGGER if Object.const_defined? :RAILS_DEFAULT_LOGGER
10
+
1
11
  require 'net/http_multipart_post'
2
12
  require 'facebooker/rails/controller'
3
13
  require 'facebooker/rails/facebook_url_rewriting'
@@ -5,7 +15,8 @@ require 'facebooker/rails/facebook_session_handling'
5
15
  require 'facebooker/rails/facebook_asset_path'
6
16
  require 'facebooker/rails/facebook_request_fix'
7
17
  require 'facebooker/rails/routing'
8
-
18
+ require 'facebooker/rails/facebook_pretty_errors' rescue nil
19
+ require 'facebooker/rails/facebook_url_helper'
9
20
  module ::ActionController
10
21
  class Base
11
22
  def self.inherited_with_facebooker(subclass)
@@ -21,7 +32,6 @@ module ::ActionController
21
32
  end
22
33
  end
23
34
 
24
-
25
35
  class ActionController::Routing::Route
26
36
  def recognition_conditions_with_facebooker
27
37
  defaults = recognition_conditions_without_facebooker
@@ -30,6 +40,23 @@ class ActionController::Routing::Route
30
40
  end
31
41
  alias_method_chain :recognition_conditions, :facebooker
32
42
  end
43
+
44
+ # When making get requests, Facebook sends fb_sig parameters both in the query string
45
+ # and also in the post body. We want to ignore the query string ones because they are one
46
+ # request out of date
47
+ # We only do thise when there are POST parameters so that IFrame linkage still works
48
+ class ActionController::AbstractRequest
49
+ def query_parameters_with_facebooker
50
+ if request_parameters.blank?
51
+ query_parameters_without_facebooker
52
+ else
53
+ (query_parameters_without_facebooker||{}).reject {|key,value| key.to_s =~ /^fb_sig/}
54
+ end
55
+ end
56
+
57
+ alias_method_chain :query_parameters, :facebooker
58
+ end
59
+
33
60
  # We turn off route optimization to make named routes use our code for figuring out if they should go to the session
34
61
  # If this fails, it means we're on rails 1.2, we can ignore it
35
62
  begin
@@ -37,16 +64,7 @@ begin
37
64
  rescue NoMethodError=>e
38
65
  nil
39
66
  end
67
+
40
68
  # pull :canvas=> into env in routing to allow for conditions
41
69
  ActionController::Routing::RouteSet.send :include, Facebooker::Rails::Routing::RouteSetExtensions
42
70
  ActionController::Routing::RouteSet::Mapper.send :include, Facebooker::Rails::Routing::MapperExtensions
43
-
44
- facebook_config = "#{RAILS_ROOT}/config/facebooker.yml"
45
-
46
- if File.exist?(facebook_config)
47
- FACEBOOKER = YAML.load_file(facebook_config)[RAILS_ENV]
48
- ENV['FACEBOOK_API_KEY'] = FACEBOOKER['api_key']
49
- ENV['FACEBOOK_SECRET_KEY'] = FACEBOOKER['secret_key']
50
- ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = FACEBOOKER['canvas_page_name']
51
- ActionController::Base.asset_host = FACEBOOKER['callback_url']
52
- end