facebooker3 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 [name of plugin creator]
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.
@@ -0,0 +1,48 @@
1
+ = Facebooker3
2
+
3
+ Introduction goes here.
4
+
5
+ == Installation
6
+
7
+ Facebooker3 can be installed as a plugin by:
8
+
9
+ rails plugin install git@github.com:bvsatyaram/facebooker3.git
10
+
11
+ == Setup
12
+
13
+ In /app/controllers/application_controller, change
14
+ protect_from_forgery
15
+ to
16
+ protect_from_forgery :unless => :request_from_facebook?
17
+
18
+ Copy /vendor/plugins/facebooker3/sample_files/facebooker3.yml to /config folder and update /config/facebooker3.yml with your app settings.
19
+
20
+ == License
21
+
22
+ Copyright (c) 2011 [Satyaram B V], released under the MIT license
23
+
24
+ (The MIT License)
25
+
26
+ Copyright (c) 2011
27
+
28
+ * Satyaram B V
29
+ * Mmanu Chaturvedi
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the facebooker3 plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Generate documentation for the facebooker3 plugin.'
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'Facebooker3'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+ PKG_FILES = FileList[
27
+ '[a-zA-Z]*',
28
+ 'generators/**/*',
29
+ 'lib/**/*',
30
+ 'rails/**/*',
31
+ 'tasks/**/*',
32
+ 'test/**/*'
33
+ ]
34
+
35
+ spec = Gem::Specification.new do |s|
36
+ s.name = "facebooker3"
37
+ s.version = "0.0.1"
38
+ s.author = "Satyaram B V"
39
+ s.email = "bvsatyaram@gmail.com"
40
+ s.homepage = "http://bvsatyaram.com/"
41
+ s.platform = Gem::Platform::RUBY
42
+ s.summary = "Facebook app development on Rails 3"
43
+ s.files = PKG_FILES.to_a
44
+ s.require_path = "lib"
45
+ s.has_rdoc = false
46
+ s.extra_rdoc_files = ["README.rdoc"]
47
+ end
48
+
49
+ desc 'Turn this plugin into a gem.'
50
+ Rake::GemPackageTask.new(spec) do |pkg|
51
+ pkg.gem_spec = spec
52
+ end
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,43 @@
1
+ module Facebooker3
2
+ @facebooker3_configuration = {}
3
+ @raw_facebooker3_configuration = {}
4
+
5
+ class << self
6
+ def load_configuration(facebooker3_yaml_file)
7
+ return false unless File.exist?(facebooker3_yaml_file)
8
+ @raw_facebooker3_configuration = YAML.load(ERB.new(File.read(facebooker3_yaml_file)).result)
9
+ if Rails.env
10
+ @raw_facebooker3_configuration = @raw_facebooker3_configuration[Rails.env]
11
+ end
12
+ apply_configuration(@raw_facebooker3_configuration)
13
+ end
14
+
15
+ # Sets the Facebook environment based on a hash of options.
16
+ # By default the hash passed in is loaded from facebooker3.yml, but it can also be passed in
17
+ # manually every request to run multiple Facebook apps off one Rails app.
18
+ def apply_configuration(config)
19
+ ENV['FACEBOOK_APP_ID'] = config['app_id']
20
+ ENV['FACEBOOK_API_KEY'] = config['api_key']
21
+ ENV['FACEBOOK_SECRET_KEY'] = config['secret_key']
22
+ ENV['FACEBOOK_RELATIVE_ROOT_URL'] = config['canvas_page_name']
23
+
24
+ @facebooker3_configuration = config
25
+ facebooker3_config
26
+ end
27
+
28
+ def facebooker3_config
29
+ @facebooker3_configuration
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'facebooker3/logging'
35
+ require 'facebooker3/signed_request'
36
+ require 'facebooker3/core_ext'
37
+
38
+ %w{ models controllers helpers }.each do |dir|
39
+ path = File.join(File.dirname(__FILE__), 'app', dir)
40
+ $LOAD_PATH << path
41
+ ActiveSupport::Dependencies.autoload_paths << path
42
+ ActiveSupport::Dependencies.autoload_once_paths.delete(path)
43
+ end
@@ -0,0 +1,8 @@
1
+ # ActionController::Base extensions
2
+ module FacebookRequestValidator
3
+ def request_from_facebook?
4
+ Facebooker3::FacebookSignedRequest.valid?(params[:signed_request])
5
+ end
6
+ end
7
+
8
+ ActionController::Base.send :include, FacebookRequestValidator
@@ -0,0 +1,17 @@
1
+ module Facebooker3
2
+ @@logger = nil
3
+ def self.logger=(logger)
4
+ @@logger = logger
5
+ end
6
+ def self.logger
7
+ @@logger
8
+ end
9
+
10
+ module Logging
11
+ def self.log_info(message, dump)
12
+ return unless Facebooker3.logger
13
+ log_message = "#{message} #{dump}"
14
+ Facebooker3.logger.info(log_message)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+
4
+ module Facebooker3::FacebookSignedRequest
5
+ def self.valid?(signed_request, secret = ENV['FACEBOOK_SECRET_KEY'])
6
+ return false if signed_request.nil?
7
+
8
+ encoded_sign, payload = signed_request.split('.')
9
+ sign = str_to_hex(base64_url_decode(encoded_sign))
10
+
11
+ data = ActiveSupport::JSON.decode base64_url_decode(payload)
12
+ if data['algorithm'].to_s.upcase != 'HMAC-SHA256'
13
+ return false
14
+ end
15
+
16
+ expected_sig = OpenSSL::HMAC.hexdigest('sha256', secret, payload)
17
+ if expected_sig != sign
18
+ return false
19
+ end
20
+
21
+ return true
22
+ end
23
+
24
+ protected
25
+
26
+ def self.base64_url_decode(str)
27
+ encoded_str = str.gsub('-','+').gsub('_','/')
28
+ encoded_str += '=' while !(encoded_str.size % 4).zero?
29
+ Base64.decode64(encoded_str)
30
+ end
31
+
32
+ def self.str_to_hex(string)
33
+ (0..(string.size-1)).to_a.map do |i|
34
+ number = string[i].to_s(16)
35
+ (string[i] < 16) ? ('0' + number) : number
36
+ end.join
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ facebook_config = "#{Rails.root.to_s}/config/facebooker3.yml"
2
+
3
+ require 'facebooker3'
4
+ FACEBOOKER = Facebooker3.load_configuration(facebook_config)
5
+
6
+ # enable logger before including everything else, in case we ever want to log initialization
7
+ Facebooker3.logger = ::Rails.logger if ::Rails.logger
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class Facebooker3Test < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebooker3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Satyaram B V
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-07 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: bvsatyaram@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - install.rb
32
+ - MIT-LICENSE
33
+ - Rakefile
34
+ - README.rdoc
35
+ - uninstall.rb
36
+ - lib/facebooker3/core_ext.rb
37
+ - lib/facebooker3/logging.rb
38
+ - lib/facebooker3/signed_request.rb
39
+ - lib/facebooker3.rb
40
+ - rails/init.rb
41
+ - test/facebooker3_test.rb
42
+ - test/test_helper.rb
43
+ has_rdoc: true
44
+ homepage: http://bvsatyaram.com/
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.7
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Facebook app development on Rails 3
77
+ test_files: []
78
+