Created
January 7, 2009 18:46
-
-
Save mmangino/44362 to your computer and use it in GitHub Desktop.
facebooker_backend.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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