Skip to content

Instantly share code, notes, and snippets.

@sroaj
Created July 6, 2012 09:32
Show Gist options
  • Select an option

  • Save sroaj/3059210 to your computer and use it in GitHub Desktop.

Select an option

Save sroaj/3059210 to your computer and use it in GitHub Desktop.
client = Google::APIClient.new
path_to_key_file = 'xxxx-privatekey.p12'
passphrase = 'xxxx'
key = Google::APIClient::PKCS12.load_key(path_to_key_file, passphrase)
asserter = Google::APIClient::JWTAsserter.new(
'[email protected]',
'https://www.googleapis.com/auth/calendar.readonly',
key)
client.authorization = asserter.authorize("[email protected]")
service = client.discovered_api('calendar', 'v3')
page_token = nil
timeMin = Time.now.strftime("%Y-%m-%dT%H:%I:%M%z")
timeMax = (Time.now + 86400).strftime("%Y-%m-%dT%H:%I:%M%z")
parameters = {'calendarId' => '[email protected]', 'timeMin' => timeMin, 'timeMax' => timeMax}
output = []
begin
result = client.execute(:api_method => service.events.list, :parameters => parameters)
result.data.items.each do |e|
#Convert to hash
output << JSON.parse(e.to_json)
end
end until (parameters['pageToken'] = result.data.next_page_token).nil?
test = { events: output }
puts test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment