facebooker 1.0.29 → 1.0.30

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.
Files changed (39) hide show
  1. data/.autotest +15 -0
  2. data/Manifest.txt +129 -0
  3. data/Rakefile +2 -3
  4. data/examples/desktop_login.rb +14 -0
  5. data/facebooker.gemspec +43 -0
  6. data/lib/facebooker.rb +41 -39
  7. data/lib/facebooker/adapters/adapter_base.rb +3 -2
  8. data/lib/facebooker/adapters/bebo_adapter.rb +6 -4
  9. data/lib/facebooker/batch_request.rb +11 -10
  10. data/lib/facebooker/logging.rb +6 -13
  11. data/lib/facebooker/mobile.rb +2 -2
  12. data/lib/facebooker/model.rb +15 -13
  13. data/lib/facebooker/models/applicationproperties.rb +1 -1
  14. data/lib/facebooker/models/applicationrestrictions.rb +3 -3
  15. data/lib/facebooker/models/event.rb +2 -2
  16. data/lib/facebooker/models/friend_list.rb +2 -2
  17. data/lib/facebooker/models/group.rb +4 -4
  18. data/lib/facebooker/models/page.rb +3 -2
  19. data/lib/facebooker/models/photo.rb +2 -2
  20. data/lib/facebooker/models/user.rb +13 -5
  21. data/lib/facebooker/models/work_info.rb +3 -2
  22. data/lib/facebooker/rails/controller.rb +6 -1
  23. data/lib/facebooker/rails/facebook_request_fix.rb +12 -8
  24. data/lib/facebooker/rails/facebook_session_handling.rb +1 -2
  25. data/lib/facebooker/rails/facebook_url_rewriting.rb +14 -11
  26. data/lib/facebooker/rails/helpers.rb +4 -3
  27. data/lib/facebooker/rails/helpers/fb_connect.rb +8 -2
  28. data/lib/facebooker/rails/publisher.rb +36 -30
  29. data/lib/facebooker/session.rb +81 -73
  30. data/lib/facebooker/version.rb +1 -1
  31. data/test/facebooker/adapters_test.rb +23 -23
  32. data/test/facebooker/model_test.rb +10 -0
  33. data/test/facebooker/rails/publisher_test.rb +97 -88
  34. data/test/facebooker/rails_integration_test.rb +44 -43
  35. data/test/facebooker/session_test.rb +5 -5
  36. data/test/rack/facebook_test.rb +2 -3
  37. data/test/rails_test_helper.rb +14 -0
  38. data/test/test_helper.rb +5 -4
  39. metadata +31 -17
@@ -9,16 +9,9 @@ module Facebooker
9
9
  end
10
10
 
11
11
  module Logging
12
-
13
- def self.skip_api_logging=(val)
14
- @skip_api_logging=val
15
- end
16
-
17
- def self.skip_api_logging
18
- @skip_api_logging
19
- end
20
-
21
-
12
+ @skip_api_logging = nil
13
+ class << self; attr_accessor :skip_api_logging; end
14
+
22
15
  def self.log_fb_api(method, params)
23
16
  message = method # might customize later
24
17
  dump = format_fb_params(params)
@@ -36,11 +29,11 @@ module Facebooker
36
29
  log_info(message, exception)
37
30
  raise
38
31
  end
39
-
32
+
40
33
  def self.format_fb_params(params)
41
34
  params.map { |key,value| "#{key} = #{value}" }.join(', ')
42
35
  end
43
-
36
+
44
37
  def self.log_info(message, dump, seconds = 0)
45
38
  return unless Facebooker.logger
46
39
  log_message = "#{message} (#{seconds}) #{dump}"
@@ -48,4 +41,4 @@ module Facebooker
48
41
  end
49
42
 
50
43
  end
51
- end
44
+ end
@@ -3,12 +3,12 @@ module Facebooker
3
3
  def initialize(session)
4
4
  @session = session
5
5
  end
6
-
6
+
7
7
  # Used to determine whether the user identified by "uid" has enabled SMS for this application.
8
8
  def can_send(user)
9
9
  @session.post('facebook.sms.canSend', :uid => User.cast_to_facebook_id(user))
10
10
  end
11
-
11
+
12
12
  # Send the given message to the user.
13
13
  # See http://wiki.developers.facebook.com/index.php/Mobile
14
14
  def send(user, message)
@@ -1,6 +1,6 @@
1
1
  module Facebooker
2
2
  ##
3
- # helper methods primarily supporting the management of Ruby objects which are populatable via Hashes.
3
+ # helper methods primarily supporting the management of Ruby objects which are populatable via Hashes.
4
4
  # Since most Facebook API calls accept and return hashes of data (as XML), the Model module allows us to
5
5
  # directly populate a model's attributes given a Hash with matching key names.
6
6
  module Model
@@ -19,15 +19,15 @@ module Facebooker
19
19
  yield instance if block_given?
20
20
  instance
21
21
  end
22
-
22
+
23
23
  ##
24
- # Create a standard attr_writer and a populating_attr_reader
24
+ # Create a standard attr_writer and a populating_attr_reader
25
25
  def populating_attr_accessor(*symbols)
26
- attr_writer *symbols
27
- populating_attr_reader *symbols
26
+ attr_writer(*symbols)
27
+ populating_attr_reader(*symbols)
28
28
  end
29
29
 
30
- ##
30
+ ##
31
31
  # Create a reader that will attempt to populate the model if it has not already been populated
32
32
  def populating_attr_reader(*symbols)
33
33
  symbols.each do |symbol|
@@ -59,27 +59,29 @@ module Facebooker
59
59
  def hash_settable_writer(symbol, klass)
60
60
  define_method("#{symbol}=") do |value|
61
61
  instance_variable_set("@#{symbol}", value.kind_of?(Hash) ? klass.from_hash(value) : value)
62
- end
62
+ end
63
63
  end
64
64
 
65
65
  #
66
66
  # Declares an attribute named ::symbol:: which can be set with either a list of instances of ::klass::
67
- # or a list of Hashes which will be used to populate a new instance of ::klass::.
67
+ # or a list of Hashes which will be used to populate a new instance of ::klass::.
68
68
  def hash_settable_list_accessor(symbol, klass)
69
69
  attr_reader symbol
70
70
  hash_settable_list_writer(symbol, klass)
71
71
  end
72
-
72
+
73
73
  def hash_settable_list_writer(symbol, klass)
74
74
  define_method("#{symbol}=") do |list|
75
75
  instance_variable_set("@#{symbol}", list.map do |item|
76
76
  item.kind_of?(Hash) ? klass.from_hash(item) : item
77
77
  end)
78
78
  end
79
- end
79
+ end
80
80
 
81
81
  def id_is(attribute)
82
- class_eval <<-EOS
82
+ (file, line) = caller.first.split(':')
83
+
84
+ class_eval(<<-EOS, file, line.to_i)
83
85
  def #{attribute}=(value)
84
86
  @#{attribute} = value.to_i
85
87
  end
@@ -90,7 +92,7 @@ module Facebooker
90
92
  EOS
91
93
  end
92
94
  end
93
-
95
+
94
96
  ##
95
97
  # Centralized, error-checked place for a model to get the session to which it is bound.
96
98
  # Any Facebook API queries require a Session instance.
@@ -113,7 +115,7 @@ module Facebooker
113
115
  end
114
116
 
115
117
  def populated?
116
- !@populated.nil?
118
+ @populated
117
119
  end
118
120
 
119
121
  ##
@@ -33,7 +33,7 @@ module Facebooker
33
33
  :private_install, :installable, :privacy_url, :help_url, :see_all_url, :tos_url,
34
34
  :dev_mode, :preload_fql, :icon_url, :canvas_name, :logo_url, :connect_logo_url ]
35
35
 
36
- attr_accessor *FIELDS
36
+ attr_accessor(*FIELDS)
37
37
 
38
38
  end
39
39
  end
@@ -3,8 +3,8 @@ module Facebooker
3
3
  class ApplicationRestrictions
4
4
  include Model
5
5
  FIELDS = [ :age, :location, :age_distribution, :type ]
6
-
7
- attr_accessor *FIELDS
8
-
6
+
7
+ attr_accessor(*FIELDS)
8
+
9
9
  end
10
10
  end
@@ -21,8 +21,8 @@ module Facebooker
21
21
  end
22
22
 
23
23
  include Model
24
- attr_accessor :eid, :pic, :pic_small, :pic_big, :name, :creator, :update_time, :description, :tagline, :venue, :host, :event_type, :nid, :location, :end_time, :start_time, :event_subtype
24
+ attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :update_time, :description, :tagline, :venue, :host, :event_type, :nid, :location, :end_time, :start_time, :event_subtype
25
25
 
26
26
  id_is :eid
27
27
  end
28
- end
28
+ end
@@ -4,8 +4,8 @@ module Facebooker
4
4
  # A simple representation of a friend list.
5
5
  class FriendList
6
6
  include Model
7
- attr_accessor :flid, :name
8
-
7
+ attr_accessor :name
8
+
9
9
  id_is :flid
10
10
 
11
11
  # We need this to be an integer, so do the conversion
@@ -8,10 +8,10 @@ module Facebooker
8
8
  attr_accessor :position, :gid, :uid
9
9
  end
10
10
  include Model
11
- attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :recent_news, :gid, :update_time, :group_subtype, :group_type, :website, :office, :description, :venue, :nid
12
-
11
+ attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :recent_news, :update_time, :group_subtype, :group_type, :website, :office, :description, :venue, :nid
12
+
13
13
  id_is :gid
14
-
14
+
15
15
  ##
16
16
  # Get the full list of members as populated User objects. First time fetches group members via Facebook API call.
17
17
  # Subsequent calls return cached values.
@@ -33,4 +33,4 @@ module Facebooker
33
33
  end
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -5,7 +5,7 @@ module Facebooker
5
5
  class Genre
6
6
  include Model
7
7
  FIELDS = [ :dance, :party, :relax, :talk, :think, :workout, :sing, :intimate, :raunchy, :headphones ]
8
- attr_accessor *FIELDS
8
+ attr_accessor(*FIELDS)
9
9
 
10
10
  def initialize(*args)
11
11
  super
@@ -18,7 +18,8 @@ module Facebooker
18
18
  end
19
19
 
20
20
  include Model
21
- attr_accessor :page_id, :name, :pic_small, :pic_big, :pic_square, :pic_large, :type, :type, :website, :location, :hours, :band_members, :bio, :hometown, :genre, :record_label, :influences, :has_added_app, :founded, :company_overview, :mission, :products, :release_date, :starring, :written_by, :directed_by, :produced_by, :studio, :awards, :plot_outline, :network, :season, :schedule
21
+ attr_accessor :page_id, :name, :pic_small, :pic_big, :pic_square, :pic_large, :type, :type, :website, :location, :hours, :band_members, :bio, :hometown, :record_label, :influences, :has_added_app, :founded, :company_overview, :mission, :products, :release_date, :starring, :written_by, :directed_by, :produced_by, :studio, :awards, :plot_outline, :network, :season, :schedule
22
+ attr_reader :genre
22
23
 
23
24
  def genre=(value)
24
25
  @genre = value.kind_of?(Hash) ? Genre.from_hash(value) : value
@@ -2,11 +2,11 @@ require 'facebooker/model'
2
2
  module Facebooker
3
3
  class Photo
4
4
  include Model
5
- attr_accessor :pid, :aid, :owner, :title,
5
+ attr_accessor :aid, :owner, :title,
6
6
  :link, :caption, :created,
7
7
  :src, :src_big, :src_small,
8
8
  :story_fbid
9
9
 
10
10
  id_is :pid
11
11
  end
12
- end
12
+ end
@@ -10,22 +10,30 @@ module Facebooker
10
10
  include Model
11
11
  attr_accessor :message, :time, :status_id
12
12
  end
13
- 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, :uid, :work_history, :sex, :religion, :notes_count, :activities, :pic_square, :movies, :has_added_app, :education_history, :birthday, :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]
13
+ FIELDS = [: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, :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]
14
14
  STANDARD_FIELDS = [:uid, :first_name, :last_name, :name, :timezone, :birthday, :sex, :affiliations, :locale, :profile_url, :pic_square]
15
- populating_attr_accessor *FIELDS
15
+ populating_attr_accessor(*FIELDS)
16
16
  attr_reader :affiliations
17
17
  populating_hash_settable_accessor :current_location, Location
18
18
  populating_hash_settable_accessor :hometown_location, Location
19
19
  populating_hash_settable_accessor :hs_info, EducationInfo::HighschoolInfo
20
- populating_hash_settable_accessor :status, Status
21
20
  populating_hash_settable_list_accessor :affiliations, Affiliation
22
21
  populating_hash_settable_list_accessor :education_history, EducationInfo
23
22
  populating_hash_settable_list_accessor :work_history, WorkInfo
24
-
23
+
24
+ populating_attr_reader :status
25
+
25
26
  # Can pass in these two forms:
26
27
  # id, session, (optional) attribute_hash
27
28
  # attribute_hash
28
29
  def initialize(*args)
30
+ @friends = nil
31
+ @current_location = nil
32
+ @pic = nil
33
+ @hometown_location = nil
34
+ @populated = false
35
+ @session = nil
36
+ @id = nil
29
37
  if (args.first.kind_of?(String) || args.first.kind_of?(Integer)) && args.size==1
30
38
  self.uid = args.shift
31
39
  @session = Session.current
@@ -35,7 +43,7 @@ module Facebooker
35
43
  end
36
44
  if args.last.kind_of?(Hash)
37
45
  populate_from_hash!(args.pop)
38
- end
46
+ end
39
47
  end
40
48
 
41
49
  id_is :uid
@@ -1,9 +1,10 @@
1
1
  module Facebooker
2
2
  class WorkInfo
3
3
  include Model
4
- attr_accessor :end_date, :start_date, :company_name, :description, :position, :location
4
+ attr_accessor :end_date, :start_date, :company_name, :description, :position
5
+ attr_reader :location
5
6
  def location=(location)
6
7
  @location = location.kind_of?(Hash) ? Location.from_hash(location) : location
7
8
  end
8
9
  end
9
- end
10
+ end
@@ -12,7 +12,12 @@ module Facebooker
12
12
  controller.helper_method :request_comes_from_facebook?
13
13
  end
14
14
 
15
-
15
+ def initialize *args
16
+ @facebook_session = nil
17
+ @installation_required = nil
18
+ super
19
+ end
20
+
16
21
  def facebook_session
17
22
  @facebook_session
18
23
  end
@@ -1,16 +1,18 @@
1
1
  module ::ActionController
2
2
  class AbstractRequest
3
3
  def request_method_with_facebooker
4
- if parameters[:fb_sig_request_method]=="GET" and parameters[:_method].blank?
5
- parameters[:_method]="GET"
4
+ if parameters[:_method].blank?
5
+ if %w{GET HEAD}.include?(parameters[:fb_sig_request_method])
6
+ parameters[:_method] = parameters[:fb_sig_request_method]
7
+ end
6
8
  end
7
9
  request_method_without_facebooker
8
10
  end
9
-
11
+
10
12
  if new.methods.include?("request_method")
11
- alias_method_chain :request_method, :facebooker
13
+ alias_method_chain :request_method, :facebooker
12
14
  end
13
-
15
+
14
16
  def xml_http_request_with_facebooker?
15
17
  parameters["fb_sig_is_mockajax"] == "1" ||
16
18
  parameters["fb_sig_is_ajax"] == "1" ||
@@ -18,7 +20,9 @@ module ::ActionController
18
20
  end
19
21
  alias_method_chain :xml_http_request?, :facebooker
20
22
  # we have to re-alias xhr? since it was pointing to the old method
21
- alias xhr? :xml_http_request?
22
-
23
+ unless defined? :xhr?
24
+ alias xhr? :xml_http_request?
25
+ end
26
+
23
27
  end
24
- end
28
+ end
@@ -24,7 +24,6 @@ end
24
24
 
25
25
  class CGI
26
26
  class Session
27
- private
28
27
  alias :initialize_aliased_by_facebooker :initialize
29
28
  attr_reader :request, :initialization_options
30
29
 
@@ -66,4 +65,4 @@ class CGI
66
65
  @session_id || create_new_id_aliased_by_facebooker
67
66
  end
68
67
  end
69
- end
68
+ end
@@ -1,35 +1,38 @@
1
1
  module ::ActionController
2
2
  if Rails.version < '2.3'
3
- class AbstractRequest
3
+ class AbstractRequest
4
4
  def relative_url_root
5
5
  Facebooker.path_prefix
6
- end
6
+ end
7
7
  end
8
8
  else
9
- class Request
9
+ class Request
10
10
  def relative_url_root
11
11
  Facebooker.path_prefix
12
- end
12
+ end
13
13
  end
14
14
  end
15
-
15
+
16
16
  class Base
17
- def self.relative_url_root
18
- Facebooker.path_prefix
17
+ class << self
18
+ alias :old_relative_url_root :relative_url_root
19
+ def relative_url_root
20
+ Facebooker.path_prefix
21
+ end
19
22
  end
20
- end
21
-
23
+ end
24
+
22
25
  class UrlRewriter
23
26
  RESERVED_OPTIONS << :canvas
24
27
  def link_to_new_canvas?
25
- @request.parameters["fb_sig_in_new_facebook"] == "1"
28
+ @request.parameters["fb_sig_in_new_facebook"] == "1"
26
29
  end
27
30
  def link_to_canvas?(params, options)
28
31
  option_override = options[:canvas]
29
32
  return false if option_override == false # important to check for false. nil should use default behavior
30
33
  option_override || (can_safely_access_request_parameters? && (@request.parameters["fb_sig_in_canvas"] == "1" || @request.parameters[:fb_sig_in_canvas] == "1" ))
31
34
  end
32
-
35
+
33
36
  #rails blindly tries to merge things that may be nil into the parameters. Make sure this won't break
34
37
  def can_safely_access_request_parameters?
35
38
  @request.request_parameters
@@ -1,16 +1,17 @@
1
1
  require 'action_pack'
2
+
2
3
  module Facebooker
3
4
  module Rails
4
-
5
+
5
6
  # Facebook specific helpers for creating FBML
6
7
  #
7
8
  # All helpers that take a user as a parameter will get the Facebook UID from the facebook_id attribute if it exists.
8
9
  # It will use to_s if the facebook_id attribute is not present.
9
10
  #
10
11
  module Helpers
11
-
12
+
12
13
  include Facebooker::Rails::Helpers::FbConnect
13
-
14
+
14
15
  # Create an fb:dialog
15
16
  # id must be a unique name e.g. "my_dialog"
16
17
  # cancel_button is true or false
@@ -36,8 +36,14 @@ module Facebooker
36
36
  });
37
37
  FBML
38
38
  end
39
- if block_given? && block_is_within_action_view?(proc)
40
- concat(javascript_tag(init_string), proc.binding)
39
+
40
+ # block_is_within_action_view? is rails 2.1.x and has been
41
+ # deprecated. rails >= 2.2.x uses block_called_from_erb?
42
+ block_tester = respond_to?(:block_is_within_action_view?) ?
43
+ :block_is_within_action_view? : :block_called_from_erb?
44
+
45
+ if block_given? && send(block_tester, proc)
46
+ concat(javascript_tag(init_string))
41
47
  else
42
48
  javascript_tag init_string
43
49
  end