robut-cron 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in robut-cron.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 AirGap IT/Kit Plummer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Robut::Cron
2
+
3
+ Schedule "message" posts via a cron-like interface from an XMPP/HipChat
4
+ session.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'robut-cron'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install robut-cron
19
+
20
+ ## Usage
21
+
22
+ Hmmn. Something like this from inside the chat session.
23
+
24
+ "#{at_nick} cron new * * * * * <message> - will send this message on the
25
+ cron schedule",
26
+ "#{at_nick} cron list - will return the list of job ids",
27
+ "#{at_nick} cron stop <id> - will remove a job"
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/robut-cron.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'rufus-scheduler'
2
+
3
+ class Robut::Plugin::Cron
4
+ include Robut::Plugin
5
+
6
+ @@skeds = Hash.new
7
+
8
+ # Returns a description of how to use this plugin
9
+ def usage
10
+ ["#{at_nick} cron new * * * * * <message> - will send this message on the cron schedule",
11
+ "#{at_nick} cron list - will return the list of job ids",
12
+ "#{at_nick} cron stop <id> - will remove a job"]
13
+ end
14
+ def handle(time, sender_nick, message)
15
+ if sent_to_me?(message) && !message.include?(" - ") && !message.include?("help")
16
+ # Need to separate the cron schedule from the message
17
+ # @bo cron '* * * * *' message
18
+
19
+ a = message.split(" ")
20
+ if a[1] == "cron"
21
+ command = a[2]
22
+
23
+ case command
24
+ when "new"
25
+ create(a[3..7].join(" "), a[8..a.count()-1].join(" "))
26
+ when "list"
27
+ reply list
28
+ when "stop"
29
+ reply stop(a[3..a.count()-1].join(" "))
30
+ else
31
+ reply "i don't understand that cron command"
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def create(cron, message)
38
+ begin
39
+ scheduler = Rufus::Scheduler.start_new
40
+ job = scheduler.cron cron do |job|
41
+
42
+ if @@skeds.has_value? job
43
+ connection = self.connection
44
+ reply(message)
45
+ else
46
+ job.unschedule
47
+ end
48
+
49
+ end
50
+ @@skeds[message] = job
51
+ reply "new cron job with id: #{message}"
52
+ rescue ArgumentError
53
+ reply "argument error, perhaps the cronline?"
54
+ end
55
+ end
56
+
57
+ def list()
58
+ if @@skeds.empty?
59
+ "no jobs!"
60
+ else
61
+ @@skeds.keys.to_s
62
+ end
63
+ end
64
+
65
+ def stop(id)
66
+ if @@skeds.has_key?(id)
67
+ @@skeds.delete(id)
68
+ "stopping #{id}"
69
+ else
70
+ "invalid id: #{id}, can't stop that"
71
+ end
72
+ end
73
+
74
+ end
75
+
@@ -0,0 +1,5 @@
1
+ module Robut
2
+ module Cron
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/robut-cron/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kit Plummer"]
6
+ gem.email = ["kitplummer@gmail.com"]
7
+ gem.description = %q{Robut cron plugin}
8
+ gem.summary = %q{Have Robut send messages on a cron schedule.}
9
+ gem.homepage = "https://github.com/airgap/robut-cron"
10
+ gem.license = "MIT"
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "robut-cron"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Robut::Cron::VERSION
17
+
18
+ gem.add_dependency("robut")
19
+ gem.add_dependency("rufus-scheduler", "~> 2.0.23")
20
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robut-cron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kit Plummer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: robut
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rufus-scheduler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.23
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.23
46
+ description: Robut cron plugin
47
+ email:
48
+ - kitplummer@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/robut-cron.rb
59
+ - lib/robut-cron/version.rb
60
+ - robut-cron.gemspec
61
+ homepage: https://github.com/airgap/robut-cron
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Have Robut send messages on a cron schedule.
86
+ test_files: []