fb_graph 1.9.2 → 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fb_graph (1.9.1)
4
+ fb_graph (1.9.2)
5
5
  httpclient (>= 2.2.0.2)
6
6
  rack-oauth2 (>= 0.8.0)
7
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.2
1
+ 1.9.3
@@ -0,0 +1,64 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Settings
4
+ AVAILABLE_SETTINGS = [
5
+ :users_can_post,
6
+ :users_can_post_photos,
7
+ :users_can_tag_photos,
8
+ :users_can_post_videos
9
+ ]
10
+
11
+ def self.included(klass)
12
+ AVAILABLE_SETTINGS.each do |setting|
13
+ klass.class_eval <<-SETTING
14
+ def #{setting}?(options = {})
15
+ settings(options).include? :#{setting}
16
+ end
17
+
18
+ def #{setting}!(options = {})
19
+ enable! :#{setting}, options
20
+ end
21
+
22
+ def #{setting.to_s.sub('can', 'cannot')}!(options = {})
23
+ disable! :#{setting}, options
24
+ end
25
+ SETTING
26
+ end
27
+ end
28
+
29
+ def settings(options = {})
30
+ @settings = nil if options[:no_cache]
31
+ @settings ||= self.connection(:settings, options).inject([]) do |_settings_, _setting_|
32
+ _settings_ << _setting_[:setting].downcase.to_sym if _setting_[:value]
33
+ _settings_
34
+ end
35
+ end
36
+
37
+ def enable!(setting, options = {})
38
+ __update_setting__ setting, true, options
39
+ end
40
+
41
+ def disable!(setting, options = {})
42
+ __update_setting__ setting, false, options
43
+ end
44
+
45
+ private
46
+
47
+ def __update_setting__(setting, value, options = {})
48
+ succeeded = post options.merge(
49
+ :setting => setting.to_s.upcase,
50
+ :value => value,
51
+ :connection => :settings
52
+ )
53
+ if succeeded
54
+ if value
55
+ @settings << setting.to_sym
56
+ else
57
+ @settings.delete_if { |key| key == setting.to_sym }
58
+ end
59
+ end
60
+ succeeded
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,18 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Tabs
4
+ def tabs(options = {})
5
+ tabs = self.connection(:tabs, options)
6
+ tabs.map! do |tab|
7
+ Tab.new(tab[:id], tab.merge(
8
+ :access_token => options[:access_token] || self.access_token
9
+ ))
10
+ end
11
+ end
12
+
13
+ def tab!(options = {})
14
+ post options.merge(:connection => :tabs)
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/fb_graph/node.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'tempfile'
2
+
1
3
  module FbGraph
2
4
  class Node
3
5
  include Comparison
@@ -13,7 +15,8 @@ module FbGraph
13
15
  def fetch(options = {})
14
16
  options[:access_token] ||= self.access_token if self.access_token
15
17
  _fetched_ = get(options)
16
- self.class.new(_fetched_[:id], _fetched_.merge(:access_token => options[:access_token]))
18
+ _fetched_[:access_token] ||= options[:access_token]
19
+ self.class.new(_fetched_[:id], _fetched_)
17
20
  end
18
21
 
19
22
  def self.fetch(identifier, options = {})
@@ -72,9 +75,9 @@ module FbGraph
72
75
  _params_.each do |key, value|
73
76
  next if value.blank?
74
77
  _params_[key] = case value
75
- when Symbol, Numeric, Rack::OAuth2::AccessToken::Legacy
78
+ when String, Symbol, Numeric, Rack::OAuth2::AccessToken::Legacy
76
79
  value.to_s
77
- when String, IO
80
+ when IO, Tempfile
78
81
  value
79
82
  when defined?(ActionDispatch::Http::UploadedFile) && ActionDispatch::Http::UploadedFile
80
83
  # NOTE: for Rails 3.0.6+
data/lib/fb_graph/page.rb CHANGED
@@ -11,7 +11,9 @@ module FbGraph
11
11
  include Connections::Photos
12
12
  include Connections::Picture
13
13
  include Connections::Posts
14
+ include Connections::Settings
14
15
  include Connections::Statuses
16
+ include Connections::Tabs
15
17
  include Connections::Tagged
16
18
  include Connections::Videos
17
19
  extend Searchable
