gwtf 0.3.0 → 0.4.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.
@@ -2,10 +2,12 @@ module Gwtf
2
2
  require 'gwtf/items'
3
3
  require 'gwtf/item'
4
4
  require 'gwtf/version'
5
+ require 'gwtf/notifier/base'
5
6
  require 'json'
6
7
  require 'yaml'
7
8
  require 'fileutils'
8
9
  require 'tempfile'
10
+ require 'uri'
9
11
 
10
12
  def self.each_command
11
13
  commands_dir = File.join(File.dirname(__FILE__), "gwtf", "commands")
@@ -23,6 +25,24 @@ module Gwtf
23
25
  end.compact.sort
24
26
  end
25
27
 
28
+ def self.notifier_for_address(address)
29
+ uri = URI.parse(address)
30
+
31
+ case uri.scheme
32
+ when nil, "email"
33
+ require 'gwtf/notifier/email'
34
+ return Notifier::Email
35
+ when "boxcar"
36
+ gem 'boxcar_api', '>= 1.2.0'
37
+ require 'boxcar_api'
38
+ require 'gwtf/notifier/boxcar'
39
+
40
+ return Notifier::Boxcar
41
+ else
42
+ raise "Do not know how to handle addresses of type #{uri.scheme} for #{address}"
43
+ end
44
+ end
45
+
26
46
  # borrowed from ohai, thanks Adam.
27
47
  def self.seconds_to_human(seconds)
28
48
  days = seconds.to_i / 86400
@@ -32,8 +32,10 @@ command [:list, :ls, :l] do |c|
32
32
  Gwtf.projects(global_options[:data]).each do |project|
33
33
  items = Gwtf::Items.new(File.join(global_options[:data], project), project)
34
34
 
35
- puts items.list_text(options[:all]) if items.item_ids.size > 0
36
- puts
35
+ if items.item_ids.size > 0
36
+ text = items.list_text(options[:all], true)
37
+ puts text if text
38
+ end
37
39
  end
38
40
  else
39
41
  puts
@@ -42,28 +42,7 @@ command [:remind, :rem] do |c|
42
42
  item = @items.load_item(args.first)
43
43
 
44
44
  unless options[:ifopen] && item.closed?
45
- begin
46
- tmp = Tempfile.new("gwtf")
47
- tmp.write(item.summary)
48
- tmp.rewind
49
-
50
- if global_options[:project] == "default"
51
- subject = "Reminder for item %s" % [ args.first ]
52
- else
53
- subject = "Reminder for item %s in %s project" % [ args.first, global_options[:project] ]
54
- end
55
-
56
- system("cat #{tmp.path} | mail -s '#{subject}' '#{options[:recipient]}'")
57
-
58
- if options[:done]
59
- item.record_work("Closing item as part of scheduled reminder")
60
- item.close
61
- item.save
62
- end
63
- ensure
64
- tmp.close
65
- tmp.unlink
66
- end
45
+ item.send_reminder(options[:recipient], options[:done], Gwtf.notifier_for_address(options[:recipient]))
67
46
  end
68
47
  end
69
48
  end
@@ -25,7 +25,7 @@ command :shell do |c|
25
25
  begin
26
26
  description = STDIN.gets.chomp
27
27
  if description =~ /^(done|close)!\s*(.+)/
28
- description = $1
28
+ description = $2
29
29
  item.close
30
30
  end
31
31
  rescue Exception
@@ -185,6 +185,16 @@ module Gwtf
185
185
  system "echo gwtf --project='%s' remind %s %s | at %s" % [ @project, command_args.join(" "), item_id, timespec]
186
186
  end
187
187
 
188
+ def send_reminder(recipient, mark_as_done, klass)
189
+ klass.new(self, recipient).notify
190
+
191
+ if mark_as_done
192
+ record_work("Closing item as part of scheduled reminder")
193
+ close
194
+ save
195
+ end
196
+ end
197
+
188
198
  # simple read from the class:
189
199
  #
190
200
  # >> i.description
@@ -91,7 +91,7 @@ module Gwtf
91
91
  end
92
92
 
93
93
  # Returns a blob of text that represents a list of items in a project
94
- def list_text(all=false)
94
+ def list_text(all=false, only_if_active=false)
95
95
  list = StringIO.new
96
96
  items = StringIO.new
97
97
 
@@ -103,9 +103,14 @@ module Gwtf
103
103
  items.puts item if (all || item.open?)
104
104
  end
105
105
 
106
- list.puts "Project %s items: %d / %d" % [ @project, count["open"], count["open"] + count["closed"] ]
106
+ count["total"] = count["open"] + count["closed"]
107
+
108
+ return nil if only_if_active && count["open"] == 0
109
+
110
+ list.puts "Project %s items: %d / %d" % [ @project, count["open"], count["total"] ]
107
111
  list.puts
108
112
  list.puts items.string
113
+ list.puts
109
114
 
110
115
  list.string
111
116
  end
@@ -0,0 +1,16 @@
1
+ module Gwtf
2
+ module Notifier
3
+ class Base
4
+ attr_reader :item, :recipient
5
+
6
+ def initialize(item, recipient)
7
+ @item = item
8
+ @recipient = recipient
9
+ end
10
+
11
+ def notify
12
+ raise "Notifiers must impliment the notify method"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ module Gwtf
2
+ module Notifier
3
+ class Boxcar<Base
4
+ def notify
5
+ config_file = File.join(Etc.getpwuid.dir, ".boxcar")
6
+
7
+ raise "Please configure boxcar in ~/.boxcar" unless File.exist?(config_file)
8
+
9
+ config = YAML.load_file(config_file)
10
+
11
+ raise "Config needs to be a hash" unless config.is_a?(Hash)
12
+ raise "Config must include :apikey" unless config[:apikey]
13
+ raise "Config must include :apisecret" unless config[:apisecret]
14
+ raise "Config must include :serviceid" unless config[:serviceid]
15
+ raise "Config must include :sender" unless config[:sender]
16
+
17
+ uri = URI.parse(recipient)
18
+
19
+ raise "Recipient must have a user portion" unless uri.user
20
+ raise "Recipient must have a host portion" unless uri.host
21
+
22
+ email_address = "%s@%s" % [uri.user, uri.host]
23
+
24
+ bp = BoxcarAPI::Provider.new(config[:apikey], config[:apisecret], config[:sender])
25
+
26
+ if item.project == "default"
27
+ msg = "%s: %s" % [ item.item_id, item.subject ]
28
+ else
29
+ msg = "%s:%s: %s" % [ item.project, item.item_id, item.subject ]
30
+ end
31
+
32
+ res = bp.notify(email_address, msg, {:from_screen_name => config[:sender], :icon_url => "http://www.devco.net/images/gwtf.jpg"})
33
+
34
+ raise "Failed to send message to Boxcar, got code #{res.code}" unless res.code == 200
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ module Gwtf
2
+ module Notifier
3
+ class Email<Base
4
+ def notify
5
+ begin
6
+ tmp = Tempfile.new("gwtf")
7
+ tmp.write(item.summary)
8
+ tmp.rewind
9
+
10
+ if item.project == "default"
11
+ subject = "Reminder for item %s" % [ item.item_id ]
12
+ else
13
+ subject = "Reminder for item %s in %s project" % [ item.item_id, item.project ]
14
+ end
15
+
16
+ system("cat #{tmp.path} | mail -s '#{subject}' '#{recipient}'")
17
+ ensure
18
+ tmp.close
19
+ tmp.unlink
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Gwtf
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gwtf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.I.Pienaar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-13 00:00:00 +00:00
18
+ date: 2012-03-15 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,22 @@ dependencies:
76
76
  version: 1.5.1
77
77
  type: :runtime
78
78
  version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: boxcar_api
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ hash: 31
88
+ segments:
89
+ - 1
90
+ - 2
91
+ - 0
92
+ version: 1.2.0
93
+ type: :runtime
94
+ version_requirements: *id005
79
95
  description: A Unix cli centric todo manager
80
96
  email: rip@devco.net
81
97
  executables:
@@ -95,6 +111,9 @@ files:
95
111
  - lib/gwtf/commands/new_command.rb
96
112
  - lib/gwtf/commands/list_command.rb
97
113
  - lib/gwtf/commands/remind_command.rb
114
+ - lib/gwtf/notifier/email.rb
115
+ - lib/gwtf/notifier/boxcar.rb
116
+ - lib/gwtf/notifier/base.rb
98
117
  - lib/gwtf/version.rb
99
118
  - lib/gwtf/item.rb
100
119
  - lib/gwtf/items.rb