faceb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.document +5 -0
  2. data/.gitignore +24 -0
  3. data/Gemfile +13 -0
  4. data/LICENSE +20 -0
  5. data/README.md +70 -0
  6. data/Rakefile +76 -0
  7. data/VERSION +1 -0
  8. data/bin/console +3 -0
  9. data/faceb.gemspec +164 -0
  10. data/features/faceb-session.feature +7 -0
  11. data/features/step_definitions/facebook-session_steps.rb +14 -0
  12. data/features/support/env.rb +4 -0
  13. data/lib/faceb.rb +7 -0
  14. data/lib/faceb/api.rb +69 -0
  15. data/lib/faceb/base.rb +51 -0
  16. data/lib/faceb/rails.rb +12 -0
  17. data/lib/faceb/rails/api.rb +21 -0
  18. data/lib/faceb/rails/base.rb +30 -0
  19. data/lib/faceb/rails/configuration.rb +31 -0
  20. data/lib/faceb/rails/controller.rb +49 -0
  21. data/lib/faceb/rails/generators.rb +3 -0
  22. data/lib/faceb/rails/generators/config/USAGE +8 -0
  23. data/lib/faceb/rails/generators/config/config_generator.rb +16 -0
  24. data/lib/faceb/rails/generators/config/templates/faceb.yml +6 -0
  25. data/lib/faceb/rails/generators/fb_connect/USAGE +7 -0
  26. data/lib/faceb/rails/generators/fb_connect/fb_connect_generator.rb +16 -0
  27. data/lib/faceb/rails/generators/fb_connect/templates/xd_receiver.html +10 -0
  28. data/lib/faceb/rails/generators/fb_connect/templates/xd_receiver_ssl.html +10 -0
  29. data/lib/faceb/rails/rails_23_init.rb +21 -0
  30. data/lib/faceb/rails/railtie.rb +39 -0
  31. data/lib/faceb/rails/tasks.rb +2 -0
  32. data/lib/faceb/rails/tasks/faceb.tasks +6 -0
  33. data/lib/faceb/rails/tasks/tunnel.tasks +46 -0
  34. data/lib/faceb/session.rb +38 -0
  35. data/spec/faceb_api_spec.rb +107 -0
  36. data/spec/faceb_base_spec.rb +48 -0
  37. data/spec/faceb_session_spec.rb +64 -0
  38. data/spec/rails/config_generator_spec.rb +39 -0
  39. data/spec/rails/configuration_sepc.rb +11 -0
  40. data/spec/rails/controller_spec.rb +39 -0
  41. data/spec/rails/fb_connect_generator_spec.rb +28 -0
  42. data/spec/rails/railtie_spec.rb +23 -0
  43. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  44. data/spec/rails_app/app/controllers/posts_controller.rb +7 -0
  45. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  46. data/spec/rails_app/config.ru +4 -0
  47. data/spec/rails_app/config/application.rb +46 -0
  48. data/spec/rails_app/config/boot.rb +9 -0
  49. data/spec/rails_app/config/database.yml +22 -0
  50. data/spec/rails_app/config/environment.rb +5 -0
  51. data/spec/rails_app/config/environments/development.rb +19 -0
  52. data/spec/rails_app/config/environments/production.rb +33 -0
  53. data/spec/rails_app/config/environments/test.rb +32 -0
  54. data/spec/rails_app/config/faceb.yml +3 -0
  55. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
  57. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  58. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  59. data/spec/rails_app/config/initializers/session_store.rb +10 -0
  60. data/spec/rails_app/config/locales/en.yml +5 -0
  61. data/spec/rails_app/config/routes.rb +58 -0
  62. data/spec/rails_app/log/development.log +0 -0
  63. data/spec/rails_app/log/production.log +0 -0
  64. data/spec/rails_app/log/server.log +0 -0
  65. data/spec/rails_app/log/test.log +0 -0
  66. data/spec/rails_app/public/404.html +26 -0
  67. data/spec/rails_app/public/422.html +26 -0
  68. data/spec/rails_app/public/500.html +26 -0
  69. data/spec/rails_app/public/favicon.ico +0 -0
  70. data/spec/rails_app/public/javascripts/application.js +2 -0
  71. data/spec/rails_app/public/javascripts/controls.js +965 -0
  72. data/spec/rails_app/public/javascripts/dragdrop.js +974 -0
  73. data/spec/rails_app/public/javascripts/effects.js +1123 -0
  74. data/spec/rails_app/public/javascripts/prototype.js +4874 -0
  75. data/spec/rails_app/public/javascripts/rails.js +110 -0
  76. data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
  77. data/spec/rails_app/script/rails +9 -0
  78. data/spec/rails_spec_helper.rb +6 -0
  79. data/spec/spec.opts +1 -0
  80. data/spec/spec_helper.rb +27 -0
  81. metadata +247 -0
@@ -0,0 +1,107 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module FaceB
4
+ describe Api do
5
+ describe "Default params" do
6
+ subject { FaceB::Api.default_params }
7
+
8
+ it { subject[:format].should == 'JSON' }
9
+ it { subject[:v].should == '1.0' }
10
+ end
11
+
12
+ # Call
13
+ describe "#call" do
14
+ before(:each) do
15
+ @session = FaceB.new('api-key', 'secret-key')
16
+ end
17
+
18
+ # Error Response
19
+ context "When error" do
20
+ before(:each) do
21
+ mock(FaceB::Api).post(FaceB::Api::API_SERVER_URL, is_a(Hash)) {
22
+ {"error_msg" => "error message", "error_code" => 100}
23
+ }
24
+ end
25
+
26
+ it "should get error nicely" do
27
+ lambda {
28
+ @session.call("facebook.method")
29
+ }.should raise_error(FaceB::Api::Error, "Facebook error 100 : 'error message'")
30
+ end
31
+ end
32
+
33
+ # Success Response with String
34
+ context "When success with string response" do
35
+ before(:each) do
36
+ mock(FaceB::Api).post(FaceB::Api::API_SERVER_URL, is_a(Hash)) { "data" }
37
+ @response = @session.call("facebook.method")
38
+ end
39
+
40
+ subject { @response }
41
+
42
+ it { should be_an_instance_of(FaceB::Api::Response) }
43
+ its(:data) { should == 'data'}
44
+ end
45
+
46
+ # Success Response with Array with one Hash element
47
+ context "When success with one Array response with one Hash element" do
48
+ before(:each) do
49
+ mock(FaceB::Api).post(FaceB::Api::API_SERVER_URL, is_a(Hash)) {
50
+ [{'key1' => 'value1', 'key2' => 'value2'}]
51
+ }
52
+ @response = @session.call("facebook.method")
53
+ end
54
+
55
+ subject { @response }
56
+
57
+ it { should be_an_instance_of(FaceB::Api::Response) }
58
+ its(:data) { should == [{"key1"=>"value1", "key2"=>"value2"}] }
59
+ its(:key1) { should == "value1" }
60
+ its(:key2) { should == "value2" }
61
+ end
62
+
63
+ # Success Response one Hash element
64
+ context "When success with one Hash response" do
65
+ before(:each) do
66
+ mock(FaceB::Api).post(FaceB::Api::API_SERVER_URL, is_a(Hash)) {
67
+ {'key1' => 'value1', 'key2' => 'value2'}
68
+ }
69
+ @response = @session.call("facebook.method")
70
+ end
71
+
72
+ subject { @response }
73
+
74
+ it { should be_an_instance_of(FaceB::Api::Response) }
75
+ its(:data) { should == {"key1"=>"value1", "key2"=>"value2"} }
76
+ its(:key1) { should == "value1" }
77
+ its(:key2) { should == "value2" }
78
+ end
79
+
80
+
81
+ # Session Key
82
+ context "With Session key" do
83
+ before(:each) do
84
+ mock.instance_of(FaceB::Session).secure_with_session_key!('session-key').once { 12345 }
85
+ mock(@session).call('users.getLoggedInUser', :session_key => 'session-key') { FaceB::Api::Response.new(12345) }
86
+ @session.secure_with_session_key!('session-key')
87
+ @api = FaceB::Api.new(@session)
88
+ end
89
+
90
+ it "should pass the current session_key if param is true" do
91
+ mock(FaceB::Api).post(FaceB::Api::API_SERVER_URL, satisfy {|arg| arg[:body][:session_key] == "session-key"} ) {
92
+ {"ok" => "ok"}
93
+ }
94
+ @api.call('method', :session_key => true)
95
+ end
96
+
97
+ it "should be able to averride the current session_key" do
98
+ mock(FaceB::Api).post(FaceB::Api::API_SERVER_URL, satisfy {|arg| arg[:body][:session_key] == "my-new-session-key"} ) {
99
+ {"ok" => "ok"}
100
+ }
101
+ @api.call('method', :session_key => 'my-new-session-key')
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe FaceB do
4
+
5
+ describe "#current_session" do
6
+ before(:each) do
7
+ @session = FaceB.new('api-key', 'secret-key')
8
+ end
9
+
10
+ subject { FaceB.current_session }
11
+
12
+ it { should be_an_instance_of(FaceB::Session) }
13
+ it { should == @session }
14
+
15
+ its(:api_key) { should == 'api-key' }
16
+ its(:secret_key) { should == 'secret-key' }
17
+ end
18
+
19
+ # New
20
+ describe "#new" do
21
+ before(:each) do
22
+ @session = FaceB.new('api-key', 'secret-key')
23
+ end
24
+
25
+ subject { @session }
26
+
27
+ its(:api_key) { should == 'api-key' }
28
+ its(:secret_key) { should == 'secret-key' }
29
+
30
+ it "should be able to reset the current session" do
31
+ FaceB::Session.reset!
32
+ FaceB.current_session.should be_nil
33
+ end
34
+ end
35
+
36
+ # Call
37
+ describe "#call" do
38
+ it "should be able to call the api without create a session before" do
39
+ mock.instance_of(FaceB::Session).call('method', :params => 1) { "response" }
40
+ FaceB.call('api-key', 'secret-key', 'method', :params => 1).should == "response"
41
+ FaceB.current_session.should be_nil
42
+ end
43
+ end
44
+
45
+ it "should not be included in Facebook" do
46
+ FaceB.should_not respond_to(:config)
47
+ end
48
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module FaceB
4
+ describe Session do
5
+
6
+ # Create session
7
+ context "When create session" do
8
+ before(:each) do
9
+ @session = FaceB::Session.create('api-key', 'secret-key')
10
+ end
11
+
12
+ subject { @session }
13
+
14
+ its(:api_key) { should == 'api-key' }
15
+ its(:secret_key) { should == 'secret-key' }
16
+
17
+ it { should be_an_instance_of(FaceB::Session) }
18
+
19
+ it "should set session as the current session" do
20
+ FaceB::Session.current.should == @session
21
+ end
22
+
23
+ it "should be able to reset the current session" do
24
+ FaceB::Session.reset!
25
+ FaceB::Session.current.should be_nil
26
+ end
27
+ end
28
+
29
+ # New session
30
+ context "When instanciate new session" do
31
+ before(:each) do
32
+ @session = FaceB::Session.new('api-key', 'secret-key')
33
+ end
34
+
35
+ subject { @session }
36
+
37
+ its(:api_key) { should == 'api-key' }
38
+ its(:secret_key) { should == 'secret-key' }
39
+
40
+ it { should be_an_instance_of(FaceB::Session) }
41
+
42
+ it "should not have persistent session" do
43
+ FaceB::Session.current.should be_nil
44
+ end
45
+
46
+ # Session key
47
+ context "With session key" do
48
+ before(:each) do
49
+ mock.instance_of(FaceB::Session).call('users.getLoggedInUser', :session_key => 'session-key') { FaceB::Api::Response.new(12345) }
50
+ @session = FaceB::Session.new('api-key', 'secret-key', 'session-key')
51
+ end
52
+
53
+ subject { @session }
54
+
55
+ its(:api_key) { should == 'api-key' }
56
+ its(:secret_key) { should == 'secret-key' }
57
+ its(:session_key) { should == 'session-key' }
58
+ its(:user_facebook_uid) { should == 12345 }
59
+
60
+ it { should be_an_instance_of(FaceB::Session) }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module FaceB
4
+ describe ConfigGenerator do
5
+ before do
6
+ @destination = TMP_DIR
7
+ @config_file = File.join(@destination, 'config', 'faceb.yml')
8
+ @source = ConfigGenerator.source_root
9
+ end
10
+
11
+ after do
12
+ FileUtils.rm_rf(@destination)
13
+ end
14
+
15
+ it "should copy Faceb config file" do
16
+ ConfigGenerator.start([], :destination_root => @destination)
17
+ File.exists?(@config_file).should be_true
18
+ end
19
+
20
+ it "should accept options" do
21
+ ConfigGenerator.start(['--api-key=my-api-key', '--secret-key=my-secret-key'], :destination_root => @destination)
22
+
23
+ File.exists?(@config_file).should be_true
24
+ file_content = IO.read(@config_file)
25
+ file_content.should =~ /api_key: my-api-key/
26
+ file_content.should =~ /secret_key: my-secret-key/
27
+ end
28
+
29
+
30
+ it "should accept aliases" do
31
+ ConfigGenerator.start(['-a=my-api-key', '-s=my-secret-key'], :destination_root => @destination)
32
+
33
+ File.exists?(@config_file).should be_true
34
+ file_content = IO.read(@config_file)
35
+ file_content.should =~ /api_key: my-api-key/
36
+ file_content.should =~ /secret_key: my-secret-key/
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module FaceB
4
+ module Rails
5
+ describe Configuration do
6
+ it "should be included in FaceB" do
7
+ FaceB.should respond_to(:config)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ # Dummy Controller
4
+ Dummy::Application.initialize!
5
+ class MockController < ApplicationController
6
+ include FaceB::Rails::Controller
7
+
8
+ ensure_authenticated_to_facebook :only => :action1
9
+
10
+ def self.before_filters
11
+ _process_action_callbacks.select { |c| c.kind == :before }
12
+ end
13
+
14
+ def action1;end
15
+ def action2;end
16
+ end
17
+
18
+ # MockController
19
+ describe MockController do
20
+ describe "ClassMethods" do
21
+ it "should include before_filter 'set_facebook_request_format'" do
22
+ filters = MockController.before_filters.map! { |c| c.raw_filter }
23
+ filters.should include(:set_facebook_request_format)
24
+ end
25
+
26
+ it "should include ensure_authenticated_to_facebook filter only for action1" do
27
+ filter = MockController.before_filters.find {|f| f.raw_filter == :ensure_authenticated_to_facebook}
28
+ filter.options[:only].should == :action1
29
+ end
30
+ end
31
+
32
+
33
+ #describe "#facebook_session" do
34
+ # before(:each) { @controller.get :action1 }
35
+ # subject { @controller.facebook_session }
36
+ #
37
+ # it { should be_an_instance_of(FaceB::Session) }
38
+ #end
39
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module FaceB
4
+ describe FbConnectGenerator do
5
+ before do
6
+ @destination = TMP_DIR
7
+ @source = FbConnectGenerator.source_root
8
+ end
9
+
10
+ after do
11
+ FileUtils.rm_rf(@destination)
12
+ end
13
+
14
+ it "should create xd_receiver file" do
15
+ FbConnectGenerator.start([], :destination_root => @destination)
16
+ file = File.join(TMP_DIR, 'public', 'xd_receiver.html')
17
+ File.exists?(file).should be_true
18
+ IO.read(file).should =~ %r{http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js}
19
+ end
20
+
21
+ it "should create xd_receiver file with SSL support" do
22
+ FbConnectGenerator.start(['--ssl'], :destination_root => @destination)
23
+ file = File.join(TMP_DIR, 'public', 'xd_receiver_ssl.html')
24
+ File.exists?(file).should be_true
25
+ IO.read(file).should =~ %r{https://ssl.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js}
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Rails app initialization" do
4
+ before(:each) do
5
+ Dummy::Application.initialize!
6
+ end
7
+
8
+ it "should load facebook config file" do
9
+ FaceB.config.should_not be_nil
10
+ FaceB.config.api_key.should == 'rails-api-key'
11
+ FaceB.config.secret_key.should == 'rails-secret-key'
12
+ end
13
+
14
+ it "should add Rack-Facebook as a middleware" do
15
+ Dummy::Application.config.middleware.should include(Rack::Facebook)
16
+ end
17
+
18
+ it "should add FBML request type" do
19
+ mime_type = Mime::Type.lookup(:fbml)
20
+ mime_type.should_not be_nil
21
+ mime_type.should be_an_instance_of(Mime::Type)
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,7 @@
1
+ class PostsController < ApplicationController
2
+ include FaceB::Rails::Controller
3
+
4
+ def index
5
+ render 'index'
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "faceb/rails"
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Add additional load paths for your own custom dirs
19
+ # config.load_paths += %W( #{config.root}/extras )
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # Configure generators values. Many other options are available, be sure to check the documentation.
37
+ # config.generators do |g|
38
+ # g.orm :active_record
39
+ # g.template_engine :erb
40
+ # g.test_framework :test_unit, :fixture => true
41
+ # end
42
+
43
+ # Configure sensitive parameters which will be filtered from the log file.
44
+ config.filter_parameters << :password
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ begin
2
+ require File.expand_path("../../../../.bundle/environment", __FILE__)
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ Bundler.setup
7
+ end
8
+
9
+ $:.unshift File.expand_path('../../../../lib', __FILE__)