facebooker 1.0.64 → 1.0.65

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.
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{facebooker}
5
- s.version = "1.0.64"
5
+ s.version = "1.0.65"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Chad Fowler", "Patrick Ewing", "Mike Mangino", "Shane Vitarana", "Corey Innis", "Mike Mangino"]
9
- s.date = %q{2010-02-26}
9
+ s.date = %q{2010-03-17}
10
10
  s.description = %q{Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://wiki.developers.facebook.com/index.php/API]. Its goals are:
11
11
 
12
12
  * Idiomatic Ruby
@@ -6,6 +6,6 @@ module Facebooker
6
6
  end
7
7
 
8
8
  include Model
9
- attr_accessor :concentrations, :name, :year, :degree
9
+ attr_accessor :concentrations, :name, :year, :degree, :school_type
10
10
  end
11
11
  end
@@ -9,7 +9,7 @@ module Facebooker
9
9
  include Model
10
10
  class Status
11
11
  include Model
12
- attr_accessor :message, :time, :status_id
12
+ attr_accessor :uid, :message, :time, :status_id, :source
13
13
  end
14
14
  FIELDS = [:status, :political, :pic_small, :name, :quotes, :is_app_user, :tv, :profile_update_time, :meeting_sex, :hs_info, :timezone, :relationship_status, :hometown_location, :about_me, :wall_count, :significant_other_id, :pic_big, :music, :work_history, :sex, :religion, :notes_count, :activities, :pic_square, :movies, :has_added_app, :education_history, :birthday, :birthday_date, :first_name, :meeting_for, :last_name, :interests, :current_location, :pic, :books, :affiliations, :locale, :profile_url, :proxied_email, :email_hashes, :allowed_restrictions, :pic_with_logo, :pic_big_with_logo, :pic_small_with_logo, :pic_square_with_logo, :online_presence, :verified, :profile_blurb, :username, :website, :is_blocked, :family, :email]
15
15
  STANDARD_FIELDS = [:uid, :first_name, :last_name, :name, :timezone, :birthday, :sex, :affiliations, :locale, :profile_url, :proxied_email, :email]
@@ -297,6 +297,17 @@ module Facebooker
297
297
  end
298
298
  end
299
299
 
300
+ ###
301
+ # Retrieve user's facebook stream
302
+ # See http://wiki.developers.facebook.com/index.php/Stream.get for options
303
+ #
304
+
305
+ def stream(options = {})
306
+ @stream = session.post('facebook.stream.get', prepare_get_stream_options(options)) do |response|
307
+ response
308
+ end
309
+ end
310
+
300
311
  def create_album(params)
301
312
  @album = session.post('facebook.photos.createAlbum', params) {|response| Album.from_hash(response)}
302
313
  end
@@ -532,24 +543,12 @@ module Facebooker
532
543
 
533
544
  # Facebooker::User.dashboard_multi_increment_count ['1234', '5678']
534
545
  def self.dashboard_multi_increment_count(*uids)
535
- Facebooker::Session.create.post("facebook.dashboard.multiIncrementCount", :uids => uids.flatten.to_json)
546
+ Facebooker::Session.create.post("facebook.dashboard.multiIncrementCount", :uids => uids.flatten.collect{ |uid| uid.to_s }.to_json)
536
547
  end
537
548
 
538
549
  # Facebooker::User.dashboard_multi_decrement_count ['1234', '5678']
539
550
  def self.dashboard_multi_decrement_count(*uids)
540
- Facebooker::Session.create.post("facebook.dashboard.multiDecrementCount", :uids => uids.flatten.to_json)
541
- end
542
-
543
- def self.dashboard_multi_set_count(ids)
544
- Facebooker::Session.create.post("facebook.dashboard.multiSetCount", :ids => ids.to_json)
545
- end
546
-
547
- def self.dashboard_multi_increment_count(uids)
548
- Facebooker::Session.create.post("facebook.dashboard.multiIncrementCount", :uids => uids.to_json)
549
- end
550
-
551
- def self.dashboard_multi_decrement_count(uids)
552
- Facebooker::Session.create.post("facebook.dashboard.multiDecrementCount", :uids => uids.to_json)
551
+ Facebooker::Session.create.post("facebook.dashboard.multiDecrementCount", :uids => uids.flatten.collect{ |uid| uid.to_s }.to_json)
553
552
  end
554
553
 
555
554
 
@@ -730,5 +729,17 @@ module Facebooker
730
729
  (uid << 32) + (aid & 0xFFFFFFFF)
731
730
  end
732
731
 
732
+ def prepare_get_stream_options(options)
733
+ opts = {}
734
+
735
+ opts[:viewer_id] = self.id
736
+ opts[:source_ids] = options[:source_ids] if options[:source_ids]
737
+ opts[:start_time] = options[:start_time].to_i if options[:start_time]
738
+ opts[:end_time] = options[:end_time].to_i if options[:end_time]
739
+ opts[:limit] = options[:limit] if options[:limit].is_a?(Integer)
740
+ opts[:metadata] = Facebooker.json_encode(options[:metadata]) if options[:metadata]
741
+ opts
742
+ end
743
+
733
744
  end
734
745
  end
@@ -296,6 +296,12 @@ module Facebooker
296
296
  end
297
297
  end
298
298
 
299
+ class UploadNativeStrings < Parser#:nodoc:
300
+ def self.process(data)
301
+ element('intl_uploadNativeStrings_response', data).content.strip
302
+ end
303
+ end
304
+
299
305
  class PublishActionOfUser < Parser#:nodoc:
300
306
  def self.process(data)
301
307
  element('feed_publishActionOfUser_response', data).content.strip
@@ -962,7 +968,8 @@ module Facebooker
962
968
  'facebook.dashboard.multiClearNews' => DashboardMultiClearNews,
963
969
  'facebook.dashboard.publishActivity' => DashboardPublishActivity,
964
970
  'facebook.dashboard.removeActivity' => DashboardRemoveActivity,
965
- 'facebook.dashboard.getActivity' => DashboardGetActivity
971
+ 'facebook.dashboard.getActivity' => DashboardGetActivity,
972
+ 'facebook.intl.uploadNativeStrings' => UploadNativeStrings
966
973
  }
