toodledo 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ == 1.3.0 / 2008-05-31
2
+
3
+ * Added star, status and startdate to correspond to version 3.9.0
4
+
1
5
  == 1.2.0 / 2008-04-19
2
6
 
3
7
  * Added get_deleted() method
@@ -32,6 +32,7 @@ lib/toodledo/priority.rb
32
32
  lib/toodledo/repeat.rb
33
33
  lib/toodledo/server_error.rb
34
34
  lib/toodledo/session.rb
35
+ lib/toodledo/status.rb
35
36
  lib/toodledo/task.rb
36
37
  test/client_test.rb
37
38
  test/parser_helper_test.rb
@@ -5,7 +5,7 @@
5
5
  module Toodledo
6
6
 
7
7
  # Required for gem
8
- VERSION = '1.2.0'
8
+ VERSION = '1.3.0'
9
9
 
10
10
  # Returns the configuration object.
11
11
  def self.get_config()
@@ -24,11 +24,21 @@ module Toodledo
24
24
  #
25
25
  # The following will do most everything you want, assuming you've set
26
26
  # the config correctly:
27
- #
28
- # require 'toodledo'
29
- # Toodledo.begin do |session|
30
- # session.add_task('foo')
31
- # end
27
+ #
28
+ # require 'rubygems'
29
+ # require 'toodledo'
30
+ # require 'yaml'
31
+ # config = {
32
+ # "connection" => {
33
+ # "url" => "http://www.toodledo.com/api.php",
34
+ # "user_id" => "<your user id>",
35
+ # "password" => "<your password>"
36
+ # }
37
+ # }
38
+ # Toodledo.set_config(config)
39
+ # Toodledo.begin do |session|
40
+ # session.add_task('foo')
41
+ # end
32
42
  #
33
43
  def self.begin(logger = nil)
34
44
  config = Toodledo.get_config()
@@ -56,6 +66,7 @@ end
56
66
  require 'toodledo/server_error'
57
67
  require 'toodledo/item_not_found_error'
58
68
  require 'toodledo/invalid_configuration_error'
69
+ require 'toodledo/status'
59
70
  require 'toodledo/task'
60
71
  require 'toodledo/context'
61
72
  require 'toodledo/goal'
@@ -18,6 +18,7 @@ require 'toodledo/command_line/add_command'
18
18
  # READ
19
19
  require 'toodledo/command_line/hotlist_command'
20
20
  require 'toodledo/command_line/list_tasks_command'
21
+ require 'toodledo/command_line/list_tasks_by_context_command'
21
22
  require 'toodledo/command_line/list_folders_command'
22
23
  require 'toodledo/command_line/list_contexts_command'
23
24
  require 'toodledo/command_line/list_goals_command'
@@ -76,10 +77,16 @@ module Toodledo
76
77
  }
77
78
  end
78
79
 
80
+ #
81
+ # Returns debugging status.
82
+ #
79
83
  def debug?
80
84
  return @debug
81
85
  end
82
86
 
87
+ #
88
+ # Sets the debugging on or off.
89
+ #
83
90
  def debug=(is_debug)
84
91
  @debug = is_debug
85
92
  if (@debug == true)
@@ -89,6 +96,9 @@ module Toodledo
89
96
  end
90
97
  end
91
98
 
99
+ #
100
+ # Returns the logger.
101
+ #
92
102
  def logger
93
103
  return @logger
94
104
  end
@@ -293,6 +303,20 @@ module Toodledo
293
303
  end
294
304
  end
295
305
 
306
+ #
307
+ # Prints all active tasks nested by context.
308
+ #
309
+ def list_tasks_by_context(session, line)
310
+ folder = parse_folder(line)
311
+
312
+ session.get_contexts().each do |context|
313
+ criteria = { :folder => folder, :context => context, :notcomp => true }
314
+ tasks = session.get_tasks(criteria)
315
+ print "#{context.name}" if (! tasks.empty?)
316
+ tasks.each { |task| print " " + @formatters[:task].format(task) }
317
+ end
318
+ end
319
+
296
320
  #
297
321
  # Lists the goals. Takes an optional argument of
298
322
  # 'short', 'medium' or 'life'.
@@ -359,10 +383,8 @@ module Toodledo
359
383
  # The order of symbols does not matter, but the title must be the last thing
360
384
  # on the line.
361
385
  #
362
- # add @[Deep Space] *Action ^[For Great Justice] Take off every Zig
386
+ # add @[Deep Space] !top *Action ^[For Great Justice] Take off every Zig
363
387
  #
364
- # There is no priority handling in this method. It may be added if there is
365
- # demand for it.
366
388
  def add_task(session, line)
367
389
  context = parse_context(line)
368
390
  folder = parse_folder(line)
@@ -397,6 +419,9 @@ module Toodledo
397
419
  print "Task #{task_id} added."
398
420
  end
399
421
 
422
+ #
423
+ # Adds context.
424
+ #
400
425
  def add_context(session, input)
401
426
 
402
427
  title = input.strip
@@ -406,6 +431,9 @@ module Toodledo
406
431
  print "Context #{context_id} added."
407
432
  end
408
433
 
434
+ #
435
+ # Adds goal.
436
+ #
409
437
  def add_goal(session, input)
410
438
  input.strip!
411
439
 
@@ -455,7 +483,7 @@ module Toodledo
455
483
  # Edits a single task. This method allows you to change the symbols on a
456
484
  # task. Note that you must specify the ID here.
457
485
  #
458
- # edit *Action 12345
486
+ # edit *Action !top 12345
459
487
  def edit_task(session, input)
460
488
  logger.debug("edit_task: #{input.inspect}")
461
489
 
@@ -522,7 +550,8 @@ module Toodledo
522
550
  #
523
551
  # delete 123
524
552
  #
525
- def delete_task(session, line)
553
+ def delete_task(session, line)
554
+ logger.debug("delete_task: #{line.inspect}")
526
555
  task_id = line
527
556
 
528
557
  if (task_id == nil)
@@ -538,7 +567,12 @@ module Toodledo
538
567
  end
539
568
  end
540
569
 
570
+ #
571
+ # Deletes context.
572
+ #
541
573
  def delete_context(session, line)
574
+ logger.debug("delete_context #{line.inspect}")
575
+
542
576
  id = line
543
577
 
544
578
  id.strip!
@@ -550,6 +584,9 @@ module Toodledo
550
584
  end
551
585
  end
552
586
 
587
+ #
588
+ # Deletes goal.
589
+ #
553
590
  def delete_goal(session, line)
554
591
  id = line
555
592
 
@@ -562,6 +599,9 @@ module Toodledo
562
599
  end
563
600
  end
564
601
 
602
+ #
603
+ # Deletes folder
604
+ #
565
605
  def delete_folder(session, line)
566
606
  id = line
567
607
 
@@ -573,8 +613,10 @@ module Toodledo
573
613
  print "Folder #{id} could not be deleted!"
574
614
  end
575
615
  end
576
-
616
+
617
+ #
577
618
  # Prints out a single line.
619
+ #
578
620
  def print(line = nil)
579
621
  if (line == nil)
580
622
  puts
@@ -29,6 +29,19 @@ module Toodledo
29
29
  fmt = '%m/%d/%Y %I:%M %p'
30
30
  msg += " \#[#{task.duedatemodifier}#{task.duedate.strftime(fmt)}]"
31
31
  end
32
+
33
+ if (task.startdate != nil)
34
+ fmt = '%m/%d/%Y'
35
+ msg += " startdate[#{task.startdate.strftime(fmt)}]"
36
+ end
37
+
38
+ if (task.status != Status::NONE)
39
+ msg += " status[#{readable_status(task.status)}]"
40
+ end
41
+
42
+ if (task.star)
43
+ msg += " starred"
44
+ end
32
45
 
33
46
  if (task.tag != nil)
34
47
  msg += " tag[#{task.tag}]"
@@ -46,7 +59,7 @@ module Toodledo
46
59
  msg += " timer[#{task.timer}]"
47
60
  end
48
61
 
49
- if (task.num_children != nil)
62
+ if (task.num_children != nil && task.num_children > 0)
50
63
  msg += " children[#{task.num_children}]"
51
64
  end
52
65
 
@@ -76,6 +89,9 @@ module Toodledo
76
89
  end
77
90
  end
78
91
 
92
+ #
93
+ # Returns a string matching the numeric repeat code.
94
+ #
79
95
  def readable_repeat(repeat)
80
96
  case repeat
81
97
  when Repeat::NONE
@@ -100,6 +116,36 @@ module Toodledo
100
116
  ''
101
117
  end
102
118
  end
119
+
120
+ #
121
+ # Return a readable status given the numeric code.
122
+ #
123
+ def readable_status(status)
124
+ case status
125
+ when Status::NONE
126
+ 'none'
127
+ when Status::NEXT_ACTION
128
+ 'Next Action'
129
+ when Status::ACTIVE
130
+ 'Active'
131
+ when Status::PLANNING
132
+ 'Planning'
133
+ when Status::DELEGATED
134
+ 'Delegated'
135
+ when Status::WAITING
136
+ 'Waiting'
137
+ when Status::HOLD
138
+ 'Hold'
139
+ when Status::POSTPONED
140
+ 'Postponed'
141
+ when Status::SOMEDAY
142
+ 'Someday'
143
+ when Status::CANCELLED
144
+ 'Cancelled'
145
+ when Status::REFERENCE
146
+ 'Reference'
147
+ end
148
+ end
103
149
  end
104
150
  end
105
151
  end
@@ -1,8 +1,6 @@
1
- #
2
- # To change this template, choose Tools | Templates
3
- # and open the template in the editor.
4
-
5
-
1
+ #
2
+ # The value values for repeats
3
+ #
6
4
  module Toodledo
7
5
  class Repeat
8
6
 
@@ -15,6 +13,7 @@ module Toodledo
15
13
  BIMONTHLY = 6
16
14
  SEMIANNUALLY = 7
17
15
  QUARTERLY = 8
16
+ WITH_PARENT = 9
18
17
 
19
18
  REPEAT_ARRAY = [
20
19
  NONE,
@@ -25,7 +24,8 @@ module Toodledo
25
24
  BIWEEKLY,
26
25
  BIMONTHLY,
27
26
  SEMIANNUALLY,
28
- QUARTERLY
27
+ QUARTERLY,
28
+ WITH_PARENT
29
29
  ]
30
30
 
31
31
  def self.each
@@ -350,6 +350,9 @@ module Toodledo
350
350
  # * compbefore
351
351
  # * compafter
352
352
  # * notcomp
353
+ # * star
354
+ # * status
355
+ # * startdate
353
356
  #
354
357
  # Returns an array of tasks. This information is never cached.
355
358
  def get_tasks(params={})
@@ -420,7 +423,19 @@ module Toodledo
420
423
  # * compafter : A date formated as YYYY-MM-DD. Used to find tasks with a
421
424
  # completed date after this date.
422
425
  handle_date(myhash, params, :compafter)
423
-
426
+
427
+ # startbefore:
428
+ handle_date(myhash, params, :startbefore)
429
+
430
+ # startafter:
431
+ handle_date(myhash, params, :startafter)
432
+
433
+ # star
434
+ handle_boolean(myhash, params, :star)
435
+
436
+ # status
437
+ handle_status(myhash, params)
438
+
424
439
  # * notcomp : Set to 1 to omit completed tasks. Omit variable, or set to 0
425
440
  # to retrieve both completed and uncompleted tasks.
426
441
  handle_boolean(myhash, params, :notcomp)
@@ -482,6 +497,9 @@ module Toodledo
482
497
 
483
498
  # Goal handling
484
499
  handle_goal(myhash, params)
500
+
501
+ # Add the start date if it's been added.
502
+ handle_date(myhash, params, :startdate)
485
503
 
486
504
  # duedate handling. Take either a string or a Time object.'YYYY-MM-DD'
487
505
  handle_date(myhash, params, :duedate)
@@ -497,7 +515,14 @@ module Toodledo
497
515
 
498
516
  # priority use the map to change from the symbol to the raw numeric value.
499
517
  handle_priority(myhash, params)
518
+
519
+ # Handle the star.
520
+ handle_boolean(myhash, params, :star)
500
521
 
522
+ # Handle the status date.
523
+ handle_status(myhash, params)
524
+
525
+ # Handle the note.
501
526
  handle_string(myhash, params, :note)
502
527
 
503
528
  result = call('addTask', myhash, @key)
@@ -1121,6 +1146,19 @@ module Toodledo
1121
1146
 
1122
1147
  myhash.merge!({ :repeat => repeat })
1123
1148
  end
1149
+
1150
+ # Handles the status parameter
1151
+ def handle_status(myhash, params)
1152
+ status = params[:status]
1153
+
1154
+ return if (status == nil)
1155
+
1156
+ if (! Status.valid?(status))
1157
+ raise "Invalid status value: #{status}"
1158
+ end
1159
+
1160
+ myhash.merge!({ :status => status })
1161
+ end
1124
1162
 
1125
1163
  # Handles the priority. This must be one of several values.
1126
1164
  def handle_priority(myhash, params)
@@ -0,0 +1,44 @@
1
+ #
2
+ # The possible values for the status field of a task.
3
+ #
4
+ class Status
5
+
6
+ NONE = 0
7
+ NEXT_ACTION = 1
8
+ ACTIVE = 2
9
+ PLANNING = 3
10
+ DELEGATED = 4
11
+ WAITING = 5
12
+ HOLD = 6
13
+ POSTPONED = 7
14
+ SOMEDAY = 8
15
+ CANCELLED = 9
16
+ REFERENCE = 10
17
+
18
+ STATUS_ARRAY = [
19
+ NONE,
20
+ NEXT_ACTION,
21
+ ACTIVE,
22
+ PLANNING,
23
+ DELEGATED,
24
+ WAITING,
25
+ HOLD,
26
+ POSTPONED,
27
+ SOMEDAY,
28
+ CANCELLED,
29
+ REFERENCE
30
+ ]
31
+
32
+ def self.each
33
+ STATUS_ARRAY.each{|value| yield(value)}
34
+ end
35
+
36
+ def self.valid?(input)
37
+ for status in STATUS_ARRAY
38
+ if (status == input)
39
+ return true
40
+ end
41
+ end
42
+ return false
43
+ end
44
+ end
@@ -26,7 +26,14 @@ module Toodledo
26
26
  attr_reader :parent_id, :parent, :title, :tag
27
27
  attr_reader :added, :modified, :completed
28
28
  attr_reader :duedate, :duedatemodifier
29
- attr_reader :repeat, :priority, :length, :timer, :note
29
+ attr_reader :repeat, :priority
30
+ attr_reader :length, :timer
31
+ attr_reader :note
32
+
33
+ # as of 3.90
34
+ attr_reader :status
35
+ attr_reader :startdate
36
+ attr_reader :star
30
37
 
31
38
  def server_id
32
39
  return @id
@@ -79,6 +86,10 @@ module Toodledo
79
86
  @length = params[:length]
80
87
  @timer = params[:timer]
81
88
  @note = params[:note]
89
+
90
+ @startdate = params[:startdate]
91
+ @status = params[:status]
92
+ @star = params[:star]
82
93
  end
83
94
 
84
95
  def completed?
@@ -130,8 +141,11 @@ module Toodledo
130
141
  # <repeat>1</repeat>
131
142
  # <priority>2</priority>
132
143
  # <length>20</length>
133
- # <timer>0</timer>
144
+ # <timer onfor=''>0</timer>
134
145
  # <note></note>
146
+ # <startdate></startdate>
147
+ # <status>0</status>
148
+ # <star></star>
135
149
  # </task> #++
136
150
 
137
151
  id = el.elements['id'].text
@@ -220,6 +234,16 @@ module Toodledo
220
234
  note = el.elements['note'].text
221
235
  note = nil if (note == '0')
222
236
 
237
+ startdate = el.elements['startdate'].text
238
+ if (startdate != nil)
239
+ startdate = Date.strptime(startdate, Session::DATE_FORMAT)
240
+ end
241
+
242
+ status = el.elements['status'].text
243
+ status = Status::NONE if (status == '0')
244
+
245
+ star = (el.elements['star'].text.to_i == 1)
246
+
223
247
  params = {
224
248
  :parent_id => parent_id,
225
249
  :parent => parent,
@@ -239,6 +263,9 @@ module Toodledo
239
263
  :length => length,
240
264
  :timer => timer,
241
265
  :note => note,
266
+ :startdate => startdate,
267
+ :status => status,
268
+ :star => star
242
269
  }
243
270
  return Task.new(id, params)
244
271
  end
@@ -118,6 +118,7 @@ module Toodledo
118
118
  :folder => Folder::NO_FOLDER,
119
119
  :context => Context::NO_CONTEXT,
120
120
  :goal => Goal::NO_GOAL,
121
+ :status => Status::NONE,
121
122
  :repeat => Repeat::NONE
122
123
  }
123
124
  task = Task.new(1234, params)
@@ -139,16 +140,43 @@ module Toodledo
139
140
  :context => Context.new(345, 'test context'),
140
141
  :goal => Goal.new(342341, 0, 0, 'test goal'),
141
142
  :repeat => Repeat::BIWEEKLY,
142
- :tag => 'some tag'
143
+ :status => Status::NEXT_ACTION,
144
+ :tag => 'some tag',
145
+ :star => true
143
146
  }
144
147
  task = Task.new(1234, params)
145
148
  tasks = [ task ]
146
149
  @session.should_receive(:get_tasks).and_return(tasks)
147
- @client.should_receive(:print).with('<1234> -- !low *[test folder] @[test context] ^[test goal] repeat[biweekly] tag[some tag] foo')
150
+ @client.should_receive(:print).with('<1234> -- !low *[test folder] @[test context] ^[test goal] repeat[biweekly] status[Next Action] starred tag[some tag] foo')
148
151
 
149
152
  input = ''
150
153
  @client.list_tasks(@session, input)
151
154
  end
155
+
156
+ def test_list_tasks_by_context()
157
+ context = Context.new(345, 'test context')
158
+ folder = Folder.new(1234, 0, 0, 'test folder')
159
+
160
+ params = {
161
+ :priority => Priority::LOW,
162
+ :title => 'foo',
163
+ :folder => folder,
164
+ :goal => Goal::NO_GOAL,
165
+ :repeat => Repeat::NONE,
166
+ :status => Status::NONE,
167
+ :context => context
168
+ }
169
+ task = Task.new(1234, params)
170
+ tasks = [ task ]
171
+ contexts = [ context ]
172
+ @session.should_receive(:get_contexts).and_return(contexts)
173
+ @session.should_receive(:get_tasks).and_return(tasks)
174
+ @client.should_receive(:print).with('test context')
175
+ @client.should_receive(:print).with(' <1234> -- !low *[test folder] @[test context] foo')
176
+
177
+ input = ''
178
+ @client.list_tasks_by_context(@session, input)
179
+ end
152
180
 
153
181
  def test_list_contexts()
154
182
  context = Context.new(1234, 'Context')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toodledo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Sargent
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-19 00:00:00 -07:00
12
+ date: 2008-05-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,7 @@ files:
84
84
  - lib/toodledo/repeat.rb
85
85
  - lib/toodledo/server_error.rb
86
86
  - lib/toodledo/session.rb
87
+ - lib/toodledo/status.rb
87
88
  - lib/toodledo/task.rb
88
89
  - test/client_test.rb
89
90
  - test/parser_helper_test.rb
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  requirements: []
113
114
 
114
115
  rubyforge_project: toodledo
115
- rubygems_version: 1.0.1
116
+ rubygems_version: 1.1.1
116
117
  signing_key:
117
118
  specification_version: 2
118
119
  summary: A command line client and API to Toodledo