mmangino-facebooker 1.0.27 → 1.0.28

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,6 +68,9 @@ module Facebooker
68
68
  end
69
69
  return adapter_class.new(adapter_config)
70
70
  end
71
+
72
+ return self.default_adapter(params)
73
+
71
74
  end
72
75
 
73
76
  def self.default_adapter(params = {})
@@ -122,10 +122,12 @@ module Facebooker
122
122
  unless hash.nil? || hash.empty?
123
123
  hash.each do |key, value|
124
124
  set_attr_method = "#{key}="
125
- if !value.nil? && respond_to?(set_attr_method)
126
- self.__send__(set_attr_method, value)
127
- else
128
- Facebooker::Logging.log_info("**Warning**, Attempt to set non-attribute: #{key}",hash)
125
+ unless value.nil?
126
+ if respond_to?(set_attr_method)
127
+ self.__send__(set_attr_method, value)
128
+ else
129
+ Facebooker::Logging.log_info("**Warning**, Attempt to set non-attribute: #{key}",hash)
130
+ end
129
131
  end
130
132
  end
131
133
  @populated = true
@@ -384,22 +384,35 @@ module Facebooker
384
384
  end
385
385
 
386
386
 
387
- # Unregister a bunch of users
388
- def self.unregister(emails)
389
- emails = emails.collect {|e| hash_email(e)}
390
- Facebooker::Session.create.post("facebook.connect.unregisterUsers",:email_hashes=>emails.to_json) do |ret|
387
+ # Unregister an array of email hashes
388
+ def self.unregister(email_hashes)
389
+ Facebooker::Session.create.post("facebook.connect.unregisterUsers",:email_hashes=>email_hashes.to_json) do |ret|
391
390
  ret.each do |hash|
392
- emails.delete(hash)
391
+ email_hashes.delete(hash)
393
392
  end
394
- unless emails.empty?
393
+ unless email_hashes.empty?
395
394
  e=Facebooker::Session::UserUnRegistrationFailed.new
396
- e.failed_users = emails
395
+ e.failed_users = email_hashes
397
396
  raise e
398
397
  end
399
398
  ret
400
399
  end
401
400
  end
402
401
 
402
+ # unregister an array of email addresses
403
+ def self.unregister_emails(emails)
404
+ emails_hash = {}
405
+ emails.each {|e| emails_hash[hash_email(e)] = e}
406
+ begin
407
+ unregister(emails_hash.keys).collect {|r| emails_hash[r]}
408
+ rescue
409
+ # re-raise with emails instead of hashes.
410
+ e = Facebooker::Session::UserUnRegistrationFailed.new
411
+ e.failed_users = $!.failed_users.collect { |f| emails_hash[f] }
412
+ raise e
413
+ end
414
+ end
415
+
403
416
  def self.hash_email(email)
404
417
  email = email.downcase.strip
405
418
  crc=Zlib.crc32(email)
@@ -6,7 +6,7 @@ module Facebooker
6
6
  include Facebooker::Rails::ProfilePublisherExtensions
7
7
  def self.included(controller)
8
8
  controller.extend(ClassMethods)
9
- #controller.before_filter :set_adapter <-- security hole noted by vchu
9
+ controller.before_filter :set_adapter
10
10
  controller.before_filter :set_facebook_request_format
11
11
  controller.helper_attr :facebook_session_parameters
12
12
  controller.helper_method :request_comes_from_facebook?
@@ -54,7 +54,7 @@ module Facebooker
54
54
  def fb_login_button(*args)
55
55
 
56
56
  callback = args.first
57
- options = args.second || {}
57
+ options = args[1] || {}
58
58
  options.merge!(:onlogin=>callback)if callback
59
59
 
60
60
  content_tag("fb:login-button",nil, options)
@@ -282,8 +282,9 @@ module Facebooker
282
282
 
283
283
  # Render an <fb:profile-pic> for the specified user.
284
284
  #
285
- # You can optionally specify the size using the :size=> option.
286
- # Valid sizes are :thumb, :small, :normal and :square
285
+ # You can optionally specify the size using the :size=> option. Valid
286
+ # sizes are :thumb, :small, :normal and :square. Or, you can specify
287
+ # width and height settings instead, just like an img tag.
287
288
  #
288
289
  # You can optionally specify whether or not to include the facebook icon
289
290
  # overlay using the :facebook_logo => true option. Default is false.
@@ -298,7 +299,7 @@ module Facebooker
298
299
  end
299
300
 
300
301
  FB_PROFILE_PIC_OPTION_KEYS_TO_TRANSFORM = {:facebook_logo => 'facebook-logo'}
301
- FB_PROFILE_PIC_VALID_OPTION_KEYS = [:size, :linked, 'facebook-logo']
302
+ FB_PROFILE_PIC_VALID_OPTION_KEYS = [:size, :linked, 'facebook-logo', :width, :height]
302
303
 
303
304
 
304
305
  # Render an fb:photo tag.
@@ -2,7 +2,7 @@ module Facebooker #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 27
5
+ TINY = 28
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/facebooker.rb CHANGED
@@ -28,27 +28,34 @@ module Facebooker
28
28
  def load_configuration(facebooker_yaml_file)
29
29
  if File.exist?(facebooker_yaml_file)
30
30
  if defined? RAILS_ENV
31
- facebooker = YAML.load_file(facebooker_yaml_file)[RAILS_ENV]
31
+ config = YAML.load_file(facebooker_yaml_file)[RAILS_ENV]
32
32
  else
33
- facebooker = YAML.load_file(facebooker_yaml_file)
33
+ config = YAML.load_file(facebooker_yaml_file)
34
34
  end
35
- ENV['FACEBOOK_API_KEY'] = facebooker['api_key']
36
- ENV['FACEBOOK_SECRET_KEY'] = facebooker['secret_key']
37
- ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = facebooker['canvas_page_name']
38
- ENV['FACEBOOKER_API'] = facebooker['api']
39
- if facebooker.has_key?('set_asset_host_to_callback_url')
40
- Facebooker.set_asset_host_to_callback_url = facebooker['set_asset_host_to_callback_url']
41
- end
42
- Facebooker.timeout = facebooker['timeout']
43
- if Object.const_defined?("ActionController")
44
- ActionController::Base.asset_host = facebooker['callback_url'] if(ActionController::Base.asset_host.blank?) && Facebooker.set_asset_host_to_callback_url
45
- end
46
- @facebooker_configuration = facebooker
35
+ apply_configuration(config)
36
+ end
37
+ end
38
+
39
+ # Sets the Facebook environment based on a hash of options.
40
+ # By default the hash passed in is loaded from facebooker.yml, but it can also be passed in
41
+ # manually every request to run multiple Facebook apps off one Rails app.
42
+ def apply_configuration(config)
43
+ ENV['FACEBOOK_API_KEY'] = config['api_key']
44
+ ENV['FACEBOOK_SECRET_KEY'] = config['secret_key']
45
+ ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = config['canvas_page_name']
46
+ ENV['FACEBOOKER_API'] = config['api']
47
+ if config.has_key?('set_asset_host_to_callback_url')
48
+ Facebooker.set_asset_host_to_callback_url = config['set_asset_host_to_callback_url']
49
+ end
50
+ if Object.const_defined?("ActionController") and Facebooker.set_asset_host_to_callback_url
51
+ ActionController::Base.asset_host = config['callback_url']
47
52
  end
53
+ Facebooker.timeout = config['timeout']
54
+ @facebooker_configuration = config
48
55
  end
49
56
 
50
57
  def facebooker_config
51
- @facebooker_configuration
58
+ @facebooker_configuration || {} # to prevent pretty_errors error if the config hasn't been set yet
52
59
  end
53
60
 
54
61
  def current_adapter=(adapter_class)
@@ -185,6 +185,16 @@ class Facebooker::UserTest < Test::Unit::TestCase
185
185
  assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.register([{:email=>"mary@example.com",:account_id=>1}])
186
186
  end
187
187
 
188
+ def test_unregister_with_array
189
+ expect_http_posts_with_responses(unregister_response_xml)
190
+ assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.unregister(["4228600737_c96da02bba97aedfd26136e980ae3761"])
191
+ end
192
+
193
+ def test_unregister_emails_with_array
194
+ expect_http_posts_with_responses(unregister_response_xml)
195
+ assert_equal ["mary@example.com"],Facebooker::User.unregister_emails(["mary@example.com"])
196
+ end
197
+
188
198
  def test_register_with_array_raises_if_not_all_success
189
199
  expect_http_posts_with_responses(register_response_xml)
190
200
  assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.register([{:email=>"mary@example.com",:account_id=>1},{:email=>"mike@example.com",:account_id=>2}])
@@ -193,6 +203,23 @@ class Facebooker::UserTest < Test::Unit::TestCase
193
203
  assert_equal({:email=>"mike@example.com",:account_id=>2},e.failed_users.first)
194
204
  end
195
205
 
206
+ def test_unregister_with_array_raises_if_not_all_success
207
+ expect_http_posts_with_responses(unregister_response_xml)
208
+ assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.unregister(["4228600737_c96da02bba97aedfd26136e980ae3761","3587916587_791214eb452bf4de30e957d65a0234d4"])
209
+ fail "Should have raised Facebooker::Session::UserUnRegistrationFailed"
210
+ rescue Facebooker::Session::UserUnRegistrationFailed => e
211
+ assert_equal("3587916587_791214eb452bf4de30e957d65a0234d4",e.failed_users.first)
212
+ end
213
+
214
+ def test_unregister_emails_with_array_raises_if_not_all_success
215
+ expect_http_posts_with_responses(unregister_response_xml)
216
+ assert_equal ["mary@example.com"],Facebooker::User.unregister_emails(["mary@example.com","mike@example.com"])
217
+ fail "Should have raised Facebooker::Session::UserUnRegistrationFailed"
218
+ rescue Facebooker::Session::UserUnRegistrationFailed => e
219
+ assert_equal("mike@example.com",e.failed_users.first)
220
+ end
221
+
222
+
196
223
  def test_get_locale
197
224
  @user = Facebooker::User.new(9507801, @session)
198
225
  expect_http_posts_with_responses(example_users_get_info_xml)
@@ -283,6 +310,15 @@ class Facebooker::UserTest < Test::Unit::TestCase
283
310
  XML
284
311
  end
285
312
 
313
+ def unregister_response_xml
314
+ <<-XML
315
+ <?xml version="1.0" encoding="UTF-8"?>
316
+ <connect_unregisterUsers_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/facebook.xsd" list="true">
317
+ <connect_unregisterUsers_response_elt>4228600737_c96da02bba97aedfd26136e980ae3761</connect_unregisterUsers_response_elt>
318
+ </connect_unregisterUsers_response>
319
+ XML
320
+ end
321
+
286
322
  def has_app_permission_response_xml
287
323
  <<-XML
288
324
  <?xml version="1.0" encoding="UTF-8"?>
@@ -590,6 +590,10 @@ class RailsHelperTest < Test::Unit::TestCase
590
590
  assert_equal "<fb:profile-pic size=\"small\" uid=\"1234\"></fb:profile-pic>", @h.fb_profile_pic("1234", :size => :small)
591
591
  end
592
592
 
593
+ def test_fb_profile_pic_with_width_and_height
594
+ assert_equal "<fb:profile-pic height=\"200\" uid=\"1234\" width=\"100\"></fb:profile-pic>", @h.fb_profile_pic("1234", :width => 100, :height => 200)
595
+ end
596
+
593
597
  def test_fb_profile_pic_with_invalid_size
594
598
  assert_raises(ArgumentError) {@h.fb_profile_pic("1234", :size => :mediumm)}
595
599
  end
@@ -1118,30 +1122,28 @@ class RailsPrettyErrorsTest < Test::Unit::TestCase
1118
1122
  end
1119
1123
 
1120
1124
  def setup
1125
+ Facebooker.apply_configuration('api_key'=>"1234", 'secret_key'=>"34278",'canvas_page_name'=>'mike','pretty_errors'=>true)
1121
1126
  @controller = ControllerWhichFails.new
1122
1127
  @request = ActionController::TestRequest.new
1123
1128
  @response = ActionController::TestResponse.new
1124
1129
  end
1125
1130
 
1126
1131
  def test_pretty_errors_disabled_success
1127
- Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(false)
1128
1132
  post :pass, facebook_params
1129
1133
  assert_response 200
1130
1134
  end
1131
1135
 
1132
1136
  def test_pretty_errors_disabled_error
1133
- Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(false)
1137
+ Facebooker.apply_configuration('api_key'=>"1234", 'secret_key'=>"34278",'canvas_page_name'=>'mike','pretty_errors'=>false)
1134
1138
  post :fail, facebook_params
1135
1139
  assert_response :error
1136
1140
  end
1137
1141
 
1138
1142
  def test_pretty_errors_enabled_success
1139
- Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(true)
1140
1143
  post :pass, facebook_params
1141
1144
  assert_response 200
1142
1145
  end
1143
1146
  def test_pretty_errors_enabled_error
1144
- Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(true)
1145
1147
  post :fail, facebook_params
1146
1148
  assert_response 200
1147
1149
  end
@@ -1301,6 +1303,9 @@ class RailsRequestFormatTest < Test::Unit::TestCase
1301
1303
  end
1302
1304
 
1303
1305
  def setup
1306
+ ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
1307
+ ENV['FACEBOOK_API_KEY'] = '1234567'
1308
+ ENV['FACEBOOK_SECRET_KEY'] = '7654321'
1304
1309
  @controller = FacebookController.new
1305
1310
  @request = ActionController::TestRequest.new
1306
1311
  @response = ActionController::TestResponse.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmangino-facebooker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.27
4
+ version: 1.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Fowler
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2009-04-07 00:00:00 -07:00
16
+ date: 2009-04-14 00:00:00 -07:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency