fbgraph 0.1.6.1 → 0.1.6.3

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/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('fbgraph', '0.1.6.1') do |p|
5
+ Echoe.new('fbgraph', '0.1.6.3') do |p|
6
6
  p.description = "A Gem for Facebook Open Graph API"
7
7
  p.url = "http://github.com/nsanta/fbgraph"
8
8
  p.author = "Nicolas Santa"
data/fbgraph.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{fbgraph}
5
- s.version = "0.1.6.1"
5
+ s.version = "0.1.6.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Nicolas Santa"]
9
9
  s.cert_chain = ["/home/nicolas/certs/gem-public_cert.pem"]
10
- s.date = %q{2010-09-07}
10
+ s.date = %q{2010-09-15}
11
11
  s.description = %q{A Gem for Facebook Open Graph API}
12
12
  s.email = %q{nicolas55ar@gmail.com}
13
13
  s.extra_rdoc_files = ["README", "README.textile", "TODO.list", "lib/fbgraph.rb", "lib/fbgraph/authorization.rb", "lib/fbgraph/base.rb", "lib/fbgraph/canvas.rb", "lib/fbgraph/client.rb", "lib/fbgraph/realtime.rb", "lib/fbgraph/search.rb", "lib/fbgraph/selection.rb"]
@@ -33,22 +33,5 @@ module FBGraph
33
33
  JSON.parse(tokens).map { |hash| hash['access_token'] if hash}
34
34
  end
35
35
 
36
- def upgrade_session(key)
37
- token = upgrade_session_keys(key).first
38
- @client.access_token = token['access_token']
39
- token
40
- end
41
-
42
-
43
- def exchange_sessions(*keys)
44
- tokens = @client.oauth_client.request(:get, '/oauth/exchange_sessions', {
45
- :client_id => @client.client_id,
46
- :client_secret => @client.secret_id,
47
- :type => 'client_cred',
48
- :sessions => keys.flatten.join(',')
49
- })
50
- JSON.parse(tokens)
51
- end
52
-
53
36
  end
54
37
  end
data/lib/fbgraph/base.rb CHANGED
@@ -38,9 +38,10 @@ module FBGraph
38
38
  end
39
39
 
40
40
  def info!(parsed = true)
41
+ @params.merge!(:access_token => @client.access_token) unless @client.access_token.nil?
41
42
  if @objects.is_a? Array
42
43
  @params.merge!({:ids => @objects.join(',')})
43
- path = build_open_graph_path(nil,nil, @params)
44
+ path = build_open_graph_path(nil,nil, params)
44
45
  elsif @objects.is_a? String
45
46
  path = build_open_graph_path(@objects , @connection_type, @params)
46
47
  end
@@ -53,16 +54,21 @@ module FBGraph
53
54
 
54
55
  def publish!(data = {},parsed = true)
55
56
  @params.merge!(data)
57
+ params = @params.merge(:access_token => @client.access_token) if (@client.access_token)
56
58
  path = build_open_graph_path(@objects , @connection_type)
57
59
  puts "FBGRAPH [POST]: #{path}"
58
- result = @client.consumer[path].post(@params)
60
+ puts "PARAMS: #{params.to_a.map{|p| p.join('=')}.join('&')}"
61
+ result = @client.consumer[path].post(params)
59
62
  return parse_json(result, parsed)
60
63
  end
61
64
 
62
65
  def delete!(parsed = true)
63
66
  path = build_open_graph_path(@objects , nil)
67
+ params = @params.merge(:access_token => @client.access_token) if (@client.access_token)
68
+ params.merge!(:method => :delete)
64
69
  puts "FBGRAPH [DELETE]: #{path}"
65
- result = @client.consumer[path].post(@params.merge(:method => :delete))
70
+ puts "PARAMS: #{params.to_a.map{|p| p.join('=')}.join('&')}"
71
+ result = @client.consumer[path].post(params)
66
72
  return parse_json(result, parsed)
67
73
  end
68
74
 
@@ -80,12 +86,9 @@ module FBGraph
80
86
 
81
87
  def parse_json(result, parsed)
82
88
  return parsed ? Hashie::Mash.new(JSON.parse(result.body)) : result.body
83
- end
84
-
85
-
89
+ end
86
90
 
