class FacebookGoogleCalendarSync::EventConverter

Converts Facebook event into Google event hash

Constants

STATUS_MAPPINGS

Attributes

facebook_event[RW]
google_calendar_id[RW]

Public Class Methods

new(facebook_event, google_calendar_id) click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 9
def initialize facebook_event, google_calendar_id
  @facebook_event = facebook_event
  @google_calendar_id = google_calendar_id
end

Public Instance Methods

attendees() click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 28
def attendees
  [{"email"=>google_calendar_id, 'responseStatus' => partstat}]
end
description() click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 32
def description
  "#{facebook_event.description}\n\nOrganiser: #{organiser_name}"
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/facebook_google_calendar_sync/event_converter.rb, line 55
def method_missing(method, *args, &block)
  if facebook_event.respond_to?(method)
    facebook_event.send(method, *args, &block)
  else
    super
  end
end
organiser() click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 49
def organiser
  {
    'email' => 'noreply@facebook.com',
  }
end
organiser_name() click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 44
def organiser_name
  matches = organizer_property.to_s.scan(/CN=(.*):MAILTO:(.*)/).flatten
  matches[0]
end
partstat() click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 36
def partstat
  STATUS_MAPPINGS[facebook_event.to_s.scan(/PARTSTAT::(.*)/).flatten.first()]
end
to_hash() click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 14
def to_hash
  {
     'summary' => summary,
     'start' => date_hash(dtstart),
     'end' => date_hash(dtend),
     'iCalUID' => uid,
     'description' => description,
     'location' => location,
     'organizer' => organiser,
     'attendees' => attendees,
     'transparency' => transparency
  }
end
transparency() click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 40
def transparency
  partstat == 'accepted' ? 'opaque' : 'transparent'
end

Private Instance Methods

date_hash(date_time) click to toggle source
# File lib/facebook_google_calendar_sync/event_converter.rb, line 65
def date_hash date_time
  if date_time.instance_of? Date
    {'date' => date_time.strftime('%Y-%m-%d')}
  else
    {'dateTime' => date_time.strftime('%Y-%m-%dT%H:%M:%S.000%:z')}
  end
end