Skip to content

Instantly share code, notes, and snippets.

@theinventor
Created April 1, 2014 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theinventor/9920832 to your computer and use it in GitHub Desktop.
Save theinventor/9920832 to your computer and use it in GitHub Desktop.
class Togglr
attr_accessor :client, :workspace_id
def initialize(account)
@account = account
raise "NoToken" unless @account.settings.toggl_api_token
end
def client
@client ||= Toggl.new(@account.settings.toggl_api_token)
end
def projects
@workspace_id = client.workspaces.first['id']
@projects ||= client.projects(@workspace_id)
end
def project ticket
projects.select {|p| p['name'].include?(ticket.number.to_s) }.first
end
def new_project ticket
client.create_project({name: "#{ticket.number} - #{ticket.customer.business_then_name}", wid: @workspace_id})
end
def time_entries ticket
pid = project(ticket)['id']
client.get_time_entries.select {|e| e['pid'] == pid}
end
def archive_project ticket
pid = project(ticket)['id']
client.update_project(pid, {active: false})
end
def record_time ticket,user
TicketTimer.record_time(ticket,user,time_entries(ticket))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment