gwtf 0.8.0 → 0.9.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.
@@ -54,7 +54,7 @@ command [:new, :add, :n, :a, :c] do |c|
54
54
 
55
55
  print "Creating reminder at job for item #{item.item_id}: "
56
56
 
57
- item.schedule_reminer(options[:remind], options[:recipient], options[:done], options[:ifopen])
57
+ item.schedule_reminder(options[:remind], options[:recipient], options[:done], options[:ifopen])
58
58
  end
59
59
 
60
60
  item.save
@@ -30,22 +30,32 @@ command [:remind, :rem] do |c|
30
30
  c.default_value nil
31
31
  c.flag [:at]
32
32
 
33
+ c.desc "Cancel a previously set reminder"
34
+ c.default_value nil
35
+ c.switch [:cancel]
36
+
33
37
  c.action do |global_options,options,args|
34
38
  raise "Please supply an item ID to remind about" if args.empty?
35
39
 
36
40
  STDOUT.sync = true
37
41
 
38
42
  unless options[:send]
39
- if args.first =~ /^\d+$/ # got an item id, schedule a reminder
40
- unless options[:at]
41
- raise "Please specify a valid at(1) time specification with --at after the item id" unless args.size >= 2
42
- options[:at] = args[1..-1].join(" ")
43
+ if args.first =~ /^\d+$/ # got an item id, manage a reminder
44
+ if options[:cancel]
45
+ item = @items.load_item(args.first)
46
+ item.cancel_reminder
47
+ else
48
+ unless options[:at]
49
+ raise "Please specify a valid at(1) time specification with --at after the item id" unless args.size >= 2
50
+ options[:at] = args[1..-1].join(" ")
51
+ end
52
+
53
+ print "Creating reminder at job for item #{args.first}: "
54
+
55
+ item = @items.load_item(args.first)
56
+ item.schedule_reminder(options[:at], options[:recipient], options[:done], options[:ifopen])
57
+ item.save
43
58
  end
44
-
45
- print "Creating reminder at job for item #{args.first}: "
46
-
47
- @items.load_item(args.first).schedule_reminer(options[:at], options[:recipient], options[:done], options[:ifopen])
48
-
49
59
  else # new reminder in the 'reminders' project
50
60
  raise "Please specify an at(1) time specification" unless options[:at]
51
61
  raise "Please specify a subject for the reminder item" if args.empty?
@@ -58,7 +68,7 @@ command [:remind, :rem] do |c|
58
68
  reminder.subject = args.join(" ")
59
69
 
60
70
  print "Creating reminder at job for item #{reminder.item_id}: "
61
- out = reminder.schedule_reminer(options[:at], options[:recipient], true, true)
71
+ out = reminder.schedule_reminder(options[:at], options[:recipient], true, true)
62
72
 
63
73
  if out =~ /job (\d+) at (\d+-\d+-\d+)\s/
64
74
  reminder.due_date = reminder.date_to_due_date($2)
data/lib/gwtf/item.rb CHANGED
@@ -193,15 +193,17 @@ module Gwtf
193
193
  update_property(:status, "closed")
194
194
  end
195
195
 
196
- def schedule_reminer(timespec, recipient, done=false, ifopen=false)
196
+ def schedule_reminder(timespec, recipient, done=false, ifopen=false)
197
197
  command_args = ["--remind=%s" % [item_id]]
198
198
  command_args << "--recipient=%s" % [ recipient ]
199
199
  command_args << "--done" if done
200
200
  command_args << "--ifopen" if ifopen
201
201
 
202
202
  # attempt to parse the timespec with Chronic, if it cant then pass it onto at verbatim
203
- if time = Gwtf.parse_time(timespec)
204
- timespec = "-t %s" % [time.strftime("%Y%m%d%H%M")]
203
+ unless timespec.include?("+")
204
+ if time = Gwtf.parse_time(timespec)
205
+ timespec = "-t %s" % [time.strftime("%Y%m%d%H%M")]
206
+ end
205
207
  end
206
208
 
207
209
  command = "echo gwtf --project='%s' notify %s | at %s 2>&1" % [ @project, command_args.join(" "), timespec]
@@ -219,6 +221,17 @@ module Gwtf
219
221
  out
220
222
  end
221
223
 
224
+ def cancel_reminder
225
+ raise "No at job id recorded for this item, cannot cancel a reminder" unless has_at_job?
226
+
227
+ system("atrm %s" % at_job)
228
+
229
+ raise "Failed to remove the at job %s" % at_job unless $? == 0
230
+
231
+ update_property(:at_job, nil)
232
+ save
233
+ end
234
+
222
235
  def send_reminder(recipient, mark_as_done)
223
236
  recipient.split(",").each do |r|
224
237
  Gwtf.notifier_for_address(r.strip).new(self, r.strip).notify
@@ -9,29 +9,36 @@ module Gwtf
9
9
  config = YAML.load_file(config_file)
10
10
 
11
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]
12
+ raise "Config must include :icon_url" unless config[:icon_url]
13
+ raise "Config must include :source_name" unless config[:source_name]
14
+ raise "Config must include :sound" unless config[:sound]
16
15
 
17
16
  uri = URI.parse(recipient)
18
17
 
19
- raise "Recipient must have a user portion" unless uri.user
20
18
  raise "Recipient must have a host portion" unless uri.host
21
19
 
22
- email_address = "%s@%s" % [uri.user, uri.host]
23
-
24
- bp = BoxcarAPI::Provider.new(config[:apikey], config[:apisecret], config[:sender])
25
-
26
20
  if item.project == "default"
27
21
  msg = "%s: %s" % [ item.item_id, item.subject ]
28
22
  else
29
23
  msg = "%s:%s: %s" % [ item.project, item.item_id, item.subject ]
30
24
  end
31
25
 
32
- res = bp.notify(email_address, msg, {:from_screen_name => config[:sender], :icon_url => "http://www.devco.net/images/gwtf.jpg"})
26
+ api_uri = URI.parse("https://new.boxcar.io/api/notifications")
27
+ http = Net::HTTP.new(api_uri.host, api_uri.port)
28
+ http.use_ssl = true
29
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
30
+ request = Net::HTTP::Post.new(api_uri.path)
31
+
32
+ request.set_form_data("user_credentials" => uri.host,
33
+ "notification[title]" => item.subject,
34
+ "notification[long_message]" => msg,
35
+ "notification[sound]" => config[:sound],
36
+ "notification[source_name]" => config[:source_name],
37
+ "notification[icon_url]" => config[:icon_url])
38
+
39
+ res = http.request(request)
33
40
 
34
- raise "Failed to send message to Boxcar, got code #{res.code}" unless res.code == 200
41
+ raise "Failed to send message to Boxcar, got code #{res.code}" unless res.code == "201"
35
42
  end
36
43
  end
37
44
  end
data/lib/gwtf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gwtf
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.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: 63
4
+ hash: 59
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 8
8
+ - 9
9
9
  - 0
10
- version: 0.8.0
10
+ version: 0.9.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-04-19 00:00:00 +01:00
18
+ date: 2014-09-07 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -76,26 +76,10 @@ dependencies:
76
76
  version: 1.6.0
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
95
79
  - !ruby/object:Gem::Dependency
96
80
  name: chronic
97
81
  prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
82
+ requirement: &id005 !ruby/object:Gem::Requirement
99
83
  none: false
100
84
  requirements:
101
85
  - - ">="
@@ -105,7 +89,7 @@ dependencies:
105
89
  - 0
106
90
  version: "0"
107
91
  type: :runtime
108
- version_requirements: *id006
92
+ version_requirements: *id005
109
93
  description: A Unix cli centric todo manager
110
94
  email: rip@devco.net
111
95
  executables: