buddy 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/buddy.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  Gem::Specification.new do |s|
21
- s.add_dependency(%q<mini_fb>, [">= 0.2.2"])
22
- s.add_dependency(%q<yajl-ruby>, [">= 0"])
23
- s.add_dependency(%q<httparty>, [">= 0"])
21
+ s.add_runtime_dependency('mini_fb', '>= 0.2.2')
22
+ s.add_runtime_dependency('yajl-ruby', '>= 0')
23
+ s.add_runtime_dependency('httparty', '>= 0')
24
24
  end
25
25
  end
@@ -50,10 +50,10 @@ module Buddy
50
50
  def call(env)
51
51
  return @app.call(env) unless @condition.nil? || @condition.call(env)
52
52
 
53
- request = Rack::Request.new(env)
53
+ @request = Rack::Request.new(env)
54
54
 
55
55
  signed_request = env['HTTP_X_SIGNED_REQUEST'].split(',').first if env['HTTP_X_SIGNED_REQUEST']
56
- signed_request = request.params["signed_request"] unless signed_request
56
+ signed_request = @request.params["signed_request"] unless signed_request
57
57
  if signed_request
58
58
  signature, signed_params = signed_request.split('.')
59
59
 
@@ -62,7 +62,12 @@ module Buddy
62
62
  end
63
63
 
64
64
  signed_params = Yajl::Parser.new.parse(base64_url_decode(signed_params))
65
- request.params[:fb] = signed_params
65
+ @request.params[:fb] = signed_params
66
+ set_session(signed_params)
67
+ elsif @request.cookies["fbs_#{Buddy.current_config['app_id']}"]
68
+ payload = @request.cookies["fbs_#{Buddy.current_config['app_id']}"].chomp('"')
69
+ payload.sub!('"', '') if payload.start_with?('"')
70
+ set_session(payload)
66
71
  end
67
72
 
68
73
  @app.call(env)
@@ -85,6 +90,15 @@ module Buddy
85
90
  str = str + "=" * (6 - str.size % 6) unless str.size % 6 == 0
86
91
  return Base64.decode64(str.tr("-_", "+/"))
87
92
  end
93
+
94
+ def set_session(payload)
95
+ uid = payload['user_id'] || payload['uid']
96
+ access_token = payload['oauth_token'] || payload['access_token']
97
+ expires = payload['expires']
98
+
99
+ @request.session['facebook_session'] = Buddy::Session.create(Buddy.current_config['app_id'], Buddy.current_config['secret'])
100
+ @request.session['facebook_session'].secure!(uid.to_i, access_token, expires)
101
+ end
88
102
  end
89
103
  end
90
104
  end
@@ -21,7 +21,7 @@ module Buddy
21
21
 
22
22
  private
23
23
  def facebook_session
24
- @facebook_session
24
+ session[:facebook_session]
25
25
  end
26
26
 
27
27
  def request_comes_from_facebook?
@@ -29,7 +29,7 @@ module Buddy
29
29
  end
30
30
 
31
31
  def application_is_installed?
32
- !params[:fb][:oauth_token].blank?
32
+ facebook_session && facebook_session.secured?
33
33
  end
34
34
 
35
35
  def request_is_facebook_canvas?
@@ -49,22 +49,9 @@ module Buddy
49
49
  Buddy::Session.create(Buddy.current_config['app_id'], Buddy.current_config['secret'])
50
50
  end
51
51
 
52
- def create_facebook_session
53
- @facebook_session = new_facebook_session
54
- @facebook_session.secure!(params[:fb][:user_id], params[:fb][:oauth_token], params[:fb][:expires])
55
- @facebook_session.secured?
56
- end
57
-
58
52
  def set_facebook_session
59
- session_set = !@facebook_session.blank? && @facebook_session.secured?
60
- unless session_set
61
- session_set = create_facebook_session
62
- session[:facebook_session] = @facebook_session if session_set
63
- end
64
- if session_set
65
- Session.current = @facebook_session
66
- end
67
- return session_set
53
+ Session.current = facebook_session
54
+ return facebook_session.secured?
68
55
  end
69
56
 
70
57
  def ensure_facebook_session
data/lib/buddy/service.rb CHANGED
@@ -23,7 +23,7 @@ module Buddy
23
23
  time = Benchmark.realtime do
24
24
  result = GraphApiClient.send(method, resource, :query => params).parsed_response
25
25
  end
26
- Buddy.logger.info("GraphAPI: #{method} #{resource} - #{time}")
26
+ Buddy.logger.info("GraphAPI: #{method} #{resource} - #{time}") if Buddy.config['logging_enabled']
27
27
 
28
28
  raise OAuthException.new(result["error"]["message"]) if result["error"]
29
29
  result
@@ -70,7 +70,7 @@ module Buddy
70
70
  time = Benchmark.realtime do
71
71
  result = fun.call
72
72
  end
73
- Buddy.logger.info("RestAPI: #{api_method} (#{params.inspect}) - #{time}")
73
+ Buddy.logger.info("RestAPI: #{api_method} (#{params.inspect}) - #{time}") if Buddy.config['logging_enabled']
74
74
  result
75
75
  end
76
76
  end
data/lib/buddy/session.rb CHANGED
@@ -43,7 +43,7 @@ module Buddy
43
43
  end
44
44
 
45
45
  def install_url(options = {})
46
- "http://www.facebook.com/connect/uiserver.php?app_id=#{Buddy.current_config['app_id']}&next=#{options[:next]}&display=page&canvas=1&legacy_return=1&method=permissions.request#{"&perms="+Buddy.current_config['perms'] if Buddy.current_config['perms']}"
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
47
  end
48
48
 
49
49
  def initialize(app_id, secret_key)
data/lib/buddy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Buddy
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/buddy.rb CHANGED
@@ -21,37 +21,22 @@ module Buddy
21
21
  def load_configuration(yaml)
22
22
  return false unless File.exist?(yaml)
23
23
  @buddy_config = YAML.load(ERB.new(File.read(yaml)).result)[::Rails.env]
24
- self.current_config = buddy_config['default']
25
24
 
26
- buddy_config
27
- end
28
-
29
- def buddy_config
30
- @buddy_config
31
- end
32
-
33
- def set_asset_host_to_callback_url
34
- buddy_config[app]['set_asset_host_to_callback_url']
35
- end
36
-
37
- def timeout(app = 'default')
38
- buddy_config[app]['timeout']
39
- end
40
-
41
- def use_application(api_key)
42
- buddy_config.each do |c|
43
- if c[1]["api_key"] == api_key
44
- return self.current_config = c[1]
45
- end
25
+ unless self.config['default'].nil?
26
+ ActiveSupport::Deprecation.warn('Support for multiple apps has been removed and your config format is deprecated. Please remove your app keys (or just the "default" key)')
27
+ self.config = self.config['default']
46
28
  end
29
+ self.config
47
30
  end
48
31
 
49
- def current_config
50
- Thread.current['current_buddy_config']
32
+ def config
33
+ @buddy_config
51
34
  end
35
+ alias :buddy_config :config
36
+ alias :current_config :config
52
37
 
53
- def current_config=(config)
54
- Thread.current['current_buddy_config'] = config
38
+ def config=(c)
39
+ @buddy_config = c
55
40
  end
56
41
  end
57
42
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buddy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
- - 1
8
- - 1
7
+ - 2
9
8
  - 0
10
- version: 1.1.0
9
+ - 0
10
+ version: 2.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ole Riesenberg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-07 00:00:00 +01:00
18
+ date: 2011-07-01 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21