notifaction 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.notifaction.sample.yml +7 -0
- data/lib/notifaction.rb +10 -13
- data/lib/notifaction/config.rb +16 -0
- data/lib/notifaction/notify.rb +17 -18
- data/lib/notifaction/style.rb +29 -27
- data/lib/notifaction/type.rb +19 -3
- data/lib/notifaction/types/linux.rb +3 -3
- data/lib/notifaction/types/osx.rb +5 -3
- data/lib/notifaction/types/terminal.rb +19 -6
- data/lib/notifaction/utils.rb +11 -10
- data/lib/notifaction/version.rb +1 -1
- metadata +4 -4
- data/lib/notifaction/plugin.rb +0 -7
- data/lib/plugins/workingon.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1fbf23fc97a9f930d9dd79d440516eb4b33b148
|
4
|
+
data.tar.gz: eaf15cfb3496e21a565ae26d7710edc16a93ede9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b733df88dbbda18da7cb2f5e4563b37d918c72032e62f7dbc9481f2b9e94f39d683ac9db93583116fe5e03de6cbcbf1148550155692ed779779583362a0a57c
|
7
|
+
data.tar.gz: 4b63bc5169ee2ee76ffba4b9d79943b5d3d824dce2f36847b53fd861b1ca8f2c2f8cc3ff5feb614ae4eb23edb013437a3301b59ebaca8bcb0656597aefc38286
|
data/lib/notifaction.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'net/http'
|
4
|
-
require 'cgi'
|
1
|
+
require "time"
|
2
|
+
require "rbconfig"
|
5
3
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
4
|
+
require "notifaction/type"
|
5
|
+
require "notifaction/types/linux"
|
6
|
+
require "notifaction/types/osx"
|
7
|
+
require "notifaction/types/terminal"
|
8
|
+
require "notifaction/notify"
|
9
|
+
require "notifaction/config"
|
12
10
|
require "notifaction/version"
|
13
|
-
require
|
11
|
+
require "notifaction/utils"
|
14
12
|
|
15
|
-
|
16
|
-
end
|
13
|
+
$config = Notifaction::Cfg.new
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Notifaction
|
4
|
+
class Cfg
|
5
|
+
attr_accessor :hooks, :conf
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
conf = YAML::load(File.open(Dir.home + '/.notifaction.yml'))
|
9
|
+
|
10
|
+
@hooks = conf["hooks"] || []
|
11
|
+
@conf = conf["config"] || {}
|
12
|
+
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/notifaction/notify.rb
CHANGED
@@ -26,7 +26,7 @@ class Notify
|
|
26
26
|
def self.error(message, config = {})
|
27
27
|
handler = Notifaction::Type::Terminal.new
|
28
28
|
handler.error(message, config)
|
29
|
-
handler.quit unless config
|
29
|
+
handler.quit unless self.auto_quit_enabled(config)
|
30
30
|
end
|
31
31
|
|
32
32
|
# Prints a pre-formatted warning message to the console
|
@@ -66,16 +66,7 @@ class Notify
|
|
66
66
|
|
67
67
|
# Send status updates to WorkingOn
|
68
68
|
def self.workingon(message, print_info_message = false)
|
69
|
-
|
70
|
-
plugin = Plugin::WorkingOn.new
|
71
|
-
plugin.fire(message)
|
72
|
-
|
73
|
-
if print_info_message
|
74
|
-
info(message)
|
75
|
-
end
|
76
|
-
rescue Exception => e
|
77
|
-
error("Error notifying WO - #{e.message}")
|
78
|
-
end
|
69
|
+
self.deprecation_notice("0.3.0")
|
79
70
|
end
|
80
71
|
|
81
72
|
# pretty-print a spacer
|
@@ -85,6 +76,8 @@ class Notify
|
|
85
76
|
end
|
86
77
|
|
87
78
|
def self.configure
|
79
|
+
self.deprecation_notice("0.3.0")
|
80
|
+
|
88
81
|
yield self if block_given?
|
89
82
|
end
|
90
83
|
|
@@ -98,14 +91,20 @@ class Notify
|
|
98
91
|
|
99
92
|
# register new plugins
|
100
93
|
def self.plugins=(plugin_config_arr)
|
101
|
-
|
102
|
-
|
103
|
-
# include the requested plugin
|
104
|
-
require_relative "plugins/#{plugin.downcase}.rb"
|
94
|
+
self.deprecation_notice("0.3.0")
|
95
|
+
end
|
105
96
|
|
106
|
-
|
107
|
-
|
108
|
-
|
97
|
+
private_class_method
|
98
|
+
|
99
|
+
#
|
100
|
+
# @since 0.2.8
|
101
|
+
def deprecation_notice(version)
|
102
|
+
puts "Deprecated as of #{version}, current #{Notifaction::VERSION}"
|
109
103
|
end
|
110
104
|
|
105
|
+
#
|
106
|
+
# @since 0.3.0
|
107
|
+
def self.auto_quit_enabled(config)
|
108
|
+
config[:auto_quit] == false || $config.conf["auto_quit"] == false
|
109
|
+
end
|
111
110
|
end
|
data/lib/notifaction/style.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
:
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
module Notifaction
|
2
|
+
module Style
|
3
|
+
@map = {
|
4
|
+
colour: {
|
5
|
+
red: 31,
|
6
|
+
green: 32,
|
7
|
+
yellow: 33,
|
8
|
+
blue: 34,
|
9
|
+
magenta: 35,
|
10
|
+
cyan: 36,
|
11
|
+
white: 37,
|
12
|
+
null: 0
|
13
|
+
},
|
14
|
+
style: {
|
15
|
+
reset: 0,
|
16
|
+
bold: 1,
|
17
|
+
underline: 4,
|
18
|
+
normal: ""
|
19
|
+
}
|
18
20
|
}
|
19
|
-
}
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def self.format(message, colour = nil, style = nil)
|
23
|
+
c = @map[:colour][colour.to_sym] unless colour.nil?
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
if style.nil?
|
26
|
+
t = 0
|
27
|
+
else
|
28
|
+
t = @map[:style][style.to_sym]
|
29
|
+
end
|
30
|
+
|
31
|
+
"\e[#{t};#{c}m#{message}\e[0m"
|
28
32
|
end
|
29
|
-
|
30
|
-
"\e[#{t};#{c}m#{message}\e[0m"
|
31
33
|
end
|
32
|
-
end
|
34
|
+
end
|
data/lib/notifaction/type.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
|
1
4
|
module Notifaction
|
2
5
|
module Type
|
3
6
|
class Base
|
4
|
-
|
5
7
|
#
|
6
8
|
# @since 0.2.8
|
7
9
|
def deprecation_notice(version)
|
8
|
-
puts "Deprecated as of #{version}"
|
10
|
+
puts "Deprecated as of #{version}, current #{Notifaction::VERSION}"
|
9
11
|
end
|
10
12
|
|
11
13
|
#
|
@@ -14,6 +16,20 @@ module Notifaction
|
|
14
16
|
exit
|
15
17
|
end
|
16
18
|
|
19
|
+
#
|
20
|
+
# @since 0.3.0
|
21
|
+
def fire_hooks(payload)
|
22
|
+
hooks = $config.hooks
|
23
|
+
|
24
|
+
return if hooks.nil?
|
25
|
+
|
26
|
+
hooks.each do |uri|
|
27
|
+
uri = URI.parse(uri)
|
28
|
+
|
29
|
+
response = Net::HTTP.post_form(uri, payload)
|
30
|
+
response.code.to_i < 300
|
31
|
+
end
|
32
|
+
end
|
17
33
|
end
|
18
34
|
end
|
19
|
-
end
|
35
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Notifaction
|
2
2
|
module Type
|
3
3
|
class Linux < Type::Base
|
4
|
-
|
5
4
|
def bubble(message, title)
|
6
5
|
@response = `notify-send "#{title}" "#{message}"`
|
7
6
|
$?.exitstatus == 0
|
7
|
+
|
8
|
+
fire_hooks({ method: __method__, message: message, title: title })
|
8
9
|
end
|
9
10
|
|
10
11
|
def modal(message, title)
|
11
12
|
nil
|
12
13
|
end
|
13
|
-
|
14
14
|
end
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
module Notifaction
|
2
2
|
module Type
|
3
3
|
class OSX < Type::Base
|
4
|
-
|
5
4
|
def bubble(message, title)
|
6
5
|
@response = `osascript -e 'display notification "#{message}" with title "#{title}"'`
|
7
6
|
$?.exitstatus == 0
|
7
|
+
|
8
|
+
fire_hooks(method: __method__, message: message, title: title)
|
8
9
|
end
|
9
10
|
|
10
11
|
def modal(message, title, icon = :caution)
|
11
12
|
@response = `osascript -e 'tell app "System Events" to display dialog "#{message}" buttons {"OK"} default button 1 with title "#{title}" with icon #{icon}'`
|
12
13
|
$?.exitstatus == 0
|
13
|
-
end
|
14
14
|
|
15
|
+
fire_hooks(method: __method__, message: message, title: title)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
end
|
19
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "notifaction/style"
|
2
2
|
|
3
3
|
module Notifaction
|
4
4
|
module Type
|
@@ -34,7 +34,7 @@ module Notifaction
|
|
34
34
|
#
|
35
35
|
# @since 0.2.8
|
36
36
|
def sinfo(message, config)
|
37
|
-
deprecation_notice(
|
37
|
+
deprecation_notice("0.2.8")
|
38
38
|
|
39
39
|
note(message, config, :cyan)
|
40
40
|
end
|
@@ -70,15 +70,28 @@ module Notifaction
|
|
70
70
|
message += " - #{Utils.formatted_time}"
|
71
71
|
else
|
72
72
|
# update message content based on configuration variables
|
73
|
-
message += " - #{Utils.formatted_time}" if config
|
74
|
-
message = "#{config[:symbol]} #{message}" if config
|
73
|
+
message += " - #{Utils.formatted_time}" if show_time(config)
|
74
|
+
message = "#{config[:symbol]} #{message}" if show_symbol(config)
|
75
75
|
end
|
76
76
|
|
77
|
-
puts Style.format(message, colour, style) unless config
|
77
|
+
puts Style.format(message, colour, style) unless show_message(config)
|
78
|
+
|
79
|
+
fire_hooks(method: __method__, message: message, config: config)
|
78
80
|
|
79
81
|
true
|
80
82
|
end
|
81
83
|
|
84
|
+
def show_symbol(config)
|
85
|
+
config[:symbol] || config[:fancy] || $config.conf["fancy"] == true
|
86
|
+
end
|
87
|
+
|
88
|
+
def show_time(config)
|
89
|
+
config[:show_time] || $config.conf["show_time"]
|
90
|
+
end
|
91
|
+
|
92
|
+
def show_message(config)
|
93
|
+
config[:print] == false || $config.conf["print"] == false
|
94
|
+
end
|
82
95
|
end
|
83
96
|
end
|
84
|
-
end
|
97
|
+
end
|
data/lib/notifaction/utils.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
time
|
1
|
+
module Notifaction
|
2
|
+
class Utils
|
3
|
+
def self.formatted_time(time = nil)
|
4
|
+
if time.nil?
|
5
|
+
time = Time.now
|
6
|
+
end
|
7
|
+
|
8
|
+
time.strftime("%e/%-m/%Y @ %I:%M:%S%P")
|
5
9
|
end
|
6
|
-
|
7
|
-
time.strftime("%e/%-m/%Y @ %I:%M:%S%P")
|
8
|
-
end
|
9
10
|
|
10
|
-
|
11
|
-
@os ||= (
|
11
|
+
def self.os
|
12
12
|
host_os = RbConfig::CONFIG['host_os']
|
13
|
+
|
13
14
|
case host_os
|
14
15
|
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
15
16
|
:windows
|
@@ -22,6 +23,6 @@ class Utils
|
|
22
23
|
else
|
23
24
|
puts "unknown os: #{host_os.inspect}"
|
24
25
|
end
|
25
|
-
|
26
|
+
end
|
26
27
|
end
|
27
28
|
end
|
data/lib/notifaction/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Яyan Priebe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- .notifaction.sample.yml
|
63
64
|
- .travis.yml
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
@@ -68,8 +69,8 @@ files:
|
|
68
69
|
- bin/console
|
69
70
|
- bin/setup
|
70
71
|
- lib/notifaction.rb
|
72
|
+
- lib/notifaction/config.rb
|
71
73
|
- lib/notifaction/notify.rb
|
72
|
-
- lib/notifaction/plugin.rb
|
73
74
|
- lib/notifaction/style.rb
|
74
75
|
- lib/notifaction/type.rb
|
75
76
|
- lib/notifaction/types/linux.rb
|
@@ -77,7 +78,6 @@ files:
|
|
77
78
|
- lib/notifaction/types/terminal.rb
|
78
79
|
- lib/notifaction/utils.rb
|
79
80
|
- lib/notifaction/version.rb
|
80
|
-
- lib/plugins/workingon.rb
|
81
81
|
- notifaction.gemspec
|
82
82
|
homepage: https://rubygems.org/gems/notifaction
|
83
83
|
licenses:
|
data/lib/notifaction/plugin.rb
DELETED
data/lib/plugins/workingon.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Plugin
|
2
|
-
class WorkingOn
|
3
|
-
def fire(message)
|
4
|
-
log = File.new('/tmp/wo-digest.log', 'a+')
|
5
|
-
|
6
|
-
open(log, 'a') do |file|
|
7
|
-
file.write("#{message}\n")
|
8
|
-
end
|
9
|
-
|
10
|
-
# enough messages have been stored, send digest
|
11
|
-
if Plugin::num_lines(log) > 3
|
12
|
-
digest = open(log, 'r').read
|
13
|
-
|
14
|
-
Net::HTTP.post_form(URI(sprintf(api_endpoint, api_key)), :task => CGI.escapeHTML(digest.split("\n").uniq.join(', ')))
|
15
|
-
|
16
|
-
# reset digest after sending
|
17
|
-
File.truncate(log, 0)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def api_endpoint
|
22
|
-
"https://api.workingon.co/hooks/incoming?token=%s"
|
23
|
-
end
|
24
|
-
|
25
|
-
def api_key
|
26
|
-
Notify.instance_variable_get('@WorkingOn_key')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|