facebook-login 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/facebook/client.rb +25 -15
  2. data/lib/facebook/login.rb +6 -6
  3. metadata +10 -57
@@ -4,37 +4,47 @@ module Facebook
4
4
  # http://www.facebook.com/developers/apps.php?app_id=APPID
5
5
  class Client
6
6
  class << self
7
- attr_accessor :app_id, :secret
7
+ attr_reader :last_oauth_client
8
8
  end
9
-
10
- def self.oauth_client(app_id = nil, secret = nil)
11
- self.app_id, self.secret = app_id, secret unless app_id.nil?
12
- OAuth2::Client.new(self.app_id, self.secret, :site => 'https://graph.facebook.com')
9
+
10
+ def self.oauth_client(app_id, secret, &block)
11
+ @last_oauth_client = OAuth2::Client.new app_id, secret,
12
+ :site => 'https://graph.facebook.com',
13
+ :token_url => '/oauth/access_token',
14
+ &block
15
+ end
16
+
17
+ def self.access_token_options
18
+ {:mode => :query, :param_name => 'access_token'}
19
+ end
20
+
21
+ def self.restore_access_token(token_string)
22
+ OAuth2::AccessToken.new(last_oauth_client, token_string, access_token_options)
13
23
  end
14
-
15
- def initialize(app_id, secret, options = {})
16
- @oauth = self.class.oauth_client(app_id, secret)
24
+
25
+ attr_reader :oauth
26
+
27
+ def initialize(app_id, secret, options = {}, &block)
28
+ @oauth = self.class.oauth_client(app_id, secret, &block)
17
29
  @default_params = { :scope => options[:permissions], :display => options[:display] }
18
30
  @user_fields = Array(options[:user_fields])
19
31
  end
20
32
 
21
33
  # params: redirect_uri, scope, display
22
34
  def authorize_url(params = {})
23
- @oauth.web_server.authorize_url(@default_params.merge(params))
35
+ @oauth.auth_code.authorize_url(@default_params.merge(params))
24
36
  end
25
37
 
26
38
  def get_access_token(code, redirect_uri)
27
- @oauth.web_server.get_access_token(code, :redirect_uri => redirect_uri)
28
- end
29
-
30
- def restore_access_token(token_string)
31
- OAuth2::AccessToken.new(@oauth, token_string)
39
+ token = @oauth.auth_code.get_token(code, :redirect_uri => redirect_uri, :parse => :query)
40
+ token.options.update(self.class.access_token_options)
41
+ token
32
42
  end
33
43
 
34
44
  def login_handler(options = {})
35
45
  Login.new(self, options)
36
46
  end
37
-
47
+
38
48
  def get_user_info(access_token, path)
39
49
  access_token.get(path, :fields => @user_fields.join(','))
40
50
  end
@@ -1,5 +1,4 @@
1
1
  require 'facebook/client'
2
- require 'yajl'
3
2
  require 'rack/request'
4
3
  require 'addressable/uri'
5
4
 
@@ -28,11 +27,11 @@ module Facebook
28
27
 
29
28
  module Helpers
30
29
  def facebook_client
31
- OAuth2::AccessToken.new(facebook_oauth, session[:facebook_access_token])
30
+ Facebook::Client.restore_access_token session[:facebook_access_token]
32
31
  end
33
32
 
34
33
  def facebook_oauth
35
- Facebook::Client.oauth_client
34
+ Facebook::Client.last_oauth_client
36
35
  end
37
36
 
38
37
  def facebook_user
@@ -71,13 +70,14 @@ module Facebook
71
70
  private
72
71
 
73
72
  def handle_facebook_authorization(code, callback_url, request)
73
+ require 'json' unless defined? ::JSON
74
74
  access_token = @client.get_access_token(code, callback_url)
75
75
  user_info = @client.get_user_info(access_token, '/me')
76
-
76
+
77
77
  request.session[:facebook_access_token] = access_token.token
78
- request.session[:facebook_user] = Yajl::Parser.parse(user_info)
78
+ request.session[:facebook_user] = JSON.parse(user_info.body)
79
79
  redirect_to_return_path(request)
80
- end
80
+ end
81
81
 
82
82
  def handle_error(error, request)
83
83
  request.session[:facebook_error] = error
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook-login
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 3
10
- version: 0.2.3
4
+ prerelease:
5
+ version: 0.3.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - "Mislav Marohni\xC4\x87"
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-09-25 00:00:00 -07:00
19
- default_executable:
13
+ date: 2011-09-25 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: oauth2
@@ -26,76 +20,42 @@ dependencies:
26
20
  requirements:
27
21
  - - ">="
28
22
  - !ruby/object:Gem::Version
29
- hash: 19
30
- segments:
31
- - 0
32
- - 0
33
- - 6
34
23
  version: 0.0.6
35
24
  type: :runtime
36
25
  version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: yajl-ruby
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 9
46
- segments:
47
- - 0
48
- - 7
49
- - 5
50
- version: 0.7.5
51
- type: :runtime
52
- version_requirements: *id002
53
26
  - !ruby/object:Gem::Dependency
54
27
  name: rack
55
28
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
57
30
  none: false
58
31
  requirements:
59
32
  - - ~>
60
33
  - !ruby/object:Gem::Version
61
- hash: 11
62
- segments:
63
- - 1
64
- - 2
65
34
  version: "1.2"
66
35
  type: :runtime
67
- version_requirements: *id003
36
+ version_requirements: *id002
68
37
  - !ruby/object:Gem::Dependency
69
38
  name: addressable
70
39
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
40
+ requirement: &id003 !ruby/object:Gem::Requirement
72
41
  none: false
73
42
  requirements:
74
43
  - - ~>
75
44
  - !ruby/object:Gem::Version
76
- hash: 1
77
- segments:
78
- - 2
79
- - 1
80
45
  version: "2.1"
81
46
  type: :runtime
82
- version_requirements: *id004
47
+ version_requirements: *id003
83
48
  - !ruby/object:Gem::Dependency
84
49
  name: hashie
85
50
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
87
52
  none: false
88
53
  requirements:
89
54
  - - ">="
90
55
  - !ruby/object:Gem::Version
91
- hash: 23
92
- segments:
93
- - 0
94
- - 2
95
- - 0
96
56
  version: 0.2.0
97
57
  type: :runtime
98
- version_requirements: *id005
58
+ version_requirements: *id004
99
59
  description: Easy integration with Facebook Graph for your application
100
60
  email: mislav.marohnic@gmail.com
101
61
  executables: []
@@ -107,7 +67,6 @@ extra_rdoc_files: []
107
67
  files:
108
68
  - lib/facebook/client.rb
109
69
  - lib/facebook/login.rb
110
- has_rdoc: false
111
70
  homepage: http://github.com/mislav/facebook
112
71
  licenses: []
113
72
 
@@ -121,23 +80,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
80
  requirements:
122
81
  - - ">="
123
82
  - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
83
  version: "0"
128
84
  required_rubygems_version: !ruby/object:Gem::Requirement
129
85
  none: false
130
86
  requirements:
131
87
  - - ">="
132
88
  - !ruby/object:Gem::Version
133
- hash: 3
134
- segments:
135
- - 0
136
89
  version: "0"
137
90
  requirements: []
138
91
 
139
92
  rubyforge_project:
140
- rubygems_version: 1.3.7
93
+ rubygems_version: 1.8.8
141
94
  signing_key:
142
95
  specification_version: 3
143
96
  summary: REST library + Rack middleware for the Facebook Graph API