Class: GcalMapper::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/gcal_mapper/calendar.rb

Overview

Provide methods to get google calendar data

Instance Method Summary collapse

Instance Method Details

#get_calendars_list(access_token) ⇒ Array

Get the calendar list for the connected user.

Parameters:

  • access_token (Hash)

    the token obtain with Authentification.access_token

Returns:

  • (Array)

    google calendar id that the user can access.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gcal_mapper/calendar.rb', line 11

def get_calendars_list(access_token)
  url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList'
  options = {
    :method => :get,
    :headers => {'Authorization' => 'Bearer ' + access_token}
  }
  req = GcalMapper::RestRequest.new(url, options)
  response = req.execute

  tab_cal=response['items']
  ids = []

  tab_cal.each do |t|
    t.each do |k, v|
      if k == 'id'
        ids.push(v)
      end
    end
  end

  ids
end

#get_events_list(access_token, calendar_id) ⇒ Array

Get all events from specified calendar(s).

Parameters:

  • access_token (Hash)

    the token obtain with Authentification.access_token

  • calendar_id (Array)

    contain the calendar(s) id you want to map

Returns:

  • (Array)

    all events from given calendar(s) id.



39
40
41
42
43
44
45
46
47
48
# File 'lib/gcal_mapper/calendar.rb', line 39

def get_events_list(access_token, calendar_id)
  url = 'https://www.googleapis.com/calendar/v3/calendars/'+calendar_id+'/events?showDeleted=true'
  options = {
    :method => :get,
    :headers => {'Authorization' => 'Bearer ' + access_token},
  }
  req = GcalMapper::RestRequest.new(url, options)
  response = req.execute
  response['items']
end