mmangino-facebooker 1.0.45 → 1.0.46

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #
2
+ #
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
  begin
@@ -8,19 +8,24 @@ rescue LoadError
8
8
  $stderr.puts "Install the multi_rails gem to run tests against multiple versions of Rails"
9
9
  end
10
10
 
11
- $: << File.dirname(__FILE__) + '/lib'
12
- require './lib/facebooker.rb'
11
+ require 'lib/facebooker/version'
12
+
13
+ HOE = Hoe.spec('facebooker') do
14
+ self.version = Facebooker::VERSION::STRING
15
+ self.rubyforge_name = 'facebooker'
16
+ developer 'Chad Fowler', 'chad@chadfowlwer.com'
17
+ developer 'Patrick Ewing', ''
18
+ developer 'Mike Mangino', ''
19
+ developer 'Shane Vitarana', ''
20
+ developer 'Corey Innis', ''
21
+ developer 'Mike Mangino', 'mmangino@elevatedrails.com'
13
22
 
14
- HOE = Hoe.new('facebooker', Facebooker::VERSION::STRING) do |p|
15
- p.rubyforge_name = 'facebooker'
16
- p.author = ['Chad Fowler', 'Patrick Ewing', 'Mike Mangino', 'Shane Vitarana', 'Corey Innis']
17
- p.email = 'mmangino@elevatedrails.com'
18
- p.readme_file = 'README.rdoc'
19
- p.history_file = 'CHANGELOG.rdoc'
20
- p.remote_rdoc_dir = '' # Release to root
21
- p.test_globs = 'test/**/*_test.rb'
22
- p.extra_deps << ['json', '>= 1.0.0']
23
- p.extra_rdoc_files = FileList['*.rdoc']
23
+ self.readme_file = 'README.rdoc'
24
+ self.history_file = 'CHANGELOG.rdoc'
25
+ self.remote_rdoc_dir = '' # Release to root
26
+ self.test_globs = 'test/**/*_test.rb'
27
+ extra_deps << ['json', '>= 1.0.0']
28
+ self.extra_rdoc_files = FileList['*.rdoc']
24
29
  end
25
30
 
26
31
  require 'rcov/rcovtask'
data/facebooker.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{facebooker}
5
- s.version = "1.0.45"
5
+ s.version = "1.0.46"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Chad Fowler", "Patrick Ewing", "Mike Mangino", "Shane Vitarana", "Corey Innis"]
9
- s.date = %q{2009-07-24}
8
+ s.authors = ["Chad Fowler", "Patrick Ewing", "Mike Mangino", "Shane Vitarana", "Corey Innis", "Mike Mangino"]
9
+ s.date = %q{2009-08-14}
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
13
13
  * No dependencies outside of the Ruby standard library (This is true with Rails 2.1. Previous Rails versions require the JSON gem)
14
14
  * Concrete classes and methods modeling the Facebook data, so it's easy for a Rubyist to understand what's available
15
15
  * Well tested}
16
- s.email = %q{mmangino@elevatedrails.com}
16
+ s.email = ["chad@chadfowlwer.com", "", "", "", "", "mmangino@elevatedrails.com"]
17
17
  s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "COPYING.rdoc", "README.rdoc", "TODO.rdoc"]
18
18
  s.files = [".autotest", "CHANGELOG.rdoc", "COPYING.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "TODO.rdoc", "examples/desktop_login.rb", "facebooker.gemspec", "generators/facebook/facebook_generator.rb", "generators/facebook/templates/config/facebooker.yml", "generators/facebook/templates/public/javascripts/facebooker.js", "generators/facebook_controller/USAGE", "generators/facebook_controller/facebook_controller_generator.rb", "generators/facebook_controller/templates/controller.rb", "generators/facebook_controller/templates/functional_test.rb", "generators/facebook_controller/templates/helper.rb", "generators/facebook_controller/templates/view.fbml.erb", "generators/facebook_controller/templates/view.html.erb", "generators/facebook_publisher/facebook_publisher_generator.rb", "generators/facebook_publisher/templates/create_facebook_templates.rb", "generators/facebook_publisher/templates/publisher.rb", "generators/facebook_scaffold/USAGE", "generators/facebook_scaffold/facebook_scaffold_generator.rb", "generators/facebook_scaffold/templates/controller.rb", "generators/facebook_scaffold/templates/facebook_style.css", "generators/facebook_scaffold/templates/functional_test.rb", "generators/facebook_scaffold/templates/helper.rb", "generators/facebook_scaffold/templates/layout.fbml.erb", "generators/facebook_scaffold/templates/layout.html.erb", "generators/facebook_scaffold/templates/style.css", "generators/facebook_scaffold/templates/view_edit.fbml.erb", "generators/facebook_scaffold/templates/view_edit.html.erb", "generators/facebook_scaffold/templates/view_index.fbml.erb", "generators/facebook_scaffold/templates/view_index.html.erb", "generators/facebook_scaffold/templates/view_new.fbml.erb", "generators/facebook_scaffold/templates/view_new.html.erb", "generators/facebook_scaffold/templates/view_show.fbml.erb", "generators/facebook_scaffold/templates/view_show.html.erb", "generators/publisher/publisher_generator.rb", "generators/xd_receiver/templates/xd_receiver.html", "generators/xd_receiver/xd_receiver_generator.rb", "init.rb", "install.rb", "lib/facebooker.rb", "lib/facebooker/adapters/adapter_base.rb", "lib/facebooker/adapters/bebo_adapter.rb", "lib/facebooker/adapters/facebook_adapter.rb", "lib/facebooker/admin.rb", "lib/facebooker/batch_request.rb", "lib/facebooker/data.rb", "lib/facebooker/feed.rb", "lib/facebooker/logging.rb", "lib/facebooker/mobile.rb", "lib/facebooker/mock/service.rb", "lib/facebooker/mock/session.rb", "lib/facebooker/model.rb", "lib/facebooker/models/affiliation.rb", "lib/facebooker/models/album.rb", "lib/facebooker/models/applicationproperties.rb", "lib/facebooker/models/applicationrestrictions.rb", "lib/facebooker/models/cookie.rb", "lib/facebooker/models/education_info.rb", "lib/facebooker/models/event.rb", "lib/facebooker/models/friend_list.rb", "lib/facebooker/models/group.rb", "lib/facebooker/models/info_item.rb", "lib/facebooker/models/info_section.rb", "lib/facebooker/models/location.rb", "lib/facebooker/models/notifications.rb", "lib/facebooker/models/page.rb", "lib/facebooker/models/photo.rb", "lib/facebooker/models/tag.rb", "lib/facebooker/models/user.rb", "lib/facebooker/models/video.rb", "lib/facebooker/models/work_info.rb", "lib/facebooker/parser.rb", "lib/facebooker/rails/backwards_compatible_param_checks.rb", "lib/facebooker/rails/controller.rb", "lib/facebooker/rails/cucumber.rb", "lib/facebooker/rails/cucumber/world.rb", "lib/facebooker/rails/extensions/action_controller.rb", "lib/facebooker/rails/extensions/rack_setup.rb", "lib/facebooker/rails/extensions/routing.rb", "lib/facebooker/rails/facebook_form_builder.rb", "lib/facebooker/rails/facebook_pretty_errors.rb", "lib/facebooker/rails/facebook_request_fix.rb", "lib/facebooker/rails/facebook_request_fix_2-3.rb", "lib/facebooker/rails/facebook_session_handling.rb", "lib/facebooker/rails/facebook_url_helper.rb", "lib/facebooker/rails/facebook_url_rewriting.rb", "lib/facebooker/rails/helpers.rb", "lib/facebooker/rails/helpers/fb_connect.rb", "lib/facebooker/rails/integration_session.rb", "lib/facebooker/rails/profile_publisher_extensions.rb", "lib/facebooker/rails/publisher.rb", "lib/facebooker/rails/routing.rb", "lib/facebooker/rails/test_helpers.rb", "lib/facebooker/rails/utilities.rb", "lib/facebooker/server_cache.rb", "lib/facebooker/service.rb", "lib/facebooker/service/base_service.rb", "lib/facebooker/service/curl_service.rb", "lib/facebooker/service/net_http_service.rb", "lib/facebooker/service/typhoeus_service.rb", "lib/facebooker/service/typhoeus_multi_service.rb", "lib/facebooker/session.rb", "lib/facebooker/version.rb", "lib/net/http_multipart_post.rb", "lib/rack/facebook.rb", "lib/tasks/facebooker.rake", "lib/tasks/tunnel.rake", "rails/init.rb", "setup.rb", "templates/layout.erb", "test/facebooker/adapters_test.rb", "test/facebooker/admin_test.rb", "test/facebooker/batch_request_test.rb", "test/facebooker/data_test.rb", "test/facebooker/logging_test.rb", "test/facebooker/mobile_test.rb", "test/facebooker/model_test.rb", "test/facebooker/models/event_test.rb", "test/facebooker/models/page_test.rb", "test/facebooker/models/photo_test.rb", "test/facebooker/models/user_test.rb", "test/facebooker/rails/publisher_test.rb", "test/facebooker/rails_integration_test.rb", "test/facebooker/rails/facebook_request_fix_2-3_test.rb", "test/facebooker/server_cache_test.rb", "test/facebooker/session_test.rb", "test/facebooker_test.rb", "test/fixtures/multipart_post_body_with_only_parameters.txt", "test/fixtures/multipart_post_body_with_single_file.txt", "test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt", "test/net/http_multipart_post_test.rb", "test/rack/facebook_test.rb", "test/rails_test_helper.rb", "test/test_helper.rb", "test/facebooker/rails/facebook_url_rewriting_test.rb", "test/facebooker/rails/integration_session_test.rb", "test/facebooker/service_test.rb"]
19
19
  s.homepage = %q{http://facebooker.rubyforge.org}
@@ -1,6 +1,6 @@
1
1
  module Facebooker
2
2
  class BatchRequest
3
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^respond_to\?$|^new$)/ }
3
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^respond_to\?$|^new|object_id$)/ }
4
4
  attr_reader :uri
5
5
  attr_reader :method
6
6
  class UnexecutedRequest < StandardError; end
@@ -26,7 +26,7 @@ module Facebooker
26
26
  end
27
27
 
28
28
  include Model
29
- 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
29
+ attr_accessor :page_id, :name, :pic_small, :pic_big, :pic_square, :pic_large, :page_url, :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
30
30
  attr_reader :genre
31
31
 
32
32
  def genre=(value)
@@ -104,6 +104,11 @@ module Facebooker
104
104
  @friends_hash[cache_key]
105
105
  end
106
106
 
107
+ def friend_ids
108
+ options = {:uid => self.id}
109
+ @session.post('facebook.friends.get', options, false)
110
+ end
111
+
107
112
  ###
108
113
  # Publish a post into the stream on the user's Wall and News Feed. This
109
114
  # post also appears in the user's friend's streams. The +publish_stream+
@@ -123,12 +128,16 @@ module Facebooker
123
128
  # :href => 'http://tenderlovemaking.com/'
124
129
  # ])
125
130
  def publish_to target, options = {}
131
+
132
+ attachment = options[:attachment]
133
+ links = options[:action_links]
126
134
  @session.post('facebook.stream.publish',
127
- :uid => self.id,
128
- :target_id => target.id,
129
- :message => options[:message],
130
- :attachment => Facebooker.json_encode(options[:attachment]),
131
- :action_links => Facebooker.json_encode(options[:action_links])
135
+ { :uid => self.id,
136
+ :target_id => target.id,
137
+ :message => options[:message],
138
+ :attachment => attachment && Facebooker.json_encode(attachment),
139
+ :action_links => links && Facebooker.json_encode(links) },
140
+ false
132
141
  )
133
142
  end
134
143
 
@@ -176,10 +185,14 @@ module Facebooker
176
185
  end
177
186
 
178
187
  def friends_with_this_app
179
- @friends_with_this_app ||= session.post('facebook.friends.getAppUsers').map do |uid|
188
+ @friends_with_this_app ||= friend_ids_with_this_app.map do |uid|
180
189
  User.new(uid, session)
181
190
  end
182
191
  end
192
+
193
+ def friend_ids_with_this_app
194
+ @friend_ids_with_this_app ||= session.post('facebook.friends.getAppUsers')
195
+ end
183
196
 
184
197
  def groups(gids = [])
185
198
  args = gids.empty? ? {} : {:gids => gids}
@@ -361,7 +374,7 @@ module Facebooker
361
374
  ##
362
375
  # Checks to see if the user has enabled the given extended permission
363
376
  def has_permission?(ext_perm) # ext_perm = email, offline_access, status_update, photo_upload, create_listing, create_event, rsvp_event, sms
364
- session.post('facebook.users.hasAppPermission',:ext_perm=>ext_perm) == "1"
377
+ session.post('facebook.users.hasAppPermission', {:ext_perm=>ext_perm, :uid => uid}, false) == "1"
365
378
  end
366
379
 
367
380
  ##
@@ -58,14 +58,14 @@ module Facebooker
58
58
  def self.element(name, data)
59
59
  data = data.body rescue data # either data or an HTTP response
60
60
  begin
61
- xml = Nokogiri::XML(data.strip).at(name)
61
+ xml = Nokogiri::XML(data.strip)
62
62
  if node = xml.at(name)
63
63
  return node
64
64
  end
65
65
  if xml.root.name == name
66
66
  return xml.root
67
67
  end
68
- rescue # Can't parse with Nokogiri
68
+ rescue NameError # Can't parse with Nokogiri
69
69
  doc = REXML::Document.new(data)
70
70
  doc.elements.each(name) do |element|
71
71
  return element
@@ -413,18 +413,19 @@ module Facebooker
413
413
  class FqlMultiquery < Parser#nodoc
414
414
  def self.process(data)
415
415
  root = element('fql_multiquery_response', data)
416
- root.elements.collect do |elm|
417
- [
418
- elm.elements[1].text,
419
- if elm.elements[2].elements[1].nil?
420
- []
416
+ root.children.reject { |child| child.text? }.map do |elm|
417
+ elm.children.reject { |child| child.text? }.map do |query|
418
+ if 'name' == query.name
419
+ query.text
421
420
  else
422
- [
423
- elm.elements[2].elements[1].name,
424
- array_of_hashes(elm.elements[2], elm.elements[2].elements[1].name)
425
- ]
421
+ list = query.children.reject { |child| child.text? }
422
+ if list.length == 0
423
+ []
424
+ else
425
+ [list.first.name, array_of_hashes(query, list.first.name)]
426
+ end
426
427
  end
427
- ]
428
+ end
428
429
  end
429
430
  end
430
431
  end
@@ -16,7 +16,7 @@ module Facebooker::Rails::BackwardsCompatibleParamChecks
16
16
  def zero_or_false( value )
17
17
  case value
18
18
  when String then
19
- value == "0"
19
+ value.empty? || value == "0"
20
20
  when Numeric then
21
21
  value.to_f == 0.0
22
22
  when FalseClass then
@@ -205,10 +205,6 @@ module Facebooker
205
205
  end
206
206
  end
207
207
  end
208
-
209
- def blank?(value)
210
- (value == '0' || value.nil? || value == '')
211
- end
212
208
 
213
209
  def verified_facebook_params
214
210
  facebook_sig_params = params.inject({}) do |collection, pair|
@@ -229,12 +225,11 @@ module Facebooker
229
225
 
230
226
  def verify_signature(facebook_sig_params,expected_signature)
231
227
  # Don't verify the signature if rack has already done so.
232
- if ::Rails.version >= "2.3"
233
- return if ActionController::Dispatcher.middleware.include? Rack::Facebook
228
+ unless ::Rails.version >= "2.3" and ActionController::Dispatcher.middleware.include? Rack::Facebook
229
+ raw_string = facebook_sig_params.map{ |*args| args.join('=') }.sort.join
230
+ actual_sig = Digest::MD5.hexdigest([raw_string, Facebooker::Session.secret_key].join)
231
+ raise Facebooker::Session::IncorrectSignature if actual_sig != expected_signature
234
232
  end
235
- raw_string = facebook_sig_params.map{ |*args| args.join('=') }.sort.join
236
- actual_sig = Digest::MD5.hexdigest([raw_string, Facebooker::Session.secret_key].join)
237
- raise Facebooker::Session::IncorrectSignature if actual_sig != expected_signature
238
233
  raise Facebooker::Session::SignatureTooOld if facebook_sig_params['time'] && Time.at(facebook_sig_params['time'].to_f) < earliest_valid_session
239
234
  true
240
235
  end
@@ -243,11 +238,11 @@ module Facebooker
243
238
  @facebook_parameter_conversions ||= Hash.new do |hash, key|
244
239
  lambda{|value| value}
245
240
  end.merge(
246
- 'time' => lambda{|value| Time.at(value.to_f)},
247
- 'in_canvas' => lambda{|value| !blank?(value)},
248
- 'added' => lambda{|value| !blank?(value)},
249
- 'expires' => lambda{|value| blank?(value) ? nil : Time.at(value.to_f)},
250
- 'friends' => lambda{|value| value.split(/,/)}
241
+ 'time' => lambda{|value| Time.at(value.to_f)},
242
+ 'in_canvas' => lambda{|value| one_or_true(value)},
243
+ 'added' => lambda{|value| one_or_true(value)},
244
+ 'expires' => lambda{|value| zero_or_false(value) ? nil : Time.at(value.to_f)},
245
+ 'friends' => lambda{|value| value.split(/,/)}
251
246
  )
252
247
  end
253
248
 
@@ -3,11 +3,13 @@ module Facebooker
3
3
  module Helpers
4
4
  module FbConnect
5
5
 
6
- def fb_connect_javascript_tag
6
+ def fb_connect_javascript_tag(options = {})
7
+ lang = "/#{options[:lang]}" if options[:lang]
8
+ # dont use the javascript_include_tag helper since it adds a .js at the end
7
9
  if request.ssl?
8
- javascript_include_tag "https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
10
+ "<script src=\"https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php#{lang}\" type=\"text/javascript\"></script>"
9
11
  else
10
- javascript_include_tag "http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
12
+ "<script src=\"http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php#{lang}\" type=\"text/javascript\"></script>"
11
13
  end
12
14
  end
13
15
 
@@ -739,6 +739,57 @@ module Facebooker
739
739
  tag "fb:time",stringify_vals({:t => time.to_i}.merge(options))
740
740
  end
741
741
 
742
+ # Renders a fb:intl element
743
+ #
744
+ # Example:
745
+ # <%= fb_intl('Age', :desc => 'Label for the age form field', :delimiters => '[]') %>
746
+ #
747
+ # See http://wiki.developers.facebook.com/index.php/Fb:intl for
748
+ # more details
749
+ def fb_intl(text=nil, options={}, &proc)
750
+ raise ArgumentError, "Missing block or text" unless block_given? or text
751
+ content = block_given? ? capture(&proc) : text
752
+ content_tag("fb:intl", content, stringify_vals(options))
753
+ end
754
+
755
+ # Renders a fb:intl-token element
756
+ #
757
+ # Example:
758
+ # <%= fb_intl-token('number', 5) %>
759
+ #
760
+ # See http://wiki.developers.facebook.com/index.php/Fb:intl-token for
761
+ # more details
762
+ def fb_intl_token(name, text=nil, &proc)
763
+ raise ArgumentError, "Missing block or text" unless block_given? or text
764
+ content = block_given? ? capture(&proc) : text
765
+ content_tag("fb:intl-token", content, stringify_vals({:name => name}))
766
+ end
767
+
768
+ # Renders a fb:date element
769
+ #
770
+ # Example:
771
+ # <%= fb_date(Time.now, :format => 'verbose', :tz => 'America/New York') %>
772
+ #
773
+ # See http://wiki.developers.facebook.com/index.php/Fb:date for
774
+ # more details
775
+ def fb_date(time, options={})
776
+ tag "fb:date", stringify_vals({:t => time.to_i}.merge(options))
777
+ end
778
+
779
+ # Renders a fb:fbml-attribute element
780
+ #
781
+ # Example:
782
+ # <%= fb_fbml_attribute('title', Education) %>
783
+ #
784
+ # The options hash is passed to the fb:intl element that is generated inside this element
785
+ # and can have the keys available for the fb:intl element.
786
+ #
787
+ # See http://wiki.developers.facebook.com/index.php/Fb:fbml-attribute for
788
+ # more details
789
+ def fb_fbml_attribute(name, text, options={})
790
+ content_tag("fb:fbml-attribute", fb_intl(text, options), stringify_vals({:name => name}))
791
+ end
792
+
742
793
  protected
743
794
 
744
795
  def cast_to_facebook_id(object)
@@ -101,10 +101,14 @@ module Facebooker
101
101
  @controller = PublisherController.new(self)
102
102
  end
103
103
 
104
- def default_url_options
104
+ def self.default_url_options
105
105
  {:host => Facebooker.canvas_server_base + Facebooker.facebook_path_prefix}
106
106
  end
107
107
 
108
+ def default_url_options
109
+ self.class.default_url_options
110
+ end
111
+
108
112
  # use facebook options everywhere
109
113
  def request_comes_from_facebook?
110
114
  true
@@ -126,6 +130,13 @@ module Facebooker
126
130
  end
127
131
  end
128
132
 
133
+ def deactivate
134
+ Facebooker::Session.create.deactivate_template_bundle_by_id(self.bundle_id)
135
+ return true
136
+ rescue Facebooker::Session::TemplateBundleInvalid => e
137
+ return false
138
+ end
139
+
129
140
 
130
141
 
131
142
  class << self
@@ -134,6 +145,7 @@ module Facebooker
134
145
  publisher = setup_publisher(klass,method)
135
146
  template_id = Facebooker::Session.create.register_template_bundle(publisher.one_line_story_templates,publisher.short_story_templates,publisher.full_story_template,publisher.action_links)
136
147
  template = find_or_initialize_by_template_name(template_name(klass,method))
148
+ template.deactivate if template.bundle_id # deactivate old templates to avoid exceeding templates/app limit
137
149
  template.bundle_id = template_id
138
150
  template.content_hash = hashed_content(klass,method) if template.respond_to?(:content_hash)
139
151
  template.save!
@@ -162,12 +174,8 @@ module Facebooker
162
174
 
163
175
  def find_in_db(klass,method)
164
176
  template = find_by_template_name(template_name(klass,method))
165
- if template and template.template_changed?(hashed_content(klass,method))
166
- template.destroy
167
- template = nil
168
- end
169
177
 
170
- if template.nil?
178
+ if template.nil? || template.template_changed?(hashed_content(klass, method))
171
179
  template = register(klass,method)
172
180
  end
173
181
  template
@@ -462,6 +470,13 @@ module Facebooker
462
470
  ActionController::Routing::Routes.named_routes.install(self.master_helper_module)
463
471
  include self.master_helper_module
464
472
  class <<self
473
+
474
+ def register_all_templates_on_all_applications
475
+ Facebooker.with_all_applications do
476
+ puts "Registering templates for #{Facebooker.api_key}"
477
+ register_all_templates
478
+ end
479
+ end
465
480
 
466
481
  def register_all_templates
467
482
  all_templates = instance_methods.grep(/_template$/) - %w(short_story_template full_story_template one_line_story_template)
@@ -6,6 +6,7 @@ class Facebooker::Service::BaseService
6
6
  def post_params(params)
7
7
  post_params = {}
8
8
  params.each do |k,v|
9
+ k = k.to_s unless k.is_a?(String)
9
10
  if Array === v || Hash === v
10
11
  post_params[k] = Facebooker.json_encode(v)
11
12
  else
@@ -15,4 +16,4 @@ class Facebooker::Service::BaseService
15
16
  post_params
16
17
  end
17
18
 
18
- end
19
+ end
@@ -100,11 +100,11 @@ module Facebooker
100
100
 
101
101
  def login_url(options={})
102
102
  options = default_login_url_options.merge(options)
103
- "#{Facebooker.login_url_base(@api_key)}#{login_url_optional_parameters(options)}"
103
+ "#{Facebooker.login_url_base}#{login_url_optional_parameters(options)}"
104
104
  end
105
105
 
106
106
  def install_url(options={})
107
- "#{Facebooker.install_url_base(@api_key)}#{install_url_optional_parameters(options)}"
107
+ "#{Facebooker.install_url_base}#{install_url_optional_parameters(options)}"
108
108
  end
109
109
 
110
110
  # The url to get user to approve extended permissions
@@ -414,6 +414,14 @@ module Facebooker
414
414
  post("facebook.feed.registerTemplateBundle", parameters, false)
415
415
  end
416
416
 
417
+ ##
418
+ # Deactivate a template bundle with Facebook.
419
+ # Returns true if a bundle with the specified id is active and owned by this app.
420
+ # Useful to avoid exceeding the 100 templates/app limit.
421
+ def deactivate_template_bundle_by_id(template_bundle_id)
422
+ post("facebook.feed.deactivateTemplateBundleByID", {:template_bundle_id => template_bundle_id.to_s}, false)
423
+ end
424
+
417
425
  ##
418
426
  # publish a previously rendered template bundle
419
427
  # see http://wiki.developers.facebook.com/index.php/Feed.publishUserAction
@@ -2,7 +2,7 @@ module Facebooker #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 45
5
+ TINY = 46
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/facebooker.rb CHANGED
@@ -95,6 +95,24 @@ module Facebooker
95
95
  end
96
96
  end
97
97
 
98
+ def all_api_keys
99
+ [
100
+ @raw_facebooker_configuration['api_key']
101
+ ] + (
102
+ @raw_facebooker_configuration['alternative_keys'] ?
103
+ @raw_facebooker_configuration['alternative_keys'].keys :
104
+ []
105
+ )
106
+ end
107
+
108
+ def with_all_applications(&block)
109
+ all_api_keys.each do |current_api_key|
110
+ with_application(current_api_key) do
111
+ block.call
112
+ end
113
+ end
114
+ end
115
+
98
116
  def fetch_config_for(api_key)
99
117
  if @raw_facebooker_configuration['api_key'] == api_key
100
118
  return @raw_facebooker_configuration
@@ -137,7 +137,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
137
137
  end
138
138
  def test_publish_to_converts_attachment_to_json
139
139
  @user = Facebooker::User.new(548871286, @session)
140
- @user.session.expects(:post).with("facebook.stream.publish",has_entry(:attachment=>instance_of(String)))
140
+ @user.session.expects(:post).with("facebook.stream.publish",has_entry(:attachment=>instance_of(String)),false)
141
141
  @user.publish_to(@other_user, :message => 'i love you man',:attachment=>{:a=>"b"})
142
142
  end
143
143
 
@@ -11,7 +11,7 @@ class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
11
11
  def test_one_or_true_on_string_1
12
12
  assert @rewriter.one_or_true( "1" )
13
13
  end
14
-
14
+
15
15
  def test_one_or_true_on_string_0
16
16
  assert !@rewriter.one_or_true( "0" )
17
17
  end
@@ -23,7 +23,7 @@ class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
23
23
  def test_one_or_true_on_float_1
24
24
  assert @rewriter.one_or_true( 1.0 )
25
25
  end
26
-
26
+
27
27
  def test_one_or_true_on_true
28
28
  assert @rewriter.one_or_true( true )
29
29
  end
@@ -36,4 +36,41 @@ class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
36
36
  assert !@rewriter.one_or_true( nil )
37
37
  end
38
38
 
39
+
40
+ def test_zero_or_false_on_blank
41
+ assert @rewriter.zero_or_false( "" )
42
+ end
43
+
44
+ def test_zero_or_false_on_integer_0
45
+ assert @rewriter.zero_or_false( 0 )
46
+ end
47
+
48
+ def test_zero_or_false_on_float_0
49
+ assert @rewriter.zero_or_false( 0.0 )
50
+ end
51
+
52
+ def test_zero_or_false_on_string_0
53
+ assert @rewriter.zero_or_false( "0" )
54
+ end
55
+
56
+ def test_zero_or_false_on_false
57
+ assert @rewriter.zero_or_false( false )
58
+ end
59
+
60
+ def test_zero_or_false_on_nil
61
+ assert @rewriter.zero_or_false( nil )
62
+ end
63
+
64
+ def test_zero_or_false_on_string_1
65
+ assert !@rewriter.zero_or_false( "1" )
66
+ end
67
+
68
+ def test_zero_or_false_on_numeric_1
69
+ assert !@rewriter.zero_or_false( 1 )
70
+ end
71
+
72
+ def test_zero_or_false_on_true
73
+ assert !@rewriter.zero_or_false( true )
74
+ end
75
+
39
76
  end
@@ -1,10 +1,13 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../../../lib/facebooker/rails/integration_session')
3
+
3
4
  class Facebooker::Rails::IntegrationSessionTest < Test::Unit::TestCase
5
+
4
6
  def test_include_api_key_in_default_request_params
5
7
  ENV['FACEBOOK_API_KEY'] = 'a key'
6
8
  integration_session = Facebooker::Rails::IntegrationSession.new
7
9
  integration_session.reset!
8
10
  assert_equal 'a key', integration_session.default_request_params[ :fb_sig_api_key ]
9
11
  end
12
+
10
13
  end
@@ -141,7 +141,6 @@ end
141
141
 
142
142
  class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
143
143
  FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
144
- include Facebooker::Rails::TestHelpers
145
144
 
146
145
  def setup
147
146
  super
@@ -187,14 +186,6 @@ class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
187
186
  FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
188
187
  end
189
188
 
190
- def test_find_in_db_should_destroy_old_record_if_changed
191
- FacebookTemplate.stubs(:find_by_template_name).returns(@template)
192
- FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
193
- @template.stubs(:template_changed?).returns(true)
194
- @template.expects(:destroy)
195
- FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
196
- end
197
-
198
189
  def test_find_in_db_should_re_register_if_changed
199
190
  FacebookTemplate.stubs(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(@template)
200
191
  FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
@@ -203,6 +194,7 @@ class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
203
194
  FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
204
195
  FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
205
196
  end
197
+
206
198
  end
207
199
 
208
200
  class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
@@ -332,6 +324,20 @@ class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
332
324
  Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
333
325
  TestPublisher.register_user_action
334
326
  end
327
+
328
+ def test_register_should_deactivate_template_bundle_if_exists
329
+ @template = mock
330
+ @template.stubs(:bundle_id).returns(999)
331
+ @template.stubs(:bundle_id=)
332
+ @template.stubs(:save!)
333
+ @session = mock
334
+ @session.stubs(:register_template_bundle).returns(1000)
335
+ Facebooker::Session.stubs(:create).returns(@session)
336
+ Facebooker::Rails::Publisher::FacebookTemplate.stubs(:find_or_initialize_by_template_name).returns(@template)
337
+ @template.expects(:deactivate)
338
+ FacebookTemplate.register(TestPublisher, "simple_user_action")
339
+ end
340
+
335
341
  def test_register_user_action_with_action_links
336
342
  ActionController::Base.append_view_path("./test/../../app/views")
337
343
  Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
@@ -125,10 +125,6 @@ class PlainOldRailsController < ActionController::Base
125
125
  end
126
126
  end
127
127
 
128
- class Test::Unit::TestCase
129
- include Facebooker::Rails::TestHelpers
130
- end
131
-
132
128
 
133
129
  # you can't use asset_recognize, because it can't pass parameters in to the requests
134
130
  class UrlRecognitionTests < Test::Unit::TestCase
@@ -332,6 +328,16 @@ class RailsIntegrationTest < Test::Unit::TestCase
332
328
  get :index, facebook_params('fb_sig_added' => "1")
333
329
  assert_equal(true, @controller.facebook_params['added'])
334
330
  end
331
+
332
+ def test_facebook_params_convert_added_to_boolean_false_when_already_false
333
+ get :index, facebook_params('fb_sig_added' => false)
334
+ assert_equal(false, @controller.facebook_params['added'])
335
+ end
336
+
337
+ def test_facebook_params_convert_added_to_boolean_true_when_already_true
338
+ get :index, facebook_params('fb_sig_added' => true)
339
+ assert_equal(true, @controller.facebook_params['added'])
340
+ end
335
341
 
336
342
  def test_facebook_params_convert_expirey_into_nil
337
343
  get :index, facebook_params(:fb_sig_expires => '0')
@@ -429,7 +435,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
429
435
  setup_fb_connect_cookies
430
436
  get :index
431
437
  assert_equal(77777, @controller.facebook_session.user.id)
432
- end
438
+ end
433
439
 
434
440
  def test_session_does_NOT_secure_with_expired_cookies
435
441
  setup_fb_connect_cookies(expired_cookie_hash_for_auth)
@@ -547,6 +553,23 @@ class RailsSignatureTest < Test::Unit::TestCase
547
553
  @response = ActionController::TestResponse.new
548
554
 
549
555
  end
556
+
557
+ if Rails.version < '2.3'
558
+
559
+ def test_should_raise_on_bad_sig
560
+ begin
561
+ get :fb_params_test, facebook_params.merge('fb_sig' => 'incorrect')
562
+ fail "No IncorrectSignature raised"
563
+ rescue Facebooker::Session::IncorrectSignature=>e
564
+ end
565
+ end
566
+
567
+ def test_valid_signature
568
+ @controller.expects(:earliest_valid_session).returns(Time.at(1186588275.5988)-1)
569
+ get :fb_params_test, facebook_params
570
+ end
571
+
572
+ end
550
573
 
551
574
  def test_should_raise_too_old_for_replayed_session
552
575
  begin
@@ -556,20 +579,6 @@ class RailsSignatureTest < Test::Unit::TestCase
556
579
  end
557
580
  end
558
581
 
559
- def test_should_raise_on_bad_sig
560
- begin
561
- get :fb_params_test, facebook_params.merge('fb_sig' => 'incorrect')
562
- fail "No IncorrectSignature raised"
563
- rescue Facebooker::Session::IncorrectSignature=>e
564
- end
565
- end
566
-
567
- def test_valid_signature
568
- @controller.expects(:earliest_valid_session).returns(Time.at(1186588275.5988)-1)
569
- get :fb_params_test, facebook_params
570
-
571
- end
572
-
573
582
  end
574
583
  class RailsHelperTest < Test::Unit::TestCase
575
584
  class HelperClass
@@ -1072,13 +1081,17 @@ class RailsHelperTest < Test::Unit::TestCase
1072
1081
  def test_fb_logout_link
1073
1082
  assert_equal @h.fb_logout_link("Logout","My URL"),"<a href=\"#\" onclick=\"FB.Connect.logoutAndRedirect(&quot;My URL&quot;);; return false;\">Logout</a>"
1074
1083
  end
1084
+
1075
1085
  def test_fb_user_action_with_literal_callback
1076
1086
  action = Facebooker::Rails::Publisher::UserAction.new
1077
- assert_equal @h.fb_user_action(action,"message","prompt","function() {alert('hi')}"),"FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, function() {alert('hi')}, \"prompt\", {\"value\": \"message\"});"
1087
+ assert_equal "FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, function() {alert('hi')}, \"prompt\", #{{"value" => "message"}.to_json});",
1088
+ @h.fb_user_action(action,"message","prompt","function() {alert('hi')}")
1078
1089
  end
1090
+
1079
1091
  def test_fb_user_action_with_nil_callback
1080
1092
  action = Facebooker::Rails::Publisher::UserAction.new
1081
- assert_equal @h.fb_user_action(action,"message","prompt"),"FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, null, \"prompt\", {\"value\": \"message\"});"
1093
+ assert_equal "FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, null, \"prompt\", #{{"value" => "message"}.to_json});",
1094
+ @h.fb_user_action(action,"message","prompt")
1082
1095
  end
1083
1096
 
1084
1097
 
@@ -1089,6 +1102,13 @@ class RailsHelperTest < Test::Unit::TestCase
1089
1102
  end
1090
1103
  end
1091
1104
 
1105
+ def test_fb_connect_javascript_tag_with_language_option
1106
+ silence_warnings do
1107
+ assert_equal "<script src=\"http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US\" type=\"text/javascript\"></script>",
1108
+ @h.fb_connect_javascript_tag(:lang => "en_US")
1109
+ end
1110
+ end
1111
+
1092
1112
  def test_fb_connect_javascript_tag_ssl
1093
1113
  @h.instance_eval do
1094
1114
  def request
@@ -1104,6 +1124,21 @@ class RailsHelperTest < Test::Unit::TestCase
1104
1124
  end
1105
1125
  end
1106
1126
 
1127
+ def test_fb_connect_javascript_tag_ssl_with_language_option
1128
+ @h.instance_eval do
1129
+ def request
1130
+ ssl_request = ActionController::TestRequest.new
1131
+ ssl_request.stubs(:ssl?).returns(true)
1132
+ ssl_request
1133
+ end
1134
+ end
1135
+
1136
+ silence_warnings do
1137
+ assert_equal "<script src=\"https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US\" type=\"text/javascript\"></script>",
1138
+ @h.fb_connect_javascript_tag(:lang => "en_US")
1139
+ end
1140
+ end
1141
+
1107
1142
  def test_fb_container
1108
1143
  @h.expects(:capture).returns("Inner Stuff")
1109
1144
  @h.fb_container(:condition=>"somejs") do
@@ -245,6 +245,16 @@ class Facebooker::SessionTest < Test::Unit::TestCase
245
245
  @session.register_template_bundle(one_line, short_story, full_story)
246
246
  end
247
247
 
248
+ def test_can_deactivate_template_bundle_by_id
249
+ @session = Facebooker::Session.create(ENV['FACBEOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
250
+ @session.expects(:post).with(
251
+ 'facebook.feed.deactivateTemplateBundleByID',
252
+ {:template_bundle_id => '999'},
253
+ false
254
+ )
255
+ @session.deactivate_template_bundle_by_id(999)
256
+ end
257
+
248
258
  def test_can_publish_user_action
249
259
  expect_http_posts_with_responses(publish_user_action_return_xml)
250
260
  @session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
@@ -15,6 +15,14 @@ require 'facebooker/rails/helpers'
15
15
  require 'facebooker/rails/publisher'
16
16
  require 'facebooker/rails/facebook_form_builder'
17
17
 
18
+ if Rails.version >= '2.3'
19
+ Test::Unit::TestCase.send :include, ActionController::TestCase::Assertions
20
+ Test::Unit::TestCase.send :include, ActionController::TestProcess
21
+ Test::Unit::TestCase.send :include, Facebooker::Rails::TestHelpers
22
+
23
+ ActionController::Base.session = { :key => "9hfwfl8slgh9", :secret => "db08fcba0378a9e066ce037bec4b72bc" }
24
+ end
25
+
18
26
  ActionController::Routing::Routes.draw do |map|
19
27
  map.connect '', :controller=>"facebook",:conditions=>{:canvas=>true}
20
28
  map.connect '', :controller=>"plain_old_rails"
data/test/test_helper.rb CHANGED
@@ -29,9 +29,9 @@ end
29
29
  require 'facebooker'
30
30
  require 'facebooker/rails/test_helpers'
31
31
 
32
-
33
32
  class Test::Unit::TestCase
34
- include Facebooker::Rails::TestHelpers
33
+
34
+ include Facebooker::Rails::TestHelpers unless self.included_modules.include?( Facebooker::Rails::TestHelpers )
35
35
 
36
36
  private
37
37
 
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.45
4
+ version: 1.0.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Fowler
@@ -9,11 +9,12 @@ authors:
9
9
  - Mike Mangino
10
10
  - Shane Vitarana
11
11
  - Corey Innis
12
+ - Mike Mangino
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2009-07-24 00:00:00 -07:00
17
+ date: 2009-08-14 00:00:00 -07:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
@@ -37,7 +38,13 @@ dependencies:
37
38
  version: 2.3.2
38
39
  version:
39
40
  description: "Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://wiki.developers.facebook.com/index.php/API]. Its goals are: * Idiomatic Ruby * No dependencies outside of the Ruby standard library (This is true with Rails 2.1. Previous Rails versions require the JSON gem) * Concrete classes and methods modeling the Facebook data, so it's easy for a Rubyist to understand what's available * Well tested"
40
- email: mmangino@elevatedrails.com
41
+ email:
42
+ - chad@chadfowlwer.com
43
+ - ""
44
+ - ""
45
+ - ""
46
+ - ""
47
+ - mmangino@elevatedrails.com
41
48
  executables: []
42
49
 
43
50
  extensions: []
@@ -193,6 +200,7 @@ files:
193
200
  - test/facebooker/service_test.rb
194
201
  has_rdoc: false
195
202
  homepage: http://facebooker.rubyforge.org
203
+ licenses:
196
204
  post_install_message:
197
205
  rdoc_options:
198
206
  - --main
@@ -214,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
222
  requirements: []
215
223
 
216
224
  rubyforge_project: facebooker
217
- rubygems_version: 1.2.0
225
+ rubygems_version: 1.3.5
218
226
  signing_key:
219
227
  specification_version: 3
220
228
  summary: Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://wiki.developers.facebook.com/index.php/API]