fb_rails 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -18,6 +18,10 @@ or
18
18
  config.facebook.app_id = 'my_app_id'
19
19
  config.facebook.secret = 'my_app_secret'
20
20
 
21
+ Requests use http by default. To use https, set 'use_ssl' to true:
22
+
23
+ config.facebook.use_ssl = true
24
+
21
25
  Getting the user logged in is out of the scope of this gem. That's what
22
26
  FBML and the Facebook Javascript API are for. Here's an example:
23
27
 
@@ -29,7 +33,7 @@ FBML and the Facebook Javascript API are for. Here's an example:
29
33
  <%= fbml 'login-button' %>
30
34
 
31
35
 
32
- == API
36
+ == FBRails API
33
37
 
34
38
  FbRails adds an object called 'fb', which is available to all controllers and views:
35
39
 
@@ -41,12 +45,17 @@ Get the Facebook user id for the current user:
41
45
 
42
46
  fb.uid
43
47
 
48
+ Get the Facebook user's access token:
49
+
50
+ fb.access_token
51
+
44
52
  Retrieve your Facebook application app_id or secret:
53
+
45
54
  fb.app_id
46
55
  fb.secret
47
56
 
48
57
 
49
- == Using the Graph
58
+ == Using the Graph API
50
59
 
51
60
  Make a request to the Facebook Graph:
52
61
 
@@ -54,6 +63,7 @@ Make a request to the Facebook Graph:
54
63
  my name is <%= result['first_name'] %>
55
64
 
56
65
  Post to the user's wall:
66
+
57
67
  fb.graph.post 'me/feed', :message => 'I like turtles'
58
68
 
59
69
 
@@ -1,6 +1,6 @@
1
1
  module FbRails
2
2
  class Config
3
- class_attribute :app_id, :secret, :user_class_name
3
+ class_attribute :app_id, :secret, :user_class_name, :use_ssl
4
4
 
5
5
  class << self
6
6
  def user_class
data/lib/fb_rails/fb.rb CHANGED
@@ -9,7 +9,7 @@ module FbRails
9
9
  end
10
10
 
11
11
  def graph
12
- @graph ||= FbRails::Graph.new(connect)
12
+ @graph ||= FbRails::Graph.new(connect.access_token)
13
13
  end
14
14
 
15
15
  private
@@ -7,50 +7,58 @@ module FbRails
7
7
  class Graph
8
8
  class << self
9
9
  def facebook_uri
10
- @facebook_uri ||= URI.parse('https://graph.facebook.com')
11
- end
12
-
13
- def http
14
- Net::HTTP.new(facebook_uri.host, facebook_uri.port).tap do |result|
15
- result.use_ssl = true
16
- result.verify_mode = OpenSSL::SSL::VERIFY_NONE
10
+ @facebook_uri ||= begin
11
+ protocol = FbRails::Config.use_ssl ? 'https': 'http'
12
+ URI.parse("#{protocol}://graph.facebook.com")
17
13
  end
18
14
  end
19
15
 
20
- def get(path, params)
16
+ def get(path, params = {})
21
17
  request(:get, "#{path}?#{build_param_string(params)}")
22
18
  end
23
19
 
24
- def post(path, params)
20
+ def post(path, params = {})
25
21
  request(:post, path, build_param_string(params))
26
22
  end
27
23
 
28
- def request(http_verb, path, *arguments)
29
- response = ActiveSupport::Notifications.instrument('request.fb_rails') do |payload|
30
- payload[:http_verb] = http_verb
31
- payload[:request_uri] = path
32
- http.send(http_verb, path, *arguments)
24
+ private
25
+ def request(http_verb, path, *arguments)
26
+ response = ActiveSupport::Notifications.instrument('request.fb_rails') do |payload|
27
+ payload[:http_verb] = http_verb
28
+ payload[:request_uri] = path
29
+ http.send(http_verb, path, *arguments)
30
+ end
31
+
32
+ ActiveSupport::JSON.decode(response.body)
33
33
  end