87
- def build_open_graph_path(objects,connection_type = nil , params = {})
88
- params.merge!(:access_token => @client.access_token)
91
+ def build_open_graph_path(objects, connection_type = nil , params = {})
89
92
  request = [objects , connection_type].compact.join('/')
90
93
  request += "?"+params.to_a.map{|p| p.join('=')}.join('&') unless params.empty?
91
94
  URI.encode(request)
@@ -8,6 +8,7 @@ module FBGraph
8
8
  @client_id, @secret_id = options[:client_id] || FBGraph.config[:client_id], options[:secret_id] || FBGraph.config[:secret_id]
9
9
  @facebook_uri = 'https://graph.facebook.com'
10
10
  @consumer = RestClient::Resource.new(@facebook_uri)
11
+ @access_token = options.fetch :token, nil
11
12
  @auth = OAuth2::AccessToken.new(oauth_client , @access_token)
12
13
  return true
13
14
  end
@@ -40,8 +40,9 @@ module FBGraph
40
40
 
41
41
  def picture
42
42
  uri = [@client.facebook_uri , build_open_graph_path(@objects , 'picture')].join('/')
43
- return uri unless @client.consumer
43
+ return uri if @client.access_token.nil?
44
44
  uri + '?access_token=' + @client.access_token
45
+
45
46
  end
46
47
 
47
48
  end
@@ -37,7 +37,7 @@ describe FBGraph do
37
37
  @token.should == @consumer.token
38
38
  end
39
39
  it 'should set the consumer' do
40
- @client.consumer.should == @consumer
40
+ @client.auth.should == @consumer
41
41
  end
42
42
  end
43
43
  end
@@ -9,7 +9,8 @@ describe FBGraph do
9
9
  @client = FBGraph::Client.new(:client_id => @client_id,
10
10
  :secret_id => @secret_id,
11
11
  :token => 'token')
12
- @base = FBGraph::Base.new(@client)
12
+ @base = FBGraph::Base.new(@client)
13
+
13
14
  end
14
15
 
15
16
  describe 'initialization' do
@@ -59,9 +60,9 @@ describe FBGraph do
59
60
  describe 'info!' do
60
61
  describe 'when object is an array' do
61
62
  it 'should request with the path "/?ids=1,2,3"' do
62
- uri = "/?ids=1,2,3"
63
+ uri = "?access_token=token&ids=1,2,3"
63
64
  @base.find([1,2,3])
64
- @client.consumer.stub!(:get).with(uri).and_return('')
65
+ expect_consumer(uri)
65
66
  @base.info!(false)
66
67
  end
67
68
  end
@@ -69,34 +70,34 @@ describe FBGraph do
69
70
  describe 'when object is a string' do
70
71
 
71
72
  it 'should request with the path "/123"' do
72
- uri = "/123"
73
- @base.find('123')
74
- @client.consumer.stub!(:get).with(uri).and_return('')
73
+ uri = "123?access_token=token"
74
+ @base.find('123')
75
+ expect_consumer(uri)
75
76
  @base.info!(false)
76
77
  end
77
78
 
78
79
  it "should parse the result by default" do
79
- uri = "/123"
80
+ uri = "123?access_token=token"
80
81
  @base.find('123')
81
- @client.consumer.stub!(:get).with(uri).and_return('{"me": [1, 2]}')
82
+ expect_consumer(uri, '{"me": [1, 2]}')
82
83
  @base.info!.me.should == [1, 2]
83
84
  end
84
85
 
85
86
  describe 'when a connection is passed' do
86
87
  it 'should request with the path "/123/home"' do
87
- uri = "/123/home"
88
+ uri = "123/home?access_token=token"
88
89
  @base.find('123').connection('home')
89
- @client.consumer.stub!(:get).with(uri).and_return('')
90
+ expect_consumer(uri)
90
91
  @base.info!(false)
91
92
  end
92
93
  end
93
94
 
94
95
  describe 'when params are passed' do
95
96
  it 'should request with the path "/123?fields=name,picture"' do
96
- uri = "/123?fields=name,picture"
97
+ uri = "123?fields=name,picture&access_token=token"
97
98
  @base.find('123')
98
99
  @base.params = {:fields => "name,picture"}
99
- @client.consumer.stub!(:get).with(uri).and_return('')
100
+ expect_consumer(uri)
100
101
  @base.info!(false)
101
102
  end
102
103
  end
@@ -106,30 +107,31 @@ describe FBGraph do
106
107
  describe 'publish!' do
