notifier-0.5.1/0000755000004100000410000000000012511174562013370 5ustar www-datawww-datanotifier-0.5.1/Rakefile0000644000004100000410000000034312511174562015035 0ustar www-datawww-datarequire "bundler" Bundler::GemHelper.install_tasks require "rake/testtask" Rake::TestTask.new do |t| t.libs += %w[test lib] t.ruby_opts = %w[-rubygems] t.test_files = FileList["test/**/*_test.rb"] t.verbose = true end notifier-0.5.1/Gemfile0000644000004100000410000000004512511174562014662 0ustar www-datawww-datasource "http://rubygems.org" gemspec notifier-0.5.1/.rspec0000644000004100000410000000001012511174562014474 0ustar www-datawww-data--color notifier-0.5.1/resources/0000755000004100000410000000000012511174562015402 5ustar www-datawww-datanotifier-0.5.1/resources/register-growl.scpt0000644000004100000410000000236212511174562021254 0ustar www-datawww-dataFasdUAS 1.101.10ÿÿÿÿ lÿþÿý O Iÿüÿû ÿü.registernullÿÿ€ÿÿ€nullÿûÿú ÿú appl m  ±  test_notifier ÿù ÿù anot J ÿø m ±test_notifierÿø ÿ÷ÿö ÿ÷ dnot J ÿõ m ±test_notifierÿõÿö m(GRRRalisÊ ExceptionÄ,ÜH+AGrowlHelperApp.appuÄnÚµÿÿÿÿ ResourcesÄ-EÄoåA=<ôVException:Library:PreferencePanes:Growl.prefPane:Contents:Resources:GrowlHelperApp.app&GrowlHelperApp.app ExceptionLLibrary/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app/ÿÿÿþÿýÿôÿôÿó ÿó.aevtoappnull€****ÿòÿñÿðÿï ÿò.aevtoappnull€**** kÿîÿîÿñÿð ÿí ÿìÿëÿêÿé ÿí appl ÿì anot ÿë dnotÿê ÿé.registernullÿÿ€ÿÿ€nullÿïà*áâãäkvåækvç Uascr úÞÞ­notifier-0.5.1/spec/0000755000004100000410000000000012511174562014322 5ustar www-datawww-datanotifier-0.5.1/spec/spec_helper.rb0000644000004100000410000000044412511174562017142 0ustar www-datawww-datarequire "notifier" module SpecHelpers def unsupport_all_notifiers Notifier.notifiers.each do |notifier| allow(notifier).to receive_messages(:supported? => false) unless notifier == Notifier::Placebo end end end RSpec.configure do |config| config.include SpecHelpers end notifier-0.5.1/spec/notifier_spec.rb0000644000004100000410000000423712511174562017506 0ustar www-datawww-datarequire "spec_helper" describe Notifier do before do unsupport_all_notifiers Notifier.default_notifier = nil end it "retrieves list of supported notifiers" do allow(Notifier::Snarl).to receive_messages :supported? => true allow(Notifier::Knotify).to receive_messages :supported? => true expect(Notifier.supported_notifiers.size).to eql(3) end it "returns first available notifier" do allow(Notifier::Snarl).to receive_messages :supported? => true allow(Notifier::Knotify).to receive_messages :supported? => true expect(Notifier.notifier).to eql(Notifier::Snarl) end it "prefers default notifier" do allow(Notifier::Snarl).to receive_messages :supported? => true allow(Notifier::Knotify).to receive_messages :supported? => true Notifier.default_notifier = :knotify expect(Notifier.notifier).to eql(Notifier::Knotify) end it "sends notification" do params = { :title => "Some title", :message => "Some message", :image => "image.png" } allow(Notifier::Snarl).to receive_messages :supported? => true expect(Notifier::Snarl).to receive(:notify).with(params) Notifier.notify(params) end it "retrieves list of all notifiers" do expect(Notifier.notifiers.size).to eql(9) end it "considers Placebo as fallback notifier" do expect(Notifier.supported_notifiers.last).to eql(Notifier::Placebo) end it "returns notifier by its name" do expect(Notifier.from_name(:osd_cat)).to eql(Notifier::OsdCat) expect(Notifier.from_name(:notify_send)).to eql(Notifier::NotifySend) expect(Notifier.from_name(:growl)).to eql(Notifier::Growl) end it "returns notifier by its name when supported" do allow(Notifier::Snarl).to receive_messages :supported? => true expect(Notifier.supported_notifier_from_name(:snarl)).to eql(Notifier::Snarl) end it "returns nil when have no supported notifiers" do expect(Notifier.supported_notifier_from_name(:snarl)).to be_nil end it "returns nil when an invalid notifier name is provided" do expect(Notifier.from_name(:invalid)).to be_nil expect(Notifier.supported_notifier_from_name(:invalid)).to be_nil end end notifier-0.5.1/README.rdoc0000644000004100000410000000721112511174562015177 0ustar www-datawww-data= Notifier Send system notifications on several platforms with a simple and unified API. Currently supports: * Growl (Mac OS X) * terminal-notifier (Notification Center wrapper for Mac OS X) * GNTP Protocol (Growl, with Vagrant support) * Kdialog (Linux/KDE) * Knotify (Linux/KDE) * OSD Cat (Linux) * Libnotify (Linux) * Snarl (Windows) == Installation gem install notifier === Mac OS X Growl: * Install Growl - http://growl.info/ * Install the growlnotify script located on the "Extras" directory * Open the Growl Preference Panel (System > Growl) and activate "Listen for incoming notifications" and "Allow remote application registration" options on the Network tab. terminal-notifier: * Install terminal-notifier - https://github.com/alloy/terminal-notifier === Linux If you're a linux guy, you can choose one of these methods: * Install libnotify-bin and its dependencies: sudo aptitude install libnotify-bin * Install xosd-bin: sudo aptitude install xosd-bin * KDE users don't need to install anything: Test Notifier will use +knotify+ or +kdialog+. === Windows * Install Snarl: download from http://www.fullphat.net * Install ruby-snarl: gem install ruby-snarl == Usage Notifier will try to detect which notifiers are available in your system. So you can just send a message: Notifier.notify( :image => "image.png", :title => "Testing Notifier", :message => "Sending an important message!" ) Not all notifiers support the image option, therefore it will be ignored. If your system support more than one notifier, you can specify which one you prefer: Notifier.default_notifier = :notify_send The available names are growl, terminal_notifier, kdialog, knotify, notify_send, osd_cat, and snarl. There are several helper methods that you can use in order to retrieve notifiers. * Notifier.notifier: return the first supported notifier * Notifier.notifiers: return all notifiers * Notifier.supported_notifiers: return only supported notifiers * Notifier.from_name(name): find notifier by its name * Notifier.supported_notifier_from_name(name): find a supported notifier by its name == Creating custom notifiers To create a new notifier, just create a module on Notifier namespace that implements the following interface: module Notifier module MyCustomNotifier def self.supported? end def self.notify(options) end end end == Maintainer * Nando Vieira - http://nandovieira.com.br == Contributors * Olek Janiszewski * David Miani == License (The MIT License) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. notifier-0.5.1/lib/0000755000004100000410000000000012511174562014136 5ustar www-datawww-datanotifier-0.5.1/lib/notifier.rb0000644000004100000410000000251012511174562016300 0ustar www-datawww-datarequire "open3" require "socket" require "digest/md5" require "timeout" require "rbconfig" module Notifier require "notifier/growl" require "notifier/gntp" require "notifier/snarl" require "notifier/osd_cat" require "notifier/knotify" require "notifier/kdialog" require "notifier/notify_send" require "notifier/placebo" require "notifier/terminal_notifier" require "notifier/version" require "notifier/adapters" extend self class << self attr_accessor :default_notifier end def notifier supported_notifier_from_name(default_notifier) || supported_notifiers.first end def notify(options) notifier.notify(options) end def notifiers constants.collect do |name| const_get(name) unless %w[Placebo Adapters Version].include?(name.to_s) end.compact + [Placebo] end def supported_notifiers notifiers.select {|notifier| notifier.supported?} end def from_name(name) const_get(classify(name.to_s)) rescue Exception nil end def supported_notifier_from_name(name) notifier = from_name(name) notifier && notifier.supported? ? notifier : nil end def os?(regex) RUBY_PLATFORM =~ regex || RbConfig::CONFIG["host_os"] =~ regex end private def classify(string) string.gsub(/_(.)/sm) { "#{$1.upcase}" }.gsub(/^(.)/) { "#{$1.upcase}" } end end notifier-0.5.1/lib/notifier/0000755000004100000410000000000012511174562015755 5ustar www-datawww-datanotifier-0.5.1/lib/notifier/adapters/0000755000004100000410000000000012511174562017560 5ustar www-datawww-datanotifier-0.5.1/lib/notifier/adapters/gntp.rb0000644000004100000410000000447612511174562021070 0ustar www-datawww-datamodule Notifier module Adapters class GNTP attr_accessor :application_name attr_accessor :host attr_accessor :port attr_accessor :password def initialize(options = {}) if options.kind_of?(String) options = {:name => options} end @application_name = options.fetch(:name, "GNTP/Ruby") @host = options.fetch(:host, "127.0.0.1") @port = options.fetch(:port, 23053) @password = options.fetch(:password, nil) end def line_break(number = 1) "\r\n" * number end def write(*contents) contents.map! do |content| content.force_encoding("utf-8") rescue content end socket = TCPSocket.open(host, port) message = [*contents, line_break(2)].join(line_break) socket.write(message) "".tap do |response| while chunk = socket.gets break if chunk == line_break response << chunk end socket.close end end def notify(options) name = options.fetch(:name, "notification") register(name) icon = fetch_icon(options[:icon]) write "GNTP/1.0 NOTIFY NONE", "Application-Name: #{application_name}", "Notification-Name: #{name}", "Notification-Title: #{options[:title]}", "Notification-Text: #{options[:message]}", "Notification-Icon: x-growl-resource://#{icon[:identifier]}", "Notification-Sticky: #{bool options[:sticky]}", nil, "Identifier: #{icon[:identifier]}", "Length: #{icon[:size]}", nil, icon[:contents] end def fetch_icon(path) contents = File.open(path, "rb") {|f| f.read } { :identifier => Digest::MD5.hexdigest(contents), :contents => contents, :size => contents.bytesize } end def bool(boolean) {true => "Yes", false => "No"}[boolean] end def register(name) write "GNTP/1.0 REGISTER NONE", "Application-Name: #{application_name}", "Notifications-count: 1", nil, "Notification-Name: #{name}", "Notification-Enabled: True" end end end end notifier-0.5.1/lib/notifier/gntp.rb0000644000004100000410000000143212511174562017252 0ustar www-datawww-datamodule Notifier module GNTP extend self def supported? Timeout.timeout(1) { TCPSocket.new(host, port).close } true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Timeout::Error false end def port ENV.fetch("GNTP_PORT", 23053) end def host ENV["GNTP_HOST"] || ssh_connection || "127.0.0.1" end def ssh_connection ENV["SSH_CONNECTION"][/^([^ ]+)/, 1] if ENV["SSH_CONNECTION"] end def notify(options) gntp = Adapters::GNTP.new({ :name => "test_notifier", :host => host, :port => port }) gntp.notify({ :name => "status", :title => options[:title], :message => options[:message], :icon => options[:image] }) end end end notifier-0.5.1/lib/notifier/snarl.rb0000644000004100000410000000057012511174562017423 0ustar www-datawww-datamodule Notifier module Snarl extend self def supported? return false unless Notifier.os?(/(mswin|mingw)/) begin require "snarl" unless defined?(::Snarl) true rescue LoadError false end end def notify(options) ::Snarl.show_message(options[:title], options[:message], options[:image]) end end end notifier-0.5.1/lib/notifier/adapters.rb0000644000004100000410000000013112511174562020100 0ustar www-datawww-datamodule Notifier module Adapters autoload :GNTP, "notifier/adapters/gntp" end end notifier-0.5.1/lib/notifier/placebo.rb0000644000004100000410000000020312511174562017702 0ustar www-datawww-datamodule Notifier module Placebo extend self def supported? true end def notify(options) end end end notifier-0.5.1/lib/notifier/kdialog.rb0000644000004100000410000000061012511174562017711 0ustar www-datawww-datamodule Notifier module Kdialog extend self def supported? Notifier.os?(/(linux|freebsd)/) && `which kdialog > /dev/null` && $? == 0 end def notify(options) command = [ "kdialog", "--title", options[:title].to_s, "--passivepopup", options[:message].to_s, "5" ] Thread.new { system(*command) }.join end end end notifier-0.5.1/lib/notifier/terminal_notifier.rb0000644000004100000410000000072712511174562022022 0ustar www-datawww-datamodule Notifier module TerminalNotifier extend self def supported? Notifier.os?(/darwin/) && `which terminal-notifier` && $? == 0 end def notify(options) command = [ "terminal-notifier", "-group", "notifier-rubygems", "-title", options[:title].to_s, "-appIcon", options.fetch(:image, "").to_s, "-message", options[:message].to_s ] Thread.new { system(*command) }.join end end end notifier-0.5.1/lib/notifier/knotify.rb0000644000004100000410000000062412511174562017767 0ustar www-datawww-datamodule Notifier module Knotify extend self def supported? Notifier.os?(/(linux|freebsd)/) && `ps -Al | grep dcop` && $? == 0 end def notify(options) command = [ "dcop", "knotify", "default", "notify", "eventname", options[:title].to_s, options[:message].to_s, "", "", "16", "2" ] Thread.new { system(*command) }.join end end end notifier-0.5.1/lib/notifier/growl.rb0000644000004100000410000000131012511174562017427 0ustar www-datawww-datamodule Notifier module Growl extend self SCRIPT = File.dirname(__FILE__) + "/../../resources/register-growl.scpt" FILE = File.expand_path("~/.test_notifier-growl") def supported? Notifier.os?(/darwin/) && `which growlnotify` && $? == 0 end def notify(options) register command = [ "growlnotify", "--name", "test_notifier", "--image", options.fetch(:image, '').to_s, "--priority", "2", "--message", options[:message].to_s, options[:title].to_s ] Thread.new { system(*command) }.join end def register return if File.file?(FILE) system "osascript #{SCRIPT} > #{FILE}" end end end notifier-0.5.1/lib/notifier/version.rb0000644000004100000410000000017712511174562017774 0ustar www-datawww-datamodule Notifier module Version MAJOR = 0 MINOR = 5 PATCH = 1 STRING = "#{MAJOR}.#{MINOR}.#{PATCH}" end end notifier-0.5.1/lib/notifier/osd_cat.rb0000644000004100000410000000132212511174562017714 0ustar www-datawww-datamodule Notifier module OsdCat extend self def supported? Notifier.os?(/(linux|freebsd)/) && `which osd_cat > /dev/null` && $? == 0 end def notify(options) color = options.fetch(:color, "white").to_s command = [ "osd_cat", "--shadow", "0", "--colour", color, "--pos", "top", "--offset", "10", "--align", "center", "--font", "-bitstream-bitstream charter-bold-r-*-*-*-350-*-*-*-*-*-*", "--delay", "5", "--outline", "4", ] Thread.new do Open3.popen3(*command) do |stdin, stdout, stderr| stdin.puts options[:message] stdin.close end end.join end end end notifier-0.5.1/lib/notifier/notify_send.rb0000644000004100000410000000061512511174562020625 0ustar www-datawww-datamodule Notifier module NotifySend extend self def supported? Notifier.os?(/(linux|freebsd)/) && `which notify-send > /dev/null` && $? == 0 end def notify(options) command = [ "notify-send", "-i", options[:image].to_s, options[:title].to_s, options[:message].to_s ] Thread.new { system(*command) }.join end end end notifier-0.5.1/metadata.yml0000644000004100000410000000471712511174562015704 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: notifier version: !ruby/object:Gem::Version version: 0.5.1 platform: ruby authors: - Nando Vieira autorequire: bindir: bin cert_chain: [] date: 2015-03-20 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: Send system notifications on several platforms with a simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl email: - fnando.vieira@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".rspec" - Gemfile - README.rdoc - Rakefile - lib/notifier.rb - lib/notifier/adapters.rb - lib/notifier/adapters/gntp.rb - lib/notifier/gntp.rb - lib/notifier/growl.rb - lib/notifier/kdialog.rb - lib/notifier/knotify.rb - lib/notifier/notify_send.rb - lib/notifier/osd_cat.rb - lib/notifier/placebo.rb - lib/notifier/snarl.rb - lib/notifier/terminal_notifier.rb - lib/notifier/version.rb - notifier.gemspec - resources/register-growl.scpt - spec/notifier_spec.rb - spec/spec_helper.rb homepage: http://rubygems.org/gems/notifier licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: - Growl, terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl rubyforge_project: rubygems_version: 2.4.6 signing_key: specification_version: 4 summary: Send system notifications on several platforms with a simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl test_files: - spec/notifier_spec.rb - spec/spec_helper.rb notifier-0.5.1/.gitignore0000644000004100000410000000004512511174562015357 0ustar www-datawww-datapkg/* *.gem .bundle .DS_Store *.lock notifier-0.5.1/notifier.gemspec0000644000004100000410000000174212511174562016560 0ustar www-datawww-data# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "notifier/version" Gem::Specification.new do |s| s.name = "notifier" s.version = Notifier::Version::STRING s.platform = Gem::Platform::RUBY s.authors = ["Nando Vieira"] s.email = ["fnando.vieira@gmail.com"] s.homepage = "http://rubygems.org/gems/notifier" s.summary = "Send system notifications on several platforms with a simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl" s.description = s.summary s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.requirements << "Growl, terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl" s.add_development_dependency "rspec" s.add_development_dependency "rake" end