Class: FacebookGoogleCalendarSync::EventConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_google_calendar_sync/event_converter.rb

Overview

Converts Facebook event into Google event hash

Constant Summary collapse

STATUS_MAPPINGS =
{'NEEDS-ACTION' => 'needsAction', 'ACCEPTED' => 'accepted'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(facebook_event, google_calendar_id) ⇒ EventConverter

Returns a new instance of EventConverter.



9
10
11
12
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



55
56
57
58
59
60
61
# 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

Instance Attribute Details

#facebook_eventObject

Returns the value of attribute facebook_event.



6
7
8
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 6

def facebook_event
  @facebook_event
end

#google_calendar_idObject

Returns the value of attribute google_calendar_id.



6
7
8
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 6

def google_calendar_id
  @google_calendar_id
end

Instance Method Details

#attendeesObject



28
29
30
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 28

def attendees
  [{"email"=>google_calendar_id, 'responseStatus' => partstat}]
end

#descriptionObject



32
33
34
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 32

def description
  "#{facebook_event.description}\n\nOrganiser: #{organiser_name}"
end

#organiserObject



49
50
51
52
53
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 49

def organiser
  {
    'email' => '[email protected]',
  }
end

#organiser_nameObject



44
45
46
47
# 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

#partstatObject



36
37
38
# 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_hashObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

#transparencyObject



40
41
42
# File 'lib/facebook_google_calendar_sync/event_converter.rb', line 40

def transparency
  partstat == 'accepted' ? 'opaque' : 'transparent'
end