34
34
 
35
- ActiveSupport::JSON.decode(response.body)
36
- end
35
+ def http
36
+ result = Net::HTTP.new(facebook_uri.host, facebook_uri.port)
37
+ configure_https(result) if facebook_uri.is_a?(URI::HTTPS)
38
+ result
39
+ end
37
40
 
38
- def build_param_string(params)
39
- params.map { |key, value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
40
- end
41
+ def build_param_string(params)
42
+ params.map { |key, value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
43
+ end
44
+
45
+ def configure_https(http)
46
+ http.use_ssl = true
47
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
48
+ end
41
49
  end
42
50
 
43
- attr_reader :connect
44
- def initialize(connect)
45
- @connect = connect
51
+ attr_reader :access_token
52
+ def initialize(access_token)
53
+ @access_token = access_token
46
54
  end
47
55
 
48
56
  def post(path, params = {})
49
- self.class.post(path, params.merge(:access_token => connect.access_token))
57
+ self.class.post(path, params.merge(:access_token => access_token))
50
58
  end
51
59
 
52
60
  def get(path, params = {})
53
- self.class.get(path, params.merge(:access_token => connect.access_token))
61
+ self.class.get(path, params.merge(:access_token => access_token))
54
62
  end
55
63
  end
56
64
  end
data/test/graph_test.rb CHANGED
@@ -1,4 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class FbRails::GraphTest < ActiveSupport::TestCase
4
+ test 'facebook_uri' do
5
+ FbRails::Config.use_ssl = false
6
+ assert_equal 'http', FbRails::Graph.facebook_uri.scheme
7
+
8
+ FbRails::Config.use_ssl = true
9
+ FbRails::Graph.instance_variable_set('@facebook_uri', nil)
10
+ assert_equal 'https', FbRails::Graph.facebook_uri.scheme
11
+ end
4
12
  end
@@ -16,7 +16,7 @@ class FbRails::LogSubscriberTest < ActiveSupport::TestCase
16
16
  end
17
17
 
18
18
  test 'request notification' do
19
- graph = FbRails::Graph.new(FbRails::Connect.new(fb_cookie))
19
+ graph = FbRails::Graph.new('my_access_token')
20
20
  graph.get 'test'
21
21
 
22
22
  wait
data/test/mock_test.rb CHANGED
@@ -8,7 +8,7 @@ class FbRails::MockTest < ActiveSupport::TestCase
8
8
  end
9
9
 
10
10
  test 'mock' do
11
- graph = FbRails::Graph.new(FbRails::Connect.new(fb_cookie))
11
+ graph = FbRails::Graph.new('my_access_token')
12
12
 
13
13
  result = graph.get 'test'
14
14
 
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_rails
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 0
9
- version: 0.6.0
4
+ prerelease:
5
+ version: 0.7.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Matthew Higgins
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-07 00:00:00 -08:00
13
+ date: 2011-02-09 00:00:00 -08:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,10 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 3
30
- - 0
31
- - 0
32
24
  version: 3.0.0
33
25
  type: :development
34
26
  version_requirements: *id001
@@ -83,25 +75,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
75
  requirements:
84
76
  - - ">="
85
77
  - !ruby/object:Gem::Version
86
- segments:
87
- - 1
88
- - 8
89
- - 7
90
78
  version: 1.8.7
91
79
  required_rubygems_version: !ruby/object:Gem::Requirement
92
80
  none: false
93
81
  requirements:
94
82
  - - ">="
95
83
  - !ruby/object:Gem::Version
96
- segments:
97
- - 1
98
- - 3
99
- - 5
100
84
  version: 1.3.5
101
85
  requirements: []
102
86
 
103
87
  rubyforge_project:
104
- rubygems_version: 1.3.7
88
+ rubygems_version: 1.5.0
105
89
  signing_key:
106
90
  specification_version: 3
107
91
  summary: Facebook on Rails