facebooker 1.0.74 → 1.0.75

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{facebooker}
5
- s.version = "1.0.67"
5
+ s.version = "1.0.75"
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-03-30}
9
+ s.date = %q{2010-08-20}
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
@@ -42,6 +42,14 @@ class Facebooker::Attachment
42
42
  params[:expanded_height] = expanded_height unless expanded_height.nil?
43
43
  add_media(params)
44
44
  end
45
+
46
+
47
+ def add_property(key, value)
48
+ @storage[:properties] ||= {}
49
+ @storage[:properties][key] = value
50
+ end
51
+
52
+
45
53
 
46
54
  def to_hash
47
55
  @storage
@@ -76,7 +76,6 @@ module Facebooker
76
76
  # # => Returns true if all went well
77
77
  def rsvp_event(eid, rsvp_status, options = {})
78
78
  result = @session.post('facebook.events.rsvp', options.merge(:eid => eid, :rsvp_status => rsvp_status))
79
- result == '1' ? true : false
80
79
  end
81
80
 
82
81
  #
@@ -583,16 +583,16 @@ module Facebooker
583
583
 
584
584
  class EventsRsvp < Parser#:nodoc:
585
585
  def self.process(data)
586
- element('events_rsvp_response', data).content.strip
586
+ booleanize(element('events_rsvp_response', data).content.strip)
587
587
  end
588
588
  end
589
-
589
+
590
590
  class EventsCreate < Parser#:nodoc:
591
591
  def self.process(data)
592
592
  element('events_create_response', data).content.strip
593
593
  end
594
594
  end
595
-
595
+
596
596
  class EventsCancel < Parser#:nodoc:
597
597
  def self.process(data)
598
598
  element('events_cancel_response', data).content.strip
@@ -605,6 +605,18 @@ module Facebooker
605
605
  end
606
606
  end
607
607
 
608
+ class EventsEdit < Parser#:nodoc:
609
+ def self.process(data)
610
+ booleanize(element('events_edit_response', data).content.strip)
611
+ end
612
+ end
613
+
614
+ class EventsInvite < Parser#:nodoc:
615
+ def self.process(data)
616
+ booleanize(element('events_invite_response', data).content.strip)
617
+ end
618
+ end
619
+
608
620
  class GroupGetMembers < Parser#:nodoc:
609
621
  def self.process(data)
610
622
  root = element('groups_getMembers_response', data)
@@ -827,6 +839,7 @@ module Facebooker
827
839
  2 => Facebooker::Session::ServiceUnavailable,
828
840
  4 => Facebooker::Session::MaxRequestsDepleted,
829
841
  5 => Facebooker::Session::HostNotAllowed,
842
+ 10 => Facebooker::Session::AppPermissionError,
830
843
  100 => Facebooker::Session::MissingOrInvalidParameter,
831
844
  101 => Facebooker::Session::InvalidAPIKey,
832
845
  102 => Facebooker::Session::SessionExpired,
@@ -862,7 +875,8 @@ module Facebooker
862
875
  605 => Facebooker::Session::FQLFunctionDoesNotExist,
863
876
  606 => Facebooker::Session::FQLWrongNumberArgumentsPassedToFunction,
864
877
  612 => Facebooker::Session::ReadMailboxExtendedPermissionRequired,
865
- 807 => Facebooker::Session::TemplateBundleInvalid
878
+ 807 => Facebooker::Session::TemplateBundleInvalid,
879
+ 1001=> Facebooker::Session::EventNameLocked
866
880
  }
867
881
  def self.process(data)
868
882
  response_element = element('error_response', data) rescue nil
@@ -940,6 +954,8 @@ module Facebooker
940
954
  'facebook.events.create' => EventsCreate,
941
955
  'facebook.events.cancel' => EventsCancel,
942
956
  'facebook.events.get' => EventsGet,
957
+ 'facebook.events.edit' => EventsEdit,
958
+ 'facebook.events.invite' => EventsInvite,
943
959
  'facebook.events.rsvp' => EventsRsvp,
944
960
  'facebook.groups.get' => GroupsGet,
945
961
  'facebook.events.getMembers' => EventMembersGet,
@@ -137,6 +137,9 @@ module Facebooker
137
137
  def fb_logout_link(text,url,*args)
138
138
  js = update_page do |page|
139
139
  page.call "FB.Connect.logoutAndRedirect",url
140
+ # When session is valid, this call is meaningless, since we already redirect
141
+ # When session is invalid, it will log the user out of the system.
142
+ page.redirect_to url
140
143
  end
141
144
  link_to_function text, js, *args
142
145
  end
@@ -20,6 +20,7 @@ module Facebooker
20
20
  class ServiceUnavailable < Error; end
21
21
  class MaxRequestsDepleted < Error; end
22
22
  class HostNotAllowed < Error; end
23
+ class AppPermissionError < Error; end
23
24
  class MissingOrInvalidParameter < Error; end
24
25
  class InvalidAPIKey < Error; end
25
26
  class SessionExpired < Error; end
@@ -59,6 +60,7 @@ module Facebooker
59
60
  class ExtendedPermissionRequired < Error; end
60
61
  class ReadMailboxExtendedPermissionRequired < Error; end
61
62
  class InvalidFriendList < Error; end
63
+ class EventNameLocked < StandardError ; end
62
64
  class UserUnRegistrationFailed < Error
63
65
  attr_accessor :failed_users
64
66
  end
@@ -322,6 +324,10 @@ module Facebooker
322
324
 
323
325
  post_file('facebook.events.create', :event_info => event_info.to_json, nil => multipart_post_file)
324
326
  end
327
+
328
+ def edit_event(eid, event_info, options = {})
329
+ post('facebook.events.edit', options.merge(:eid => eid, :event_info => event_info.to_json))
330
+ end
325
331
 
326
332
  # Cancel an event
327
333
  # http://wiki.developers.facebook.com/index.php/Events.cancel
@@ -333,6 +339,22 @@ module Facebooker
333
339
  result == '1' ? true : false
334
340
  end
335
341
 
342
+ # Invite users to an event
343
+ # http://wiki.developers.facebook.com/index.php/Events.invite
344
+ # E.g:
345
+ # @session.event_invite('1000321123', %w{1234 4567 1000123321}, :personal_message => "Please come!")
346
+ def event_invite(eid, uids, options = {})
347
+ post('facebook.events.invite', options.merge(:eid => eid, :uids => uids.to_json))
348
+ end
349
+
350
+ # RSVP to an event
351
+ # http://wiki.developers.facebook.com/index.php/Events.rsvp
352
+ # E.g:
353
+ # @session.event_rsvp('1000321123', 'attending')
354
+ def event_rsvp(eid,rsvp_status, options = {})
355
+ post('facebook.events.rsvp', options.merge(:eid => eid, :rsvp_status => rsvp_status))
356
+ end
357
+
336
358
  def event_members(eid)
337
359
  @members ||= {}
338
360
  @members[eid] ||= post('facebook.events.getMembers', :eid => eid) do |response|
@@ -2,7 +2,7 @@ module Facebooker #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 74
5
+ TINY = 75
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1103,7 +1103,7 @@ class RailsHelperTest < Test::Unit::TestCase
1103
1103
  end
1104
1104
 
1105
1105
  def test_fb_logout_link
1106
- assert_equal @h.fb_logout_link("Logout","My URL"),"<a href=\"#\" onclick=\"FB.Connect.logoutAndRedirect(&quot;My URL&quot;);; return false;\">Logout</a>"
1106
+ assert_equal @h.fb_logout_link("Logout","My URL"),"<a href=\"#\" onclick=\"FB.Connect.logoutAndRedirect(&quot;My URL&quot;);\nwindow.location.href = &quot;My URL&quot;;; return false;\">Logout</a>"
1107
1107
  end
1108
1108
 
1109
1109
  def test_fb_bookmark_link
@@ -213,11 +213,33 @@ class Facebooker::SessionTest < Test::Unit::TestCase
213
213
  mock_session.create_event('name' => 'foo', 'category' => 'bar', :start_time => start_time, :end_time => end_time)
214
214
  end
215
215
 
216
+ def test_can_edit_events
217
+ expect_http_posts_with_responses(example_event_edit_xml)
218
+ assert @session.edit_event("12345", :host => 'Me, Myself, & I')
219
+ end
220
+
221
+ def test_edit_event_name_after_others_rsvp_throws_exception
222
+ expect_http_posts_with_responses(example_event_edit_name_exception_xml)
223
+ assert_raises(Facebooker::Session::EventNameLocked) {
224
+ @session.edit_event("12345", :name => 'Please Raise an Exception')
225
+ }
226
+ end
227
+
216
228
  def test_can_cancel_events
217
229
  expect_http_posts_with_responses(example_event_cancel_xml)
218
230
  assert @session.cancel_event("12345", :cancel_message => "It's raining")
219
231
  end
220
232
 
233
+ def test_can_invite_to_events
234
+ expect_http_posts_with_responses(example_event_invite_xml)
235
+ assert @session.event_invite("12345", %w{1234 4567 100043211234}, :personal_message => 'Please come!')
236
+ end
237
+
238
+ def test_can_rsvp_to_events
239
+ expect_http_posts_with_responses(example_event_rsvp_xml)
240
+ assert @session.event_rsvp("12345", "attending")
241
+ end
242
+
221
243
  def test_can_query_for_events
222
244
  expect_http_posts_with_responses(example_events_get_xml)
223
245
  events = @session.events
@@ -520,6 +542,68 @@ XML
520
542
  </events_create_response>
521
543
  XML
522
544
  end
545
+
546
+ def example_event_edit_xml
547
+ <<-XML
548
+ <?xml version="1.0" encoding="UTF-8"?>
549
+ <events_edit_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">
550
+ 1
551
+ </events_edit_response>
552
+ XML
553
+ end
554
+
555
+ def example_event_edit_name_exception_xml
556
+ <<-XML
557
+ <?xml version="1.0" encoding="UTF-8"?>
558
+ <error_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">
559
+ <error_code>1001</error_code>
560
+ <error_msg>You are no longer able to change the name of this event.</error_msg>
561
+ <request_args list="true">
562
+ <arg>
563
+ <key>v</key>
564
+ <value>1.0</value>
565
+ </arg>
566
+ <arg>
567
+ <key>session_key</key>
568
+ <value>xxxxxxxxxxxxxxxxxxxxxxxx-100000123443210</value>
569
+ </arg>
570
+ <arg>
571
+ <key>eid</key>
572
+ <value>123456776543210</value>
573
+ </arg>
574
+ <arg>
575
+ <key>api_key</key>
576
+ <value>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</value>
577
+ </arg>
578
+ <arg>
579
+ <key>method</key>
580
+ <value>facebook.events.edit</value>
581
+ </arg>
582
+ <arg>
583
+ <key>sig</key>
584
+ <value>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</value>
585
+ </arg>
586
+ <arg>
587
+ <key>event_info</key>
588
+ <value>{&quot;name&quot;:&quot;Please Raise an Exception&quot;}</value>
589
+ </arg>
590
+ <arg>
591
+ <key>call_id</key>
592
+ <value>1276801014.58273</value>
593
+ </arg>
594
+ </request_args>
595
+ </error_response>
596
+ XML
597
+ end
598
+
599
+ def example_event_invite_xml
600
+ <<-XML
601
+ <?xml version="1.0" encoding="UTF-8"?>
602
+ <events_invite_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">
603
+ 1
604
+ </events_invite_response>
605
+ XML
606
+ end
523
607
 
524
608
  def example_event_cancel_xml
525
609
  <<-XML
@@ -530,6 +614,15 @@ XML
530
614
  XML
531
615
  end
532
616
 
617
+ def example_event_rsvp_xml
618
+ <<-XML
619
+ <?xml version="1.0" encoding="UTF-8"?>
620
+ <events_rsvp_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">
621
+ 1
622
+ </events_rsvp_response>
623
+ XML
624
+ end
625
+
533
626
  def example_events_get_xml
534
627
  <<-XML
535
628
  <?xml version="1.0" encoding="UTF-8"?>
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.74
4
+ version: 1.0.75
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-06-28 00:00:00 -04:00
17
+ date: 2010-08-20 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency