class Goot::GoogleAPI

Constants

CLIENT_SECRET_STORE
CREDENTIAL_STORE
DELETED
MODIFIED
UNCHANGED

Public Class Methods

new() click to toggle source
# File lib/goot/google_api.rb, line 15
def initialize
  client = Google::APIClient.new(
    :application_name => Goot::APP_NAME,
    :application_version => Goot::VERSION
  )

  file_storage = Google::APIClient::FileStorage.new(CREDENTIAL_STORE)

  if file_storage.authorization.nil?
    client_secrets = Google::APIClient::ClientSecrets.load(CLIENT_SECRET_STORE)
    flow = Google::APIClient::InstalledAppFlow.new(
      :client_id => client_secrets.client_id,
      :client_secret => client_secrets.client_secret,
      :scope => 'https://www.googleapis.com/auth/tasks'
    )
    client.authorization = flow.authorize(file_storage)
  else
    client.authorization = file_storage.authorization
  end

  @client = client
  @api = client.discovered_api('tasks', 'v1')
end

Public Instance Methods

clear_tasks(tasklist) click to toggle source
# File lib/goot/google_api.rb, line 88
def clear_tasks(tasklist)
  @client.execute(
    :api_method => @api.tasks.clear,
    :parameters => {
      :tasklist => tasklist.id
    }
  )
end
delete_task(tasklist, task) click to toggle source
# File lib/goot/google_api.rb, line 109
def delete_task(tasklist, task)
  @client.execute(
    :api_method => @api.tasks.delete,
    :parameters => {
      :tasklist => tasklist.id,
      :task => task['id']
    }
  )
end
delete_tasklist(tasklist) click to toggle source
# File lib/goot/google_api.rb, line 59
def delete_tasklist(tasklist)
  @client.execute(
    :api_method => @api.tasklists.delete,
    :parameters => {
      :tasklist => tasklist.id
    }
  )
end
get_lists() click to toggle source
# File lib/goot/google_api.rb, line 39
def get_lists
  @client.execute(:api_method => @api.tasklists.list).data.items
end
get_tasklist(index) click to toggle source
# File lib/goot/google_api.rb, line 43
def get_tasklist(index)
  @client.execute(
    :api_method => @api.tasklists.get,
    :parameters => {
      :tasklist => get_lists[index].id
    }
  ).data
end
get_tasks(tasklist) click to toggle source
# File lib/goot/google_api.rb, line 68
def get_tasks(tasklist)
  @client.execute(
    :api_method => @api.tasks.list,
    :parameters => {
      :tasklist => tasklist.id
    }
  ).data.items.select { |t| t.status != DELETED }
end
insert_task(tasklist, task, previous, parent) click to toggle source
# File lib/goot/google_api.rb, line 97
def insert_task(tasklist, task, previous, parent)
  parameters = { :tasklist => tasklist.id }
  parameters[:previous] = previous['id'] if !previous.nil?
  parameters[:parent] = parent['id'] if !parent.nil?

  @client.execute(
    :api_method => @api.tasks.insert,
    :parameters => parameters,
    :body_object => task
  )
end
insert_tasklist(tasklist) click to toggle source
# File lib/goot/google_api.rb, line 52
def insert_tasklist(tasklist)
  @client.execute(
    :api_method => @api.tasklists.insert,
    :body_object => tasklist
  )
end
move_task(tasklist, task, previous, parent) click to toggle source
# File lib/goot/google_api.rb, line 119
def move_task(tasklist, task, previous, parent)
  parameters = {
    :tasklist => tasklist.id,
    :task => task['id']
  }
  parameters[:previous] = previous['id'] if !previous.nil?
  parameters[:parent] = parent['id'] if !parent.nil?

  @client.execute(
    :api_method => @api.tasks.move,
    :parameters => parameters
  )
end
update_task(tasklist, task) click to toggle source
# File lib/goot/google_api.rb, line 77
def update_task(tasklist, task)
  @client.execute(
    :api_method => @api.tasks.update,
    :parameters => {
      :tasklist => tasklist.id,
      :task => task['id']
    },
    :body_object => task
  )
end