967
974
  end
968
975
  end
@@ -42,6 +42,7 @@ module Facebooker
42
42
  init_string = <<-FBML
43
43
  #{case options[:js]
44
44
  when :jquery then "jQuery(document).ready("
45
+ when :mootools then "window.addEvent('domready',"
45
46
  when :dojo then "dojo.addOnLoad("
46
47
  else "Element.observe(window,'load',"
47
48
  end} function() {
@@ -65,37 +66,64 @@ module Facebooker
65
66
  end
66
67
  end
67
68
 
69
+ #
68
70
  # Render an <fb:login-button> element
69
71
  #
70
72
  # ==== Examples
71
73
  #
72
- # <%= fb_login_button%>
73
- # => <fb:login-button></fb:login-button>
74
+ # <%= fb_login_button%>
75
+ # => <fb:login-button></fb:login-button>
74
76
  #
75
77
  # Specifying a javascript callback
76
78
  #
77
- # <%= fb_login_button 'update_something();'%>
78
- # => <fb:login-button onlogin='update_something();'></fb:login-button>
79
+ # <%= fb_login_button 'update_something();'%>
80
+ # => <fb:login-button onlogin='update_something();'></fb:login-button>
79
81
  #
80
82
  # Adding options <em>See:</em> http://wiki.developers.facebook.com/index.php/Fb:login-button
81
83
  #
82
- # <%= fb_login_button 'update_something();', :size => :small, :background => :dark%>
83
- # => <fb:login-button background='dark' onlogin='update_something();' size='small'></fb:login-button>
84
+ # <%= fb_login_button 'update_something();', :size => :small, :background => :dark%>
85
+ # => <fb:login-button background='dark' onlogin='update_something();' size='small'></fb:login-button>
86
+ #
87
+ # :text option allows you to set the text value of the
88
+ # button. *A note!* This will only do what you expect it to do
89
+ # if you set :v => 2 as well.
84
90
  #
91
+ # <%= fb_login_button 'update_somethign();',
92
+ # :text => 'Loginto Facebook', :v => 2 %>
93
+ # => <fb:login-button v='2' onlogin='update_something();'>Login to Facebook</fb:login-button>
85
94
  def fb_login_button(*args)
86
95
 
87
96
  callback = args.first
88
97
  options = args[1] || {}
89
- options.merge!(:onlogin=>callback)if callback
98
+ options.merge!(:onlogin=>callback) if callback
99
+
100
+ text = options.delete(:text)
90
101
 
91
- content_tag("fb:login-button",nil, options)
102
+ content_tag("fb:login-button",text, options)
92
103
  end
93
104
 
105
+ #
106
+ # Render an <fb:login-button> element, similar to
107
+ # fb_login_button. Adds a js redirect to the onlogin event via rjs.
108
+ #
109
+ # ==== Examples
110
+ #
111
+ # fb_login_and_redirect '/other_page'
112
+ # => <fb:login-button onlogin="window.location.href = &quot;/other_page&quot;;"></fb:login-button>
113
+ #
114
+ # Like #fb_login_button, this also supports the :text option
115
+ #
116
+ # fb_login_and_redirect '/other_page', :text => "Login with Facebook", :v => '2'
117
+ # => <fb:login-button onlogin="window.location.href = &quot;/other_page&quot;;" v="2">Login with Facebook</fb:login-button>
118
+ #
94
119
  def fb_login_and_redirect(url, options = {})
95
120
  js = update_page do |page|
96
121
  page.redirect_to url
97
122
  end
98
- content_tag("fb:login-button",nil,options.merge(:onlogin=>js))
123
+
124
+ text = options.delete(:text)
125
+
126
+ content_tag("fb:login-button",text,options.merge(:onlogin=>js))
99
127
  end
100
128
 
101
129
  def fb_unconnected_friends_count
@@ -108,6 +108,7 @@ module Facebooker
108
108
  @from = nil
109
109
  @full_story_template = nil
110
110
  @recipients = nil
111
+ @action_links = nil
111
112
  @controller = PublisherController.new(self)
112
113
  @action_links = nil
113
114
  end
@@ -338,7 +339,7 @@ module Facebooker
338
339
  if links.blank?
339
340
  @action_links
340
341
  else
341
- @action_links = links
342
+ @action_links = *links
342
343
  end
343
344
  end
344
345
 
@@ -521,6 +522,14 @@ module Facebooker
521
522
  end
522
523
  end
523
524
 
525
+ def respond_to?(method_symbol, include_private=false)
526
+ if match = /^(create|deliver|register)_([_a-z]\w*)/.match(method_symbol.to_s)
527
+ instance_methods.include?(match[2])
528
+ else
529
+ super(method_symbol, include_private)
530
+ end
531
+ end
532
+
524
533
  def method_missing(name,*args)
525
534
  should_send = false
526
535
  method = ''
@@ -7,6 +7,7 @@ module Facebooker
7
7
  @api_key = api_key
8
8
  end
9
9
 
10
+ @active_service = nil
10
11
  def self.active_service
11
12
  unless @active_service
12
13
  if Facebooker.use_curl?
@@ -533,6 +533,21 @@ module Facebooker
533
533
  post("facebook.feed.publishUserAction", parameters)
534
534
  end
535
535
 
536
+ ##
537
+ # Upload strings in native locale to facebook for translations.
538
+ #
539
+ # e.g. facebook_session.upload_native_strings([:text => "Welcome {user}", :description => "Welcome message to currently logged in user."])
540
+ # returns the number of strings uploaded
541
+ #
542
+ # See http://wiki.developers.facebook.com/index.php/Intl.uploadNativeStrings for method options
543
+ #
544
+ def upload_native_strings(native_strings)
545
+ raise ArgumentError, "You must provide strings to upload" if native_strings.nil?
546
+
547
+ post('facebook.intl.uploadNativeStrings', :native_strings => Facebooker.json_encode(native_strings)) do |response|
548
+ response
549
+ end
550
+ end
536
551
 
537
552
  ##
538
553
  # Send email to as many as 100 users at a time
@@ -2,7 +2,7 @@ module Facebooker #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 64
5
+ TINY = 65
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -439,7 +439,17 @@ class Facebooker::UserTest < Test::Unit::TestCase
439
439
  assert_equal({ '1234' => '11', '4321' => '22' }, Facebooker::User.dashboard_multi_get_count(['1234', '4321']))
440
440
  end
441
441
 
442
- def test_can_dashboard_multi_increment_count
442
+ def test_can_dashboard_multi_increment_count_with_single_uid
443
+ Facebooker::Session.any_instance.expects(:post).with('facebook.dashboard.multiIncrementCount', :uids => ['8675309'].to_json)
444
+ Facebooker::User.dashboard_multi_increment_count 8675309
445
+ end
446
+
447
+ def test_can_dashboard_multi_increment_count_with_multiple_uids
448
+ Facebooker::Session.any_instance.expects(:post).with('facebook.dashboard.multiIncrementCount', :uids => ['8675309', '555'].to_json)
449
+ Facebooker::User.dashboard_multi_increment_count 8675309, 555
450
+ end
451
+
452
+ def test_can_dashboard_multi_increment_count_with_array_of_uids
443
453
  Facebooker::Session.any_instance.expects(:post).with('facebook.dashboard.multiIncrementCount', :uids => ['1234', '4321'].to_json)
444
454
  Facebooker::User.dashboard_multi_increment_count ['1234', '4321']
445
455
  end
@@ -449,12 +459,17 @@ class Facebooker::UserTest < Test::Unit::TestCase
449
459
  assert_equal({ '1234' => '1', '4321' => '1' }, Facebooker::User.dashboard_multi_increment_count(['1234', '4321']))
450
460
  end
451
461
 
452
- def test_can_dashboard_multi_decrement_count
453
- Facebooker::Session.any_instance.expects(:post).with('facebook.dashboard.multiDecrementCount', :uids => ['1234', '4321'].to_json)
454
- Facebooker::User.dashboard_multi_decrement_count ['1234', '4321']
462
+ def test_can_dashboard_multi_decrement_count_with_single_uid
463
+ Facebooker::Session.any_instance.expects(:post).with('facebook.dashboard.multiDecrementCount', :uids => ['99999999'].to_json)
464
+ Facebooker::User.dashboard_multi_decrement_count 99999999
465
+ end
466
+
467
+ def test_can_dashboard_multi_decrement_count_with_multiple_uids
468
+ Facebooker::Session.any_instance.expects(:post).with('facebook.dashboard.multiDecrementCount', :uids => ['1111', '2222'].to_json)
469
+ Facebooker::User.dashboard_multi_decrement_count 1111, 2222
455
470
  end
456
471
 
457
- def test_parse_dashboard_multi_decrement_count
472
+ def test_parse_dashboard_multi_decrement_count_with_array_of_uids
458
473
  expect_http_posts_with_responses(dashboard_multi_decrement_count_xml)
459
474
  assert_equal({ '1234' => '1', '4321' => '1' }, Facebooker::User.dashboard_multi_decrement_count(['1234', '4321']))
460
475
  end
@@ -232,6 +232,12 @@ class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
232
232
  def teardown
233
233
  super
234
234
  end
235
+
236
+ def test_respond_to
237
+ assert TestPublisher.respond_to?(:create_action)
238
+ assert TestPublisher.respond_to?(:deliver_action)
239
+ assert TestPublisher.respond_to?(:register_action)
240
+ end
235
241
 
236
242
  def test_create_action
237
243
  action=TestPublisher.create_action(@user)
@@ -1032,6 +1032,8 @@ class RailsHelperTest < Test::Unit::TestCase
1032
1032
 
1033
1033
  def test_fb_login_button
1034
1034
  assert_equal "<fb:login-button onlogin=\"somejs\"></fb:login-button>",@h.fb_login_button("somejs")
1035
+
1036
+ assert_equal "<fb:login-button onlogin=\"somejs\">Custom</fb:login-button>",@h.fb_login_button("somejs", :text => 'Custom')
1035
1037
  end
1036
1038
 
1037
1039
  def test_init_fb_connect_no_features
@@ -1076,6 +1078,10 @@ class RailsHelperTest < Test::Unit::TestCase
1076
1078
  assert ! @h.init_fb_connect(:js => :jquery).match(/\$\(document\).ready\(/)
1077
1079
  end
1078
1080
 
1081
+ def test_init_fb_connect_with_options_js_mootools
1082
+ assert @h.init_fb_connect("XFBML", :js => :mootools).match(/window.addEvent\('domready',/)
1083
+ end
1084
+
1079
1085
  def test_init_fb_connect_with_features_and_options_js_jquery
1080
1086
  assert @h.init_fb_connect("XFBML", :js => :jquery).match(/XFBML.*/)
1081
1087
  assert @h.init_fb_connect("XFBML", :js => :jquery).match(/\jQuery\(document\).ready\(/)
@@ -1092,6 +1098,8 @@ class RailsHelperTest < Test::Unit::TestCase
1092
1098
 
1093
1099
  def test_fb_login_and_redirect
1094
1100
  assert_equal @h.fb_login_and_redirect("/path"),"<fb:login-button onlogin=\"window.location.href = &quot;/path&quot;;\"></fb:login-button>"
1101
+
1102
+ assert_equal @h.fb_login_and_redirect("/path", :text => 'foo'),"<fb:login-button onlogin=\"window.location.href = &quot;/path&quot;;\">foo</fb:login-button>"
1095
1103
  end
1096
1104
 
1097
1105
  def test_fb_logout_link
@@ -273,6 +273,13 @@ class TestFacebooker < Test::Unit::TestCase
273
273
  assert_equal('The bbc home page', stream[:posts].first['message'])
274
274
  end
275
275
 
276
+ def test_can_get_user_stream
277
+ expect_http_posts_with_responses(example_user_stream_xml)
278
+ stream = @session.user.stream
279
+ assert stream[:albums].empty?
280
+ assert_equal('The bbc home page', stream[:posts].first['message'])
281
+ end
282
+
276
283
  def test_can_create_album
277
284
  expect_http_posts_with_responses(example_new_album_xml)
278
285
  assert_equal "My Empty Album", @session.user.create_album(:name => "My Empty Album", :location => "Limboland").name
@@ -285,6 +292,11 @@ class TestFacebooker < Test::Unit::TestCase
285
292
  assert_equal "Under the sunset", @session.user.upload_photo(f).caption
286
293
  end
287
294
 
295
+ def test_can_upload_native_strings
296
+ expect_http_posts_with_responses(example_upload_native_string_xml)
297
+ assert_equal "1", @session.upload_native_strings([:text => "Hello!", :description => "A common salutation."])
298
+ end
299
+
288
300
  def test_can_get_photo_tags
289
301
  expect_http_posts_with_responses(example_photo_tags_xml)
290
302
  assert_instance_of Facebooker::Tag, @session.get_tags(:pids => 97503428461115571 ).first
@@ -1154,6 +1166,13 @@ class TestFacebooker < Test::Unit::TestCase
1154
1166
  </video_upload_response>
1155
1167
  XML
1156
1168
  end
1169
+
1170
+ def example_upload_native_string_xml
1171
+ <<-XML
1172
+ <?xml version="1.0" encoding="UTF-8"?>
1173
+ <intl_uploadNativeStrings_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</intl_uploadNativeStrings_response>
1174
+ XML
1175
+ end
1157
1176
 
1158
1177
  def example_revoke_authorization_true
1159
1178
  "1"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebooker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.64
4
+ version: 1.0.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Fowler
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-26 00:00:00 -05:00
17
+ date: 2010-03-17 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency