Skip to content

Instantly share code, notes, and snippets.

@mmangino
Created January 7, 2009 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmangino/44362 to your computer and use it in GitHub Desktop.
Save mmangino/44362 to your computer and use it in GitHub Desktop.
facebooker_backend.rb
module Technoweenie # :nodoc:
module AttachmentFu # :nodoc:
module Backends
module FacebookerBackend
class RequiredLibraryNotFoundError < StandardError; end
class ConfigFileNotFoundError < StandardError; end
def self.included(base) #:nodoc:
verify_facebooker_is_present
end
def self.verify_facebooker_is_present
begin
begin
Facebooker
rescue
require 'facebooker'
end
rescue LoadError
raise RequiredLibraryNotFoundError.new('Facebooker could not be loaded')
end
end
attr_accessor :facebook_session
def public_filename
url
end
protected
def destroy_file
true # Facebook doesn't implement a destroy photo command
end
def rename_file
true # Facebook doesn't implement a rename photo command
end
def save_to_storage
unless @saved_to_storage
data = (temp_path ? File.open(temp_path).read : temp_data)
file_parameter = Net::HTTP::MultipartPostFile.new(filename, content_type, data )
photo = facebook_session.user.upload_photo(file_parameter)
@saved_to_storage = true
update_attributes(:url => photo.src_big, :facebook_pid => photo.pid)
end
true
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment