buddy 2.0.9 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/buddy/middleware.rb +3 -1
- data/lib/buddy/session/app.rb +23 -0
- data/lib/buddy/session/base.rb +37 -0
- data/lib/buddy/session/user.rb +70 -0
- data/lib/buddy/session.rb +7 -87
- data/lib/buddy/version.rb +1 -1
- data/lib/buddy.rb +2 -1
- metadata +5 -2
data/lib/buddy/middleware.rb
CHANGED
@@ -62,7 +62,9 @@ module Buddy
|
|
62
62
|
end
|
63
63
|
|
64
64
|
signed_params = Yajl::Parser.new.parse(base64_url_decode(signed_params))
|
65
|
-
|
65
|
+
|
66
|
+
env['rack.request.form_hash'] ? env['rack.request.form_hash'].merge!({'fb' => signed_params}) : env['rack.request.form_hash'] = {'fb' => signed_params}
|
67
|
+
|
66
68
|
set_session(signed_params)
|
67
69
|
elsif @request.cookies["fbs_#{Buddy.current_config['app_id']}"]
|
68
70
|
payload = @request.cookies["fbs_#{Buddy.current_config['app_id']}"].chomp('"')
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Buddy
|
2
|
+
module Session
|
3
|
+
class App < Base
|
4
|
+
class << self
|
5
|
+
def current
|
6
|
+
Thread.current['facebook_app_session']
|
7
|
+
end
|
8
|
+
|
9
|
+
def current=(session)
|
10
|
+
Thread.current['facebook_app_session'] = session
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def access_token
|
15
|
+
@access_token ||= Buddy::Service::GraphApiClient.get('/oauth/access_token', :query => {
|
16
|
+
:client_id => self.class.app_id,
|
17
|
+
:client_secret => self.class.secret_key,
|
18
|
+
:grant_type => 'client_credentials'
|
19
|
+
}).body.split('=').last
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Buddy
|
2
|
+
module Session
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
def create(app_id = nil, secret_key = nil)
|
6
|
+
app_id ||= self.app_id
|
7
|
+
secret_key ||= self.secret_key
|
8
|
+
raise ArgumentError unless !app_id.nil? && !secret_key.nil?
|
9
|
+
new(app_id, secret_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def app_id
|
13
|
+
Buddy.config["app_id"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def secret_key
|
17
|
+
Buddy.config["secret"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(api_method, params = {}, options = {})
|
22
|
+
params.merge!(:uids => uid, :access_token => access_token)
|
23
|
+
Buddy::Service.call(api_method, params, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(resource, params = {})
|
27
|
+
params.merge!(:access_token => access_token) unless params[:access_token]
|
28
|
+
Buddy::Service.get(resource, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def post(resource, params = {})
|
32
|
+
params.merge!(:access_token => access_token) unless params[:access_token]
|
33
|
+
Buddy::Service.post(resource, params)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Buddy
|
2
|
+
module Session
|
3
|
+
class User < Base
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def app_id
|
7
|
+
Buddy.current_config["app_id"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def secret_key
|
11
|
+
Buddy.current_config["secret"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def current
|
15
|
+
Thread.current['facebook_session']
|
16
|
+
end
|
17
|
+
|
18
|
+
def current=(session)
|
19
|
+
Thread.current['facebook_session'] = session
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def install_url(options = {})
|
24
|
+
"https://www.facebook.com/dialog/oauth?client_id=#{Buddy.current_config['app_id']}&redirect_uri=#{options[:next]}#{"&scope="+Buddy.current_config['perms'] if Buddy.current_config['perms']}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(app_id, secret_key)
|
28
|
+
@app_id = app_id
|
29
|
+
@secret_key = secret_key
|
30
|
+
@uid = nil
|
31
|
+
@access_token = nil
|
32
|
+
@expires = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def secure!(uid, access_token, expires)
|
36
|
+
@uid = uid
|
37
|
+
@access_token = access_token
|
38
|
+
@expires = expires
|
39
|
+
end
|
40
|
+
|
41
|
+
def infinite?
|
42
|
+
@expires == 0
|
43
|
+
end
|
44
|
+
|
45
|
+
def expired?
|
46
|
+
@expires.nil? || (!infinite? && Time.at(@expires) <= Time.now)
|
47
|
+
end
|
48
|
+
|
49
|
+
def secured?
|
50
|
+
!@uid.nil? && !@access_token.nil? && !expired?
|
51
|
+
end
|
52
|
+
|
53
|
+
def user
|
54
|
+
@user ||= Buddy::User.new(@uid, self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def uid
|
58
|
+
@uid
|
59
|
+
end
|
60
|
+
|
61
|
+
def access_token
|
62
|
+
@access_token
|
63
|
+
end
|
64
|
+
|
65
|
+
def expires
|
66
|
+
@expires
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/buddy/session.rb
CHANGED
@@ -1,91 +1,11 @@
|
|
1
|
+
require 'buddy/session/base'
|
2
|
+
require 'buddy/session/app'
|
3
|
+
require 'buddy/session/user'
|
4
|
+
|
1
5
|
module Buddy
|
2
|
-
|
6
|
+
module Session
|
3
7
|
def self.create(app_id = nil, secret_key = nil)
|
4
|
-
app_id
|
5
|
-
secret_key ||= self.secret_key
|
6
|
-
raise ArgumentError unless !app_id.nil? && !secret_key.nil?
|
7
|
-
new(app_id, secret_key)
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.app_id
|
11
|
-
Buddy.current_config["app_id"]
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.api_key
|
15
|
-
Buddy.current_config["api_key"]
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.secret_key
|
19
|
-
Buddy.current_config["secret"]
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.current
|
23
|
-
Thread.current['facebook_session']
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.current=(session)
|
27
|
-
Thread.current['facebook_session'] = session
|
28
|
-
end
|
29
|
-
|
30
|
-
def call(api_method, params = {}, options = {})
|
31
|
-
params.merge!(:uids => uid, :access_token => access_token)
|
32
|
-
Buddy::Service.call(api_method, params, options)
|
33
|
-
end
|
34
|
-
|
35
|
-
def get(resource, params = {})
|
36
|
-
params.merge!(:access_token => access_token) unless params[:access_token]
|
37
|
-
Buddy::Service.get(resource, params)
|
38
|
-
end
|
39
|
-
|
40
|
-
def post(resource, params = {})
|
41
|
-
params.merge!(:access_token => access_token) unless params[:access_token]
|
42
|
-
Buddy::Service.post(resource, params)
|
43
|
-
end
|
44
|
-
|
45
|
-
def install_url(options = {})
|
46
|
-
"https://www.facebook.com/dialog/oauth?client_id=#{Buddy.current_config['app_id']}&redirect_uri=#{options[:next]}#{"&scope="+Buddy.current_config['perms'] if Buddy.current_config['perms']}"
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize(app_id, secret_key)
|
50
|
-
@app_id = app_id
|
51
|
-
@secret_key = secret_key
|
52
|
-
@uid = nil
|
53
|
-
@access_token = nil
|
54
|
-
@expires = nil
|
55
|
-
end
|
56
|
-
|
57
|
-
def secure!(uid, access_token, expires)
|
58
|
-
@uid = uid
|
59
|
-
@access_token = access_token
|
60
|
-
@expires = expires
|
61
|
-
end
|
62
|
-
|
63
|
-
def infinite?
|
64
|
-
@expires == 0
|
65
|
-
end
|
66
|
-
|
67
|
-
def expired?
|
68
|
-
@expires.nil? || (!infinite? && Time.at(@expires) <= Time.now)
|
69
|
-
end
|
70
|
-
|
71
|
-
def secured?
|
72
|
-
!@uid.nil? && !@access_token.nil? && !expired?
|
73
|
-
end
|
74
|
-
|
75
|
-
def user
|
76
|
-
@user ||= Buddy::User.new(@uid, self)
|
77
|
-
end
|
78
|
-
|
79
|
-
def uid
|
80
|
-
@uid
|
81
|
-
end
|
82
|
-
|
83
|
-
def access_token
|
84
|
-
@access_token
|
85
|
-
end
|
86
|
-
|
87
|
-
def expires
|
88
|
-
@expires
|
8
|
+
Buddy::Session::User.create(app_id, secret_key)
|
89
9
|
end
|
90
10
|
end
|
91
|
-
end
|
11
|
+
end
|
data/lib/buddy/version.rb
CHANGED
data/lib/buddy.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Facebook library focusing on getting the work done.
|
15
15
|
email:
|
@@ -31,6 +31,9 @@ files:
|
|
31
31
|
- lib/buddy/railtie.rb
|
32
32
|
- lib/buddy/service.rb
|
33
33
|
- lib/buddy/session.rb
|
34
|
+
- lib/buddy/session/app.rb
|
35
|
+
- lib/buddy/session/base.rb
|
36
|
+
- lib/buddy/session/user.rb
|
34
37
|
- lib/buddy/user.rb
|
35
38
|
- lib/buddy/version.rb
|
36
39
|
- lib/generators/buddy_config/USAGE
|