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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28a65b85fb1a825f7af8225c38e01d8d614aa2a3
4
- data.tar.gz: 664caaee8dd66d0a045d381d5bddaca4823e44b1
3
+ metadata.gz: a1fbf23fc97a9f930d9dd79d440516eb4b33b148
4
+ data.tar.gz: eaf15cfb3496e21a565ae26d7710edc16a93ede9
5
5
  SHA512:
6
- metadata.gz: 5db2dd9639e975b4b6a22ba4562f654f01ba9fd27c88bbe1437378178d63d1aa3ff0f50b52aea40f0af657c5a2b8780c558c381fdf3dbd0f81c3fab1c7a4d56e
7
- data.tar.gz: 12f6946a537c61dec18da6f78b9a070cb9252231e8d2915e90ea665496fac8634bcefedfc7c7cb06c0485132f871dca982943444808e0ec9c4463d468767722b
6
+ metadata.gz: 4b733df88dbbda18da7cb2f5e4563b37d918c72032e62f7dbc9481f2b9e94f39d683ac9db93583116fe5e03de6cbcbf1148550155692ed779779583362a0a57c
7
+ data.tar.gz: 4b63bc5169ee2ee76ffba4b9d79943b5d3d824dce2f36847b53fd861b1ca8f2c2f8cc3ff5feb614ae4eb23edb013437a3301b59ebaca8bcb0656597aefc38286
@@ -0,0 +1,7 @@
1
+ plugin_hooks:
2
+ - "https://api.workingon.co/hooks/incoming?token=derp"
3
+ - "https://api.test.com/hooks/incoming?token=derp2"
4
+
5
+ config:
6
+ show_time: false
7
+ fancy: true
data/lib/notifaction.rb CHANGED
@@ -1,16 +1,13 @@
1
- require 'time'
2
- require 'rbconfig'
3
- require 'net/http'
4
- require 'cgi'
1
+ require "time"
2
+ require "rbconfig"
5
3
 
6
- require 'notifaction/type'
7
- require 'notifaction/types/linux'
8
- require 'notifaction/types/osx'
9
- require 'notifaction/types/terminal'
10
- require 'notifaction/notify'
11
- require 'notifaction/plugin'
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 'notifaction/utils'
11
+ require "notifaction/utils"
14
12
 
15
- module Notifaction
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
@@ -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[:auto_quit] == false
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
- begin
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
- plugin_config_arr.each do |hash|
102
- hash.each_pair do |plugin, key|
103
- # include the requested plugin
104
- require_relative "plugins/#{plugin.downcase}.rb"
94
+ self.deprecation_notice("0.3.0")
95
+ end
105
96
 
106
- instance_variable_set("@#{plugin}_key".to_sym, key)
107
- end
108
- end
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
@@ -1,32 +1,34 @@
1
- module Style
2
- @map = {
3
- :colour => {
4
- :red => 31,
5
- :green => 32,
6
- :yellow => 33,
7
- :blue => 34,
8
- :magenta => 35,
9
- :cyan => 36,
10
- :white => 37,
11
- :null => 0
12
- },
13
- :style => {
14
- :reset => 0,
15
- :bold => 1,
16
- :underline => 4,
17
- :normal => ""
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
- def self.format(message, colour = nil, style = nil)
22
- c = @map[:colour][colour.to_sym] if !colour.nil?
22
+ def self.format(message, colour = nil, style = nil)
23
+ c = @map[:colour][colour.to_sym] unless colour.nil?
23
24
 
24
- if style.nil?
25
- t = 0
26
- else
27
- t = @map[:style][style.to_sym]
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
@@ -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 'notifaction/style'
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('0.2.8')
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[:show_time]
74
- message = "#{config[:symbol]} #{message}" if config[:symbol] || config[:fancy]
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[:print] == false
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
@@ -1,15 +1,16 @@
1
- class Utils
2
- def self.formatted_time(time = nil)
3
- if time.nil?
4
- time = Time.now
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
- def self.os
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
@@ -1,3 +1,3 @@
1
1
  module Notifaction
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.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-05 00:00:00.000000000 Z
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:
@@ -1,7 +0,0 @@
1
- module Notifaction
2
- module Plugin
3
- def self.num_lines(file)
4
- File.foreach(file).inject(0) {|c, line| c+1}
5
- end
6
- end
7
- end
@@ -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