107
108
  describe 'when is passed params before invocation' do
108
109
  it 'should request with the path "/123" and params {:extra => "extra" }' do
109
- uri = "/123"
110
+ uri = "123"
110
111
  @base.find('123')
111
112
  @base.params = {:extra => "extra" }
112
- @client.consumer.stub!(:post).with(uri , @base.params).and_return('')
113
+ #@client.consumer.stub!(:post).with(uri , @base.params).and_return('')
114
+ expect_consumer_post(uri, {:extra => "extra", :access_token => 'token'})
113
115
  @base.publish!({}, false)
114
116
  end
115
117
  end
116
118
  describe 'when is passed params on invocation' do
117
119
  it 'should request with the path "/123" and params {:extra => "extra" }' do
118
- uri = "/123"
120
+ uri = "123"
119
121
  @base.find('123')
120
- ps = {:extra => "extra" }
121
- @client.consumer.stub!(:post).with(uri , ps).and_return('')
122
- @base.publish!(ps , false)
122
+ ps = {:extra => "extra"}
123
+ expect_consumer_post(uri, {:extra => "extra", :access_token => 'token'})
124
+ @base.publish!(ps, false)
123
125
  end
124
126
  end
125
127
  end
126
128
 
127
129
  describe 'delete!' do
128
130
  it 'should request with the path "/123" and params {:extra => "extra" }' do
129
- uri = "/123"
131
+ uri = "123"
130
132
  @base.find('123')
131
133
  @base.params = {:extra => "extra" }
132
- @client.consumer.stub!(:delete).with(uri , @base.params).and_return('')
134
+ expect_consumer_post(uri, {:method => :delete, :extra => "extra", :access_token => 'token'})
133
135
  @base.delete!(false)
134
136
  end
135
137
  end
@@ -37,7 +37,7 @@ describe FBGraph do
37
37
  @client.access_token.should == @token
38
38
  end
39
39
  it 'should set the consumer client' do
40
- @client.consumer.class.should == OAuth2::AccessToken
40
+ @client.consumer.class.should == RestClient::Resource
41
41
  end
42
42
  end
43
43
  end
data/specs/spec_helper.rb CHANGED
@@ -1,3 +1,15 @@
1
1
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
2
  require 'rubygems'
3
3
  require 'fbgraph'
4
+
5
+ def expect_consumer(uri, result = '')
6
+ consumer = @client.consumer[uri]
7
+ consumer.stub!(:get).and_return(Struct.new(:body).new(result))
8
+ @client.consumer.stub!(:[]).with(uri).and_return(consumer)
9
+ end
10
+
11
+ def expect_consumer_post(uri, params = {}, result = '')
12
+ rest_client = @client.consumer[uri]
13
+ rest_client.stub!(:post).with(params).and_return(Struct.new(:body).new(result))
14
+ @client.consumer.stub!(:[]).with(uri).and_return(rest_client)
15
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbgraph
3
3
  version: !ruby/object:Gem::Version
4
- hash: 93
4
+ hash: 89
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 6
10
- - 1
11
- version: 0.1.6.1
10
+ - 3
11
+ version: 0.1.6.3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Nicolas Santa
@@ -37,7 +37,7 @@ cert_chain:
37
37
  urUszHKBS/vEBMuC
38
38
  -----END CERTIFICATE-----
39
39
 
40
- date: 2010-09-07 00:00:00 -03:00
40
+ date: 2010-09-15 00:00:00 -03:00
41
41
  default_executable:
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
@@ -1 +1,2 @@
1
- HϹ�Ţpݕ�����4Щd<�̶]4��{��r���6��щ��ʠ�y��}�Ȅ 6XK�Q�F�����y� <t�!E7��}����s1���N��RCX*�!����+��I��&2�ј.�G~l��SC�/���=$U=6���b\rb���.�2�g%�o�u|#J��l=u����1(� AW�d>p�<�G�-'X���&ڠ9c,c�����2y���Ev�S/�ܵ"��񻥶��c���
1
+ ,n56򏔥!
2
+ (�v����MCC�w�Pm�h�����o�œey�n���e�K `B�cH�ʻ܇���Q(��6 �;5�*�^�A�3��5%��%�yVYsr[zo���X�k{_��:� :�Gg-!J���R*s�܃�]�4��#�S��ݷ���1 �mɾ�LԾ�И������1�,��M_���(