@@ -0,0 +1,17 @@
1
+ module FbGraph
2
+ class Tab < Node
3
+ attr_accessor :link, :application, :custom_name, :is_permanent, :position, :is_non_connection_landing_tab
4
+
5
+ def initialize(identifier, attributes = {})
6
+ super
7
+ @link = attributes[:link]
8
+ @application = if attributes[:application]
9
+ Application.new(attributes[:application][:id], attributes[:application])
10
+ end
11
+ @custom_name = attributes[:custom_name]
12
+ @is_permanent = attributes[:is_permanent]
13
+ @position = attributes[:position]
14
+ @is_non_connection_landing_tab = attributes[:is_non_connection_landing_tab]
15
+ end
16
+ end
17
+ end
data/lib/fb_graph.rb CHANGED
@@ -79,6 +79,7 @@ require 'fb_graph/post'
79
79
  require 'fb_graph/property'
80
80
  require 'fb_graph/review'
81
81
  require 'fb_graph/status'
82
+ require 'fb_graph/tab'
82
83
  require 'fb_graph/tag'
83
84
  require 'fb_graph/thread'
84
85
  require 'fb_graph/user'
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Settings do
4
+
5
+ describe '#settings' do
6
+ subject do
7
+ mock_graph :get, 'sample/settings', 'pages/settings/sample', :access_token => 'page_token' do
8
+ FbGraph::Page.new('sample').settings(:access_token => 'page_token')
9
+ end
10
+ end
11
+
12
+ it do
13
+ should == [
14
+ :users_can_post,
15
+ :users_can_post_photos,
16
+ :users_can_post_videos
17
+ ]
18
+ end
19
+ end
20
+
21
+ describe 'setting specific methods' do
22
+ let(:page) { FbGraph::Page.new('page_id', :access_token => 'page_token') }
23
+
24
+ before do
25
+ mock_graph :get, 'page_id/settings', 'pages/settings/all_enabled', :access_token => 'page_token' do
26
+ page.settings # cache settings
27
+ end
28
+ end
29
+
30
+ FbGraph::Connections::Settings::AVAILABLE_SETTINGS.each do |setting|
31
+ describe "##{setting}?" do
32
+ it { page.send(:"#{setting}?").should be_true }
33
+
34
+ context 'when no_cache specified' do
35
+ it 'should request API' do
36
+ expect { page.send(:"#{setting}?", :no_cache => true) }.should request_to 'page_id/settings'
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#{setting}!" do
42
+ it "should enable it" do
43
+ mock_graph :post, 'page_id/settings', 'true', :access_token => 'page_token', :params => {
44
+ :setting => setting.to_s.upcase, :value => 'true'
45
+ } do
46
+ page.send(:"#{setting}!").should be_true
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#{setting.to_s.sub('can', 'cannot')}!" do
52
+ it "should disable it" do
53
+ mock_graph :post, 'page_id/settings', 'true', :access_token => 'page_token', :params => {
54
+ :setting => setting.to_s.upcase, :value => 'false'
55
+ } do
56
+ page.send(:"#{setting.to_s.sub('can', 'cannot')}!").should be_true
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::Tabs do
4
+ let(:page) { FbGraph::Page.new('FbGraph', :access_token => 'page_token') }
5
+
6
+ describe '#tabs' do
7
+ it 'should return tabs as FbGraph::Tab' do
8
+ mock_graph :get, 'FbGraph/tabs', 'pages/tabs/fb_graph', :access_token => 'page_token' do
9
+ page.tabs.each do |tab|
10
+ tab.should be_a FbGraph::Tab
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ describe '#tab!' do
17
+ it 'should add a tab' do
18
+ mock_graph :post, 'FbGraph/tabs', 'true', :access_token => 'page_token', :params => {
19
+ :app_id => '12345'
20
+ } do
21
+ page.tab!(:app_id => 12345).should be_true
22
+ end
23
+ end
24
+ end
25
+ end
@@ -14,6 +14,7 @@ describe FbGraph::Node do
14
14
 
15
15
  describe '#build_params' do
16
16
  let(:node) { node = FbGraph::Node.new('identifier') }
17
+ let(:tmpfile) { Tempfile.new('tmp') }
17
18
 
18
19
  it 'should make all values to JSON or String' do
19
20
  client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
@@ -23,26 +24,31 @@ describe FbGraph::Node do
23
24
  params[:integer].should == '123'
24
25
  end
25
26
 
26
- it 'should support Rack::OAuth2::AccessToken as self.access_token' do
27
+ it 'should support Rack::OAuth2::AccessToken::Legacy as self.access_token' do
27
28
  client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
28
29
  node = FbGraph::Node.new('identifier', :access_token => Rack::OAuth2::AccessToken::Legacy.new(:access_token => 'token'))
29
30
  params = node.send :build_params, {}
30
31
  params[:access_token].should == 'token'
31
32
  end
32
33
 
33
- it 'should support OAuth2::AccessToken as options[:access_token]' do
34
+ it 'should support Rack::OAuth2::AccessToken::Legacy as options[:access_token]' do
34
35
  client = Rack::OAuth2::Client.new(:identifier => 'client_id', :secret => 'client_secret')
35
36
  params = node.send :build_params, {:access_token => Rack::OAuth2::AccessToken::Legacy.new(:access_token => 'token')}
36
37
  params[:access_token].should == 'token'
37
38
  end
38
39
 
40
+ it 'should support Tempfile' do
41
+ params = node.send :build_params, :upload => tmpfile
42
+ params[:upload].should be_equal tmpfile
43
+ end
44
+
39
45
  require 'action_dispatch/http/upload'
40
46
  it 'should support ActionDispatch::Http::UploadedFile' do
41
47
  upload = ActionDispatch::Http::UploadedFile.new(
42
- :tempfile => Tempfile.new('tmp')
48
+ :tempfile => tmpfile
43
49
  )
44
50
  params = node.send :build_params, :upload => upload
45
- params[:upload].should be_a Tempfile
51
+ params[:upload].should be_equal tmpfile
46
52
  end
47
53
  end
48
54
 
@@ -30,5 +30,16 @@ describe FbGraph::Page do
30
30
  its(:name) { should == 'Facebook Platform' }
31
31
  its(:category) { should == 'Technology' }
32
32
  its(:like_count) { should == 578214 }
33
+
34
+ context 'when access_token field fetched' do
35
+ subject do
36
+ mock_graph :get, 'my_page', 'pages/with_token', :access_token => 'user_token', :params => {
37
+ :fields => :access_token
38
+ } do
39
+ FbGraph::Page.fetch('my_page', :fields => :access_token, :access_token => 'user_token')
40
+ end
41
+ end
42
+ its(:access_token) { should == 'page_token' }
43
+ end
33
44
  end
34
45
  end
@@ -0,0 +1,20 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "setting": "USERS_CAN_POST",
5
+ "value": true
6
+ },
7
+ {
8
+ "setting": "USERS_CAN_POST_PHOTOS",
9
+ "value": true
10
+ },
11
+ {
12
+ "setting": "USERS_CAN_TAG_PHOTOS",
13
+ "value": true
14
+ },
15
+ {
16
+ "setting": "USERS_CAN_POST_VIDEOS",
17
+ "value": true
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "setting": "USERS_CAN_POST",
5
+ "value": true
6
+ },
7
+ {
8
+ "setting": "USERS_CAN_POST_PHOTOS",
9
+ "value": true
10
+ },
11
+ {
12
+ "setting": "USERS_CAN_TAG_PHOTOS",
13
+ "value": false
14
+ },
15
+ {
16
+ "setting": "USERS_CAN_POST_VIDEOS",
17
+ "value": true
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "data": [{
3
+ "id": "117513961602338/tabs/wall",
4
+ "name": "Wall",
5
+ "link": "http://www.facebook.com/FbGraph?sk=wall",
6
+ "is_permanent": true,
7
+ "position": 0
8
+ },
9
+ {
10
+ "id": "117513961602338/tabs/info",
11
+ "name": "Info",
12
+ "link": "http://www.facebook.com/FbGraph?sk=info",
13
+ "is_permanent": true,
14
+ "position": 1
15
+ },
16
+ {
17
+ "id": "117513961602338/tabs/app_134145643294322",
18
+ "name": "Custom Name",
19
+ "link": "http://www.facebook.com/FbGraph?sk=app_134145643294322",
20
+ "application": {
21
+ "name": "gem sample",
22
+ "id": "134145643294322"
23
+ },
24
+ "custom_name": "Custom Name",
25
+ "position": 2,
26
+ "is_non_connection_landing_tab": true
27
+ }]
28
+ }
@@ -0,0 +1 @@
1
+ {"access_token":"page_token","id":"117513961602338"}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 9
9
- - 2
10
- version: 1.9.2
9
+ - 3
10
+ version: 1.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - nov matake
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-04 00:00:00 Z
18
+ date: 2011-07-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httpclient
@@ -203,8 +203,10 @@ files:
203
203
  - lib/fb_graph/connections/posts.rb
204
204
  - lib/fb_graph/connections/reviews.rb
205
205
  - lib/fb_graph/connections/senders.rb
206
+ - lib/fb_graph/connections/settings.rb
206
207
  - lib/fb_graph/connections/statuses.rb
207
208
  - lib/fb_graph/connections/subscriptions.rb
209
+ - lib/fb_graph/connections/tabs.rb
208
210
  - lib/fb_graph/connections/tagged.rb
209
211
  - lib/fb_graph/connections/tags.rb
210
212
  - lib/fb_graph/connections/television.rb
@@ -241,6 +243,7 @@ files:
241
243
  - lib/fb_graph/serialization.rb
242
244
  - lib/fb_graph/status.rb
243
245
  - lib/fb_graph/subscription.rb
246
+ - lib/fb_graph/tab.rb
244
247
  - lib/fb_graph/tag.rb
245
248
  - lib/fb_graph/targeting.rb
246
249
  - lib/fb_graph/test_user.rb
@@ -299,8 +302,10 @@ files:
299
302
  - spec/fb_graph/connections/posts_spec.rb
300
303
  - spec/fb_graph/connections/reviews_spec.rb
301
304
  - spec/fb_graph/connections/senders_spec.rb
305
+ - spec/fb_graph/connections/settings_spec.rb
302
306
  - spec/fb_graph/connections/statuses_spec.rb
303
307
  - spec/fb_graph/connections/subscriptions_spec.rb
308
+ - spec/fb_graph/connections/tabs_spec.rb
304
309
  - spec/fb_graph/connections/tagged_spec.rb
305
310
  - spec/fb_graph/connections/tags_spec.rb
306
311
  - spec/fb_graph/connections/television_spec.rb
@@ -383,8 +388,12 @@ files:
383
388
  - spec/mock_json/pages/platform_public.json
384
389
  - spec/mock_json/pages/search_fb_graph.json
385
390
  - spec/mock_json/pages/search_google.json
391
+ - spec/mock_json/pages/settings/all_enabled.json
392
+ - spec/mock_json/pages/settings/sample.json
386
393
  - spec/mock_json/pages/statuses/platform_private.json
387
394
  - spec/mock_json/pages/statuses/platform_public.json
395
+ - spec/mock_json/pages/tabs/fb_graph.json
396
+ - spec/mock_json/pages/with_token.json
388
397
  - spec/mock_json/photos/sample.json
389
398
  - spec/mock_json/photos/with_tags.json
390
399
  - spec/mock_json/posts/comments/post_with_invalid_access_token.json
@@ -503,7 +512,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
503
512
  requirements: []
504
513
 
505
514
  rubyforge_project:
506
- rubygems_version: 1.7.2
515
+ rubygems_version: 1.8.5
507
516
  signing_key:
508
517
  specification_version: 3
509
518
  summary: A full-stack Facebook Graph API wrapper in Ruby.
@@ -558,8 +567,10 @@ test_files:
558
567
  - spec/fb_graph/connections/posts_spec.rb
559
568
  - spec/fb_graph/connections/reviews_spec.rb
560
569
  - spec/fb_graph/connections/senders_spec.rb
570
+ - spec/fb_graph/connections/settings_spec.rb
561
571
  - spec/fb_graph/connections/statuses_spec.rb
562
572
  - spec/fb_graph/connections/subscriptions_spec.rb
573
+ - spec/fb_graph/connections/tabs_spec.rb
563
574
  - spec/fb_graph/connections/tagged_spec.rb
564
575
  - spec/fb_graph/connections/tags_spec.rb
565
576
  - spec/fb_graph/connections/television_spec.rb
@@ -642,8 +653,12 @@ test_files:
642
653
  - spec/mock_json/pages/platform_public.json
643
654
  - spec/mock_json/pages/search_fb_graph.json
644
655
  - spec/mock_json/pages/search_google.json
656
+ - spec/mock_json/pages/settings/all_enabled.json
657
+ - spec/mock_json/pages/settings/sample.json
645
658
  - spec/mock_json/pages/statuses/platform_private.json
646
659
  - spec/mock_json/pages/statuses/platform_public.json
660
+ - spec/mock_json/pages/tabs/fb_graph.json
661
+ - spec/mock_json/pages/with_token.json
647
662
  - spec/mock_json/photos/sample.json
648
663
  - spec/mock_json/photos/with_tags.json
649
664
  - spec/mock_json/posts/comments/post_with_invalid_access_token.json