fb_graph 1.7.0.alpha → 1.7.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,10 +10,7 @@ begin
10
10
  gem.email = 'nov@matake.jp'
11
11
  gem.homepage = 'http://github.com/nov/fb_graph'
12
12
  gem.authors = ['nov matake']
13
- gem.add_dependency 'json', '>= 1.4.3'
14
- gem.add_dependency 'activesupport', '>= 2.3'
15
- gem.add_dependency 'restclient_with_cert'
16
- gem.add_dependency 'oauth2', '>= 0.1.0'
13
+ gem.add_dependency 'rack-oauth2', '>= 0.6.5'
17
14
  gem.add_development_dependency 'rspec', '~> 1.3'
18
15
  gem.add_development_dependency 'rcov'
19
16
  gem.add_development_dependency 'fakeweb', '>= 1.3.0'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.8
1
+ 1.7.0.alpha2
data/fb_graph.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fb_graph}
8
- s.version = "1.7.0.alpha"
8
+ s.version = "1.7.0.alpha2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["nov matake"]
@@ -30,12 +30,7 @@ module FbGraph
30
30
  def get_access_token(secret = nil)
31
31
  self.secret ||= secret
32
32
  auth = Auth.new(self.identifier, self.secret)
33
- response_string = auth.client.request(:post, auth.client.access_token_url, {
34
- :client_id => self.identifier,
35
- :client_secret => self.secret,
36
- :type => 'client_cred'
37
- })
38
- self.access_token = response_string.split('=').last
33
+ self.access_token = auth.client.access_token!
39
34
  end
40
35
 
41
36
  end
@@ -7,7 +7,7 @@ module FbGraph
7
7
  class Cookie
8
8
  def self.parse(client, cookie)
9
9
  fb_cookie_string = if cookie.is_a?(Hash)
10
- cookie["fbs_#{client.id}"]
10
+ cookie["fbs_#{client.identifier}"]
11
11
  else
12
12
  cookie
13
13
  end
data/lib/fb_graph/auth.rb CHANGED
@@ -5,9 +5,13 @@ module FbGraph
5
5
  attr_accessor :client, :access_token, :user, :data
6
6
 
7
7
  def initialize(client_id, client_secret, options = {})
8
- @client = OAuth2::Client.new(client_id, client_secret, options.merge(
9
- :site => ROOT_URL
10
- ))
8
+ @client = Rack::OAuth2::Client.new(
9
+ :identifier => client_id,
10
+ :secret => client_secret,
11
+ :host => URI.parse(ROOT_URL).host,
12
+ :authorization_endpoint => '/oauth/authorize',
13
+ :token_endpoint => '/oauth/access_token'
14
+ )
11
15
  if options[:cookie]
12
16
  from_cookie options[:cookie]
13
17
  elsif options[:signed_request]
@@ -22,7 +26,7 @@ module FbGraph
22
26
  def authorize_uri(canvas_uri, options = {})
23
27
  endpoint = URI.parse SignedRequest::OAUTH_DIALOG_ENDPOINT
24
28
  params = options.merge(
25
- :client_id => self.client.id,
29
+ :client_id => self.client.identifier,
26
30
  :redirect_uri => canvas_uri
27
31
  )
28
32
  params[:scope] = Array(params[:scope]).join(',') if params[:scope].present?
@@ -54,11 +58,9 @@ module FbGraph
54
58
  expires_in = unless data[:expires].zero?
55
59
  data[:expires] - Time.now.to_i
56
60
  end
57
- OAuth2::AccessToken.new(
58
- self.client,
59
- data[:oauth_token] || data[:access_token],
60
- nil,
61
- expires_in
61
+ Rack::OAuth2::AccessToken::Legacy.new(
62
+ :access_token => data[:oauth_token] || data[:access_token],
63
+ :expires_in => expires_in
62
64
  )
63
65
  end
64
66
  end
data/lib/fb_graph/node.rb CHANGED
@@ -75,8 +75,8 @@ module FbGraph
75
75
  def stringfy_params(params)
76
76
  _params_ = params.dup
77
77
  _params_[:access_token] ||= self.access_token
78
- if _params_[:access_token].is_a?(OAuth2::AccessToken)
79
- _params_[:access_token] = _params_[:access_token].token
78
+ if _params_[:access_token].is_a?(Rack::OAuth2::AccessToken::Legacy)
79
+ _params_[:access_token] = _params_[:access_token].access_token
80
80
  end
81
81
  _params_.each do |key, value|
82
82
  if value.present? && ![Symbol, String, Numeric, IO].any? { |klass| value.is_a? klass }
data/lib/fb_graph.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  require 'rubygems'
2
- require 'json'
3
- require 'restclient_with_cert'
4
- require 'oauth2'
5
- require 'active_support/all'
2
+ require 'rack/oauth2'
6
3
 
7
4
  module FbGraph
8
5
  ROOT_URL = "https://graph.facebook.com"
@@ -29,7 +29,8 @@ describe FbGraph::Application, '.get_access_token' do
29
29
  it 'should POST oauth/token' do
30
30
  @app.access_token.should be_nil
31
31
  @app.get_access_token
32
- @app.access_token.should == 'token'
32
+ @app.access_token.should be_instance_of(Rack::OAuth2::AccessToken::Legacy)
33
+ @app.access_token.access_token.should == 'token'
33
34
  end
34
35
 
35
36
  after do
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
2
 
3
3
  describe FbGraph::Auth::Cookie, '.parse' do
4
4
  before do
5
- @client = OAuth2::Client.new('client_id', 'client_secret')
5
+ @client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
6
6
  @cookie = {
7
7
  'fbs_client_id' => "access_token=t&expires=0&secret=s&session_key=k&sig=f4bae8ec88ba11440e3bdcc1bcf78317&uid=12345"
8
8
  }
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
2
 
3
3
  describe FbGraph::Auth::SignedRequest, '.parse' do
4
4
  before do
5
- @client = OAuth2::Client.new('client_id', 'client_secret')
5
+ @client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
6
6
  @signed_request = "LqsgnfcsRdfjOgyW6ZuSLpGBVsxUBegEqai4EcrWS0A=.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjAsImlzc3VlZF9hdCI6MTI5ODc4MzczOSwib2F1dGhfdG9rZW4iOiIxMzQxNDU2NDMyOTQzMjJ8MmI4YTZmOTc1NTJjNmRjZWQyMDU4MTBiLTU3OTYxMjI3NnxGS1o0akdKZ0JwN2k3bFlrOVhhUk1QZ3lhNnMiLCJ1c2VyIjp7ImNvdW50cnkiOiJqcCIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fSwidXNlcl9pZCI6IjU3OTYxMjI3NiJ9"
7
7
  end
8
8
 
@@ -1,10 +1,10 @@
1
1
  require File.join(File.dirname(__FILE__), '../spec_helper')
2
2
 
3
3
  describe FbGraph::Auth, '.new' do
4
- it 'should setup OAuth2::Client' do
4
+ it 'should setup Rack::OAuth2::Client' do
5
5
  auth = FbGraph::Auth.new('client_id', 'client_secret')
6
- auth.client.should be_a(OAuth2::Client)
7
- auth.client.id.should == 'client_id'
6
+ auth.client.should be_a(Rack::OAuth2::Client)
7
+ auth.client.identifier.should == 'client_id'
8
8
  auth.client.secret.should == 'client_secret'
9
9
  end
10
10
 
@@ -38,11 +38,10 @@ describe FbGraph::Auth, '#from_cookie' do
38
38
  @auth.access_token.should be_nil
39
39
  @auth.user.should be_nil
40
40
  @auth.from_cookie(@cookie)
41
- @auth.access_token.token.should == 't'
42
- @auth.access_token.expires_in.should be_close @expires_at - Time.now, 1
43
- @auth.access_token.expires_at.should be_close @expires_at, 1
44
- @auth.user.identifier.should == '12345'
45
- @auth.user.access_token.token.should == 't'
41
+ @auth.access_token.access_token.should == 't'
42
+ @auth.access_token.expires_in.should be_close @expires_at - Time.now, 1
43
+ @auth.user.identifier.should == '12345'
44
+ @auth.user.access_token.access_token.should == 't'
46
45
  end
47
46
 
48
47
  context 'when invalid cookie given' do
@@ -64,9 +63,9 @@ describe FbGraph::Auth, '#from_signed_request' do
64
63
  @auth.access_token.should be_nil
65
64
  @auth.user.should be_nil
66
65
  @auth.from_signed_request(@signed_request)
67
- @auth.access_token.token.should == '134145643294322|2b8a6f97552c6dced205810b-579612276|FKZ4jGJgBp7i7lYk9XaRMPgya6s'
68
- @auth.user.identifier.should == '579612276'
69
- @auth.user.access_token.token.should == '134145643294322|2b8a6f97552c6dced205810b-579612276|FKZ4jGJgBp7i7lYk9XaRMPgya6s'
66
+ @auth.access_token.access_token.should == '134145643294322|2b8a6f97552c6dced205810b-579612276|FKZ4jGJgBp7i7lYk9XaRMPgya6s'
67
+ @auth.user.identifier.should == '579612276'
68
+ @auth.user.access_token.access_token.should == '134145643294322|2b8a6f97552c6dced205810b-579612276|FKZ4jGJgBp7i7lYk9XaRMPgya6s'
70
69
  @auth.data.should include(
71
70
  "expires"=>0,
72
71
  "algorithm"=>"HMAC-SHA256",
@@ -14,24 +14,24 @@ end
14
14
 
15
15
  describe FbGraph::Node, '#stringfy_params' do
16
16
  it 'should make all values to JSON' do
17
- client = OAuth2::Client.new('client_id', 'client_secret')
17
+ client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
18
18
  node = FbGraph::Node.new('identifier')
19
19
  params = node.send :stringfy_params, {:hash => {:a => :b}, :array => [:a, :b]}
20
20
  params[:hash].should == '{"a":"b"}'
21
21
  params[:array].should == '["a","b"]'
22
22
  end
23
23
 
24
- it 'should support OAuth2::AccessToken as self.access_token' do
25
- client = OAuth2::Client.new('client_id', 'client_secret')
26
- node = FbGraph::Node.new('identifier', :access_token => OAuth2::AccessToken.new(client, 'token', 'secret'))
24
+ it 'should support Rack::OAuth2::AccessToken as self.access_token' do
25
+ client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
26
+ node = FbGraph::Node.new('identifier', :access_token => Rack::OAuth2::AccessToken::Legacy.new(:access_token => 'token'))
27
27
  params = node.send :stringfy_params, {}
28
28
  params[:access_token].should == 'token'
29
29
  end
30
30
 
31
31
  it 'should support OAuth2::AccessToken as options[:access_token]' do
32
- client = OAuth2::Client.new('client_id', 'client_secret')
32
+ client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
33
33
  node = FbGraph::Node.new('identifier')
34
- params = node.send :stringfy_params, {:access_token => OAuth2::AccessToken.new(client, 'token', 'secret')}
34
+ params = node.send :stringfy_params, {:access_token => Rack::OAuth2::AccessToken::Legacy.new(:access_token => 'token')}
35
35
  params[:access_token].should == 'token'
36
36
  end
37
37
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1851332202
4
+ hash: -3702664440
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
9
  - 0
10
10
  - alpha
11
- version: 1.7.0.alpha
11
+ - 2
12
+ version: 1.7.0.alpha2
12
13
  platform: ruby
13
14
  authors:
14
15
  - nov matake