Created
April 1, 2014 19:06
-
-
Save theinventor/9920832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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