Class: SlimTimer
- Inherits:
-
Object
- Object
- SlimTimer
- Defined in:
- lib/slimtimercli/slim_timer.rb
Constant Summary collapse
- DATE_FORMAT =
"%Y-%m-%d %H-%M-%S"
Instance Attribute Summary collapse
-
#tasks(show_completed = "yes", role = "owner,coworker") ⇒ Object
- Lists all tasks for the user logged in the system ==== Parameters show_completed<String>
- yes | no | only Include completed tasks (yes/no) or show only completed tasks Default: yes role<String>
-
owner,coworker,reporter Include tasks where the user’s role is one of the roles given (comma delimited) Default: owner,coworker.
-
#time_entries(range_start = nil, range_end = nil) ⇒ Object
- List all time entries for the user logged in ==== Parameters range_start<Time>
- start of the range range_end<Time>
-
end of the range.
Instance Method Summary collapse
-
#create_task(name, tags = "", coworker_emails = "", reporter_emails = "") ⇒ Object
- Create a new task for this user ==== Parameters name<String>
- name for the new task tags<String>
-
comma separated list of tags for the task.
- #create_time_entry(task, start_time = Time.now, duration = 0) ⇒ Object
- #delete_task(name) ⇒ Object
- #find_task_by_name(name) ⇒ Object
-
#initialize(user, pass, api) ⇒ SlimTimer
constructor
A new instance of SlimTimer.
-
#login ⇒ Object
Performs the login to the system, and stores the user id and the access token in the local class for reusse.
Constructor Details
#initialize(user, pass, api) ⇒ SlimTimer
Returns a new instance of SlimTimer.
7 8 9 10 11 12 |
# File 'lib/slimtimercli/slim_timer.rb', line 7 def initialize(user, pass, api) @user = user; @pass = pass @api_key = api @host = "slimtimer.com" @port = 80 end |
Instance Attribute Details
#tasks(show_completed = "yes", role = "owner,coworker") ⇒ Object
Lists all tasks for the user logged in the system
Parameters
- show_completed<String>
-
yes | no | only Include completed tasks (yes/no) or show only completed tasks Default: yes
- role<String>
-
owner,coworker,reporter Include tasks where the user’s role is one of the roles given (comma delimited) Default:
owner,coworker
30 31 32 |
# File 'lib/slimtimercli/slim_timer.rb', line 30 def tasks @tasks end |
#time_entries(range_start = nil, range_end = nil) ⇒ Object
List all time entries for the user logged in
Parameters
- range_start<Time>
-
start of the range
- range_end<Time>
-
end of the range
70 71 72 |
# File 'lib/slimtimercli/slim_timer.rb', line 70 def time_entries @time_entries end |
Instance Method Details
#create_task(name, tags = "", coworker_emails = "", reporter_emails = "") ⇒ Object
Create a new task for this user
Parameters
- name<String>
-
name for the new task
- tags<String>
-
comma separated list of tags for the task
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/slimtimercli/slim_timer.rb', line 45 def create_task(name, = "", coworker_emails = "", reporter_emails = "") t = Task.new t.name = name t. = t._serialize Task._load(post_request("/users/#{@user_id}/tasks", t._serialize)) end |
#create_time_entry(task, start_time = Time.now, duration = 0) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/slimtimercli/slim_timer.rb', line 82 def create_time_entry(task, start_time = Time.now, duration = 0) te = TimeEntry.new te.task = task; te.start_time = start_time te.duration_in_seconds = duration post_request("/users/#{@user_id}/time_entries", te._serialize) end |
#delete_task(name) ⇒ Object
61 62 63 64 |
# File 'lib/slimtimercli/slim_timer.rb', line 61 def delete_task(name) t = find_task_by_name(name) delete_request("/users/#{@user_id}/tasks/#{t.id}") end |
#find_task_by_name(name) ⇒ Object
57 58 59 |
# File 'lib/slimtimercli/slim_timer.rb', line 57 def find_task_by_name(name) tasks("no").find {|t| t.name == name} end |
#login ⇒ Object
Performs the login to the system, and stores the user id and the access token in the local class for reusse
17 18 19 20 21 |
# File 'lib/slimtimercli/slim_timer.rb', line 17 def login data = post_request("/users/token", User.new(@user, @pass)._serialize) @token = data["access_token"] @user_id = data["user_id"] end |