Skip to content

Instantly share code, notes, and snippets.

/a.rb Secret

Created July 21, 2015 08:39
Show Gist options
  • Save anonymous/9cc99c48505e02e22230 to your computer and use it in GitHub Desktop.
Save anonymous/9cc99c48505e02e22230 to your computer and use it in GitHub Desktop.
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'google/api_client/auth/storage'
require 'google/api_client/auth/storages/file_store'
require 'fileutils'
require 'gmail'
APPLICATION_NAME = 'Google Calendar API Quickstart'
CLIENT_SECRETS_PATH = 'client_secret.json'
CREDENTIALS_PATH = File.join(Dir.home, '.credentials',
"calendar-quickstart.json")
SCOPE = ['https://www.googleapis.com/auth/calendar', 'https://mail.google.com']
class Mcalendar < Google::APIClient # EXTEND GOOGLE API ?!
def initialize
#BLA ?
end
def authorize
FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
file_store = Google::APIClient::FileStore.new(CREDENTIALS_PATH)
storage = Google::APIClient::Storage.new(file_store)
auth = storage.authorize
if auth.nil? || (auth.expired? && auth.refresh_token.nil?)
app_info = Google::APIClient::ClientSecrets.load(CLIENT_SECRETS_PATH)
flow = Google::APIClient::InstalledAppFlow.new({
:client_id => app_info.client_id,
:client_secret => app_info.client_secret,
:scope => SCOPE})
auth = flow.authorize(storage)
puts "Credentials saved to #{CREDENTIALS_PATH}" unless auth.nil?
end
auth
end
#buggy stuff
def by_status(sStatus , eID)
bsEvents = client.execute!(:api_method => calendar_api.events.list,
:parameter => { 'calendarId' => 'primary', 'eventId' => eID})
bsEvents.data.items.each do |compare|
if compare.attendees[0].responseStatus == sStatus
return bsEvents.data.items
end
end
end
#Class end
end
#Init stuff
m = Mcalendar.new
client = m.(:application_name => APPLICATION_NAME)
#client = Google::APIClient.new(:application_name => APPLICATION_NAME) -> NORMALY THIS WORKS
client.authorization = m.authorize # THIS ?! m. ?
calendar_api = client.discovered_api('calendar', 'v3')
mail_api = client.discovered_api('gmail', 'v1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment