Module: FacebookGoogleCalendarSync::GoogleCalendarClient

Includes:
Logging
Included in:
GoogleCalendar, Synchroniser
Defined in:
lib/facebook_google_calendar_sync/google_calendar_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Class Method Details

.configure {|@@config| ... } ⇒ Object

Yields:

  • (@@config)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 17

def self.configure
  @@config = OpenStruct.new
  yield @@config

  oauth_yaml = YAML.load_file(@@config.google_api_config_file)
  @@client = Google::APIClient.new({:application_name => "Facebook to Google Calendar Sync", :application_version => FacebookGoogleCalendarSync::VERSION})
  @@client.authorization.client_id = oauth_yaml["client_id"]
  @@client.authorization.client_secret = oauth_yaml["client_secret"]
  @@client.authorization.scope = oauth_yaml["scope"]
  @@client.authorization.refresh_token = oauth_yaml["refresh_token"]
  @@client.authorization.access_token = oauth_yaml["access_token"]

  if @@client.authorization.refresh_token && @@client.authorization.expired?
    @@client.authorization.fetch_access_token!
  end

  @@calendar_service = @@client.discovered_api('calendar', 'v3')
end

Instance Method Details

#add_event(calendar_id, event) ⇒ Object



56
57
58
59
60
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 56

def add_event calendar_id, event
  make_call :api_method => calendar_service.events.import,
    :parameters => {'calendarId' => calendar_id},
    :body_object => event
end

#create_calendar(calendar_details) ⇒ Object



68
69
70
71
72
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 68

def create_calendar calendar_details
  make_call :api_method => calendar_service.calendars.insert,
    :parameters => {},
    :body_object => calendar_details
end

#find_calendar_details_by_summary(calendar_summary) ⇒ Object



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

def find_calendar_details_by_summary calendar_summary
  get_calendar_list.items.find { | calendar | calendar.summary == calendar_summary && calendar.accessRole == 'owner'}
end

#find_primary_calendar_detailsObject



44
45
46
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 44

def find_primary_calendar_details
  get_calendar_list.items.find { | calendar | calendar.primary }
end

#get_calendar(calendar_id) ⇒ Object



52
53
54
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 52

def get_calendar calendar_id
  make_call :api_method => calendar_service.events.list, :parameters => {'calendarId' => calendar_id}
end

#get_calendar_listObject



48
49
50
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 48

def get_calendar_list
  make_call :api_method => calendar_service.calendar_list.list
end

#get_calendar_metadata(calendar_id) ⇒ Object



36
37
38
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 36

def  calendar_id
  make_call :api_method => calendar_service.calendars.get, :parameters => {'calendarId' => calendar_id}
end

#update_calendar(calendar_id, calendar_details) ⇒ Object



74
75
76
77
78
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 74

def update_calendar calendar_id, calendar_details
  make_call :api_method => calendar_service.calendars.update,
    :parameters => {'calendarId' => calendar_id},
    :body_object => calendar_details
end

#update_event(calendar_id, event_id, event) ⇒ Object



62
63
64
65
66
# File 'lib/facebook_google_calendar_sync/google_calendar_client.rb', line 62

def update_event calendar_id, event_id, event
  make_call :api_method => calendar_service.events.update,
    :parameters => {'calendarId' => calendar_id, 'eventId' => event_id},
    :body_object => event
end