Saturday, September 3, 2011

Fixing error "PHP extension "curl" must be loaded." while installing Magento

While installing Magento I faces a error "PHP extension "curl" must be loaded.". I did some googling and found a solution which mentioned to remove colon(';') before 'extension=php_curl.dll'. To do this open php.ini file on your system and search for "extension=php_curl.dll" and then remove colon. and restart all your sevices. Thats all.

Monday, April 25, 2011

Issue with facebooker gem while updating an event on facebook through rails application

Facebooker is a good gem to integrate your rails application with facebook(FB). I am using this gem to post events on the Fb user wall.

While working with facebooker I found an issue with edit_event method of the Session class. Basically facebooker processes the event start and end time, as per timezone, while creating an event on FB. But don't do anything in the case of edit_event.

So I fixed that issue by overriding the edit_event and create_event method. The steps that needs to be followed are:

  1. Create a file named as 'enhanced_facebooker.rb' in config/initializers folder.
  2. Add the following code in this file:
module Facebooker
  class Session
    def create_event(event_info, multipart_post_file = nil)
      
      
      post_file('facebook.events.create', :event_info => process_event_timings(event_info), nil => multipart_post_file)
    end
    
    def edit_event(eid, event_info, options = {})
      post('facebook.events.edit', options.merge(:eid => eid, :event_info => process_event_timings(event_info)))
    end
    
    def process_event_timings event_info
      if defined?(ActiveSupport::TimeWithZone) && defined?(ActiveSupport::TimeZone)
        # Facebook expects all event local times to be in Pacific Time, so we need to take the actual local time and 
        # send it to Facebook as if it were Pacific Time converted to Unix epoch timestamp. Very confusing...
        facebook_time = ActiveSupport::TimeZone["Pacific Time (US & Canada)"]
        
        start_time = event_info.delete(:start_time) || event_info.delete('start_time')
        if start_time && start_time.is_a?(ActiveSupport::TimeWithZone)
          event_info['start_time'] = facebook_time.parse(start_time.strftime("%Y-%m-%d %H:%M:%S")).to_i
        else
          event_info['start_time'] = start_time
        end
        
        end_time = event_info.delete(:end_time) || event_info.delete('end_time')
        if end_time && end_time.is_a?(ActiveSupport::TimeWithZone)
          event_info['end_time'] = facebook_time.parse(end_time.strftime("%Y-%m-%d %H:%M:%S")).to_i
        else
          event_info['end_time'] = end_time
        end
      end
      event_info.to_json
    end
  end
end



I have just moved the event start and end time processing code in a separate method named as 'process_event_timings '. Which modifies the event timings as per FB. And calling this method from create_event and edit_method of Session class.