djanowski-facebooker 1.0.1 → 1.0.2

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/init.rb CHANGED
@@ -41,6 +41,22 @@ class ActionController::Routing::Route
41
41
  alias_method_chain :recognition_conditions, :facebooker
42
42
  end
43
43
 
44
+ # When making get requests, Facebook sends fb_sig parameters both in the query string
45
+ # and also in the post body. We want to ignore the query string ones because they are one
46
+ # request out of date
47
+ # We only do thise when there are POST parameters so that IFrame linkage still works
48
+ class ActionController::AbstractRequest
49
+ def query_parameters_with_facebooker
50
+ if request_parameters.blank?
51
+ query_parameters_without_facebooker
52
+ else
53
+ (query_parameters_without_facebooker||{}).reject {|key,value| key.to_s =~ /^fb_sig/}
54
+ end
55
+ end
56
+
57
+ alias_method_chain :query_parameters, :facebooker
58
+ end
59
+
44
60
  # We turn off route optimization to make named routes use our code for figuring out if they should go to the session
45
61
  # If this fails, it means we're on rails 1.2, we can ignore it
46
62
  begin
@@ -2,7 +2,7 @@ module Facebooker
2
2
 
3
3
  class AdapterBase
4
4
  class UnableToLoadAdapter < Exception; end
5
- require 'active_support'
5
+ require 'active_support/inflector'
6
6
  include ActiveSupport::CoreExtensions::String::Inflections
7
7
  def facebook_path_prefix
8
8
  "/" + (@facebook_path_prefix || canvas_page_name || ENV['FACEBOOK_CANVAS_PATH'] || ENV['FACEBOOKER_RELATIVE_URL_ROOT'])
@@ -43,7 +43,8 @@ module Facebooker
43
43
  set_profile_fbml_without_bebo_adapter(profile_fbml,mobile_fbml, profile_action_fbml, profile_main)
44
44
  end
45
45
  end
46
- alias_method_chain :set_profile_fbml, :bebo_adapter
46
+ alias_method :set_profile_fbml_without_bebo_adapter, :set_profile_fbml
47
+ alias_method :set_profile_fbml, :set_profile_fbml_with_bebo_adapter
47
48
 
48
49
  private
49
50
 
@@ -67,7 +68,8 @@ module Facebooker
67
68
  process_without_bebo_adapter(data)
68
69
  end
69
70
  end
70
- alias_method_chain :process, :bebo_adapter
71
+ alias_method :process_without_bebo_adapter, :process
72
+ alias_method :process, :process_with_bebo_adapter
71
73
  end
72
74
  end
73
- end
75
+ end
@@ -1,7 +1,7 @@
1
1
  require 'facebooker/model'
2
2
  module Facebooker
3
3
  ##
4
- # A simple representation of a photo album.
4
+ # A simple representation of a friend list.
5
5
  class FriendList
6
6
  include Model
7
7
  attr_accessor :flid, :name
@@ -11,4 +11,4 @@ module Facebooker
11
11
  @flid= ( f.nil? ? nil : f.to_i)
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,7 +1,6 @@
1
1
  require 'facebooker/model'
2
2
  require 'facebooker/models/affiliation'
3
3
  require 'facebooker/models/work_info'
4
- require 'active_support'
5
4
  module Facebooker
6
5
  #
7
6
  # Holds attributes and behavior for a Facebook User
@@ -219,24 +218,35 @@ module Facebooker
219
218
  end
220
219
 
221
220
  ##
222
- # Set the status of the user
223
- #
224
- # DOES NOT prepend "is" to the message
225
- #
226
- # requires extended permission.
221
+ # This DOES NOT set the status of a user on Facebook
222
+ # Use the set_status method instead
227
223
  def status=(message)
228
224
  case message
229
- when String
230
- session.post('facebook.users.setStatus',:status=>message,:status_includes_verb=>1) do |ret|
231
- ret
232
- end
233
- when Status
225
+ when String,Status
234
226
  @status = message
235
227
  when Hash
236
228
  @status = Status.from_hash(message)
237
229
  end
238
230
  end
239
231
 
232
+ ##
233
+ # Set the status for a user
234
+ # DOES NOT prepend "is" to the message
235
+ #
236
+ # requires extended permission.
237
+ def set_status(message)
238
+ self.status=message
239
+ session.post('facebook.users.setStatus',:status=>message,:status_includes_verb=>1) do |ret|
240
+ ret
241
+ end
242
+ end
243
+
244
+ ##
245
+ # Checks to see if the user has enabled the given extended permission
246
+ def has_permission?(ext_perm) # ext_perm = email, offline_access, status_update, photo_upload, create_listing, create_event, rsvp_event, sms
247
+ session.post('facebook.users.hasAppPermission',:ext_perm=>ext_perm) == "1"
248
+ end
249
+
240
250
  ##
241
251
  # Convenience method to send email to the current user
242
252
  def send_email(subject, text=nil, fbml=nil)
@@ -291,7 +301,7 @@ module Facebooker
291
301
  ret.each do |hash|
292
302
  user_map.delete(hash)
293
303
  end
294
- unless user_map.blank?
304
+ unless user_map.empty?
295
305
  e=Facebooker::Session::UserRegistrationFailed.new
296
306
  e.failed_users = user_map.values
297
307
  raise e
@@ -401,8 +401,8 @@ module Facebooker
401
401
  memo
402
402
  end
403
403
  end
404
-
405
- private
404
+
405
+ private
406
406
  def self.are_friends?(raw_value)
407
407
  if raw_value == '1'
408
408
  true
@@ -432,6 +432,12 @@ module Facebooker
432
432
  end
433
433
  end
434
434
 
435
+ class UserHasPermission < Parser
436
+ def self.process(data)
437
+ element('users_hasAppPermission_response', data).text_value
438
+ end
439
+ end
440
+
435
441
  class Errors < Parser#:nodoc:
436
442
  EXCEPTIONS = {
437
443
  1 => Facebooker::Session::UnknownError,
@@ -492,6 +498,7 @@ module Facebooker
492
498
  'facebook.users.getStandardInfo' => UserStandardInfo,
493
499
  'facebook.users.setStatus' => SetStatus,
494
500
  'facebook.users.getLoggedInUser' => GetLoggedInUser,
501
+ 'facebook.users.hasAppPermission' => UserHasPermission,
495
502
  'facebook.pages.isAdmin' => PagesIsAdmin,
496
503
  'facebook.pages.getInfo' => PagesGetInfo,
497
504
  'facebook.friends.get' => GetFriends,
data/test/user_test.rb CHANGED
@@ -15,6 +15,11 @@ class UserTest < Test::Unit::TestCase
15
15
  @user.friends = [@other_user]
16
16
  end
17
17
 
18
+ def test_has_permission
19
+ expect_http_posts_with_responses(has_app_permission_response_xml)
20
+ assert @user.has_permission?("status_update")
21
+ end
22
+
18
23
  def test_can_ask_user_if_he_or_she_is_friends_with_another_user
19
24
  assert(@user.friends_with?(@other_user))
20
25
  end
@@ -109,9 +114,13 @@ class UserTest < Test::Unit::TestCase
109
114
  @user.send_email("subject", nil, "body fbml")
110
115
  end
111
116
 
117
+ def test_doesnt_post_to_facebook_when_assigning_status
118
+ @session.expects(:post).never
119
+ @user.status="my status"
120
+ end
112
121
  def test_can_set_status_with_string
113
122
  @session.expects(:post).with('facebook.users.setStatus', :status=>"my status",:status_includes_verb=>1)
114
- @user.status="my status"
123
+ @user.set_status("my status")
115
124
  end
116
125
 
117
126
  def test_get_events
@@ -226,4 +235,13 @@ class UserTest < Test::Unit::TestCase
226
235
  </connect_registerUsers_response>
227
236
  XML
228
237
  end
229
- end
238
+
239
+ def has_app_permission_response_xml
240
+ <<-XML
241
+ <?xml version="1.0" encoding="UTF-8"?>
242
+ <users_hasAppPermission_response xmlns="http://api.facebook.com/1.0/"
243
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
244
+ xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</users_hasAppPermission_response>
245
+ XML
246
+ end
247
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djanowski-facebooker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Fowler