notify-push 0.1.3 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile +3 -15
- data/Gemfile.lock +18 -9
- data/README.md +13 -6
- data/VERSION +1 -1
- data/bin/notify-push +22 -3
- data/contrib/shell/notify-push-curl +19 -7
- data/lib/notify-push.rb +50 -144
- data/lib/notify-push/cli.rb +110 -0
- data/lib/notify-push/receiver.rb +107 -0
- data/lib/notify-push/sender.rb +55 -0
- data/notify-push.gemspec +12 -3
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00d52fe8704f4c9c24bed46b6a59d3a93096b844
|
4
|
+
data.tar.gz: 9d73dce0d6711cf6bf89595d1c706daa91a8570a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54cab4097489b0a7618bc997095b5b330600bc36b703601fc776b25b4e9e3edaad880dda75dc72bfaba7b94d3ef40e79dea453e9cbb9942edd744e0152dce1b3
|
7
|
+
data.tar.gz: de367fff0e4252b32adaa68a2f12e10bf633b494638940ce9711613df705f4d71b1c69f20907e0dc7588ff1a1490cec54a4bcdbef4fe2fe0b9eaee7d38933ea1
|
data/Gemfile
CHANGED
@@ -3,27 +3,15 @@
|
|
3
3
|
# ================================================
|
4
4
|
source "http://rubygems.org"
|
5
5
|
|
6
|
-
# http://stackoverflow.com/questions/8420414/how-to-add-mac-specific-gems-to-bundle-on-mac-but-not-on-linux
|
7
|
-
def windows_only(require_as)
|
8
|
-
RbConfig::CONFIG['host_os'] =~ /mingw|mswin/i ? require_as : false
|
9
|
-
end
|
10
|
-
|
11
|
-
def linux_only(require_as)
|
12
|
-
RbConfig::CONFIG['host_os'] =~ /linux/ ? require_as : false
|
13
|
-
end
|
14
|
-
|
15
|
-
def darwin_only(require_as)
|
16
|
-
RbConfig::CONFIG['host_os'] =~ /darwin/ ? require_as : false
|
17
|
-
end
|
18
|
-
|
19
6
|
gem "pusher"
|
20
7
|
gem "pusher-client"
|
21
8
|
gem "activesupport"
|
22
9
|
gem "recursive-open-struct"
|
23
10
|
gem "pidfile"
|
24
11
|
gem "os"
|
25
|
-
|
26
|
-
gem "
|
12
|
+
gem "notifier", github: "eriknomitch/notifier"
|
13
|
+
gem "thor"
|
14
|
+
gem "awesome_print"
|
27
15
|
|
28
16
|
group :development do
|
29
17
|
gem "shoulda", ">= 0"
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/eriknomitch/notifier.git
|
3
|
+
revision: a43138bbc90c5d246dfb38c34f8ff9b9b56ae07b
|
4
|
+
specs:
|
5
|
+
notifier (0.5.1)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
4
|
-
activesupport (4.2.
|
10
|
+
activesupport (4.2.3)
|
5
11
|
i18n (~> 0.7)
|
6
12
|
json (~> 1.7, >= 1.7.7)
|
7
13
|
minitest (~> 5.1)
|
8
14
|
thread_safe (~> 0.3, >= 0.3.4)
|
9
15
|
tzinfo (~> 1.1)
|
10
16
|
addressable (2.3.8)
|
17
|
+
awesome_print (1.6.1)
|
11
18
|
builder (3.2.2)
|
12
19
|
coderay (1.1.0)
|
13
20
|
descendants_tracker (0.0.4)
|
@@ -24,7 +31,7 @@ GEM
|
|
24
31
|
multi_json (>= 1.7.5, < 2.0)
|
25
32
|
nokogiri (~> 1.6.3)
|
26
33
|
oauth2
|
27
|
-
hashie (3.4.
|
34
|
+
hashie (3.4.2)
|
28
35
|
highline (1.7.2)
|
29
36
|
httpclient (2.6.0.1)
|
30
37
|
i18n (0.7.0)
|
@@ -37,17 +44,16 @@ GEM
|
|
37
44
|
nokogiri (>= 1.5.10)
|
38
45
|
rake
|
39
46
|
rdoc
|
40
|
-
json (1.8.
|
41
|
-
jwt (1.5.
|
47
|
+
json (1.8.3)
|
48
|
+
jwt (1.5.1)
|
42
49
|
method_source (0.8.2)
|
43
50
|
mini_portile (0.6.2)
|
44
51
|
minitest (5.7.0)
|
45
|
-
multi_json (1.11.
|
52
|
+
multi_json (1.11.2)
|
46
53
|
multi_xml (0.5.5)
|
47
54
|
multipart-post (2.0.0)
|
48
55
|
nokogiri (1.6.6.2)
|
49
56
|
mini_portile (~> 0.6.0)
|
50
|
-
notifier (0.5.1)
|
51
57
|
oauth2 (1.0.0)
|
52
58
|
faraday (>= 0.8, < 0.10)
|
53
59
|
jwt (~> 1.0)
|
@@ -67,11 +73,11 @@ GEM
|
|
67
73
|
pusher-client (0.6.2)
|
68
74
|
json
|
69
75
|
websocket (~> 1.0)
|
70
|
-
rack (1.6.
|
76
|
+
rack (1.6.4)
|
71
77
|
rake (10.4.2)
|
72
78
|
rdoc (3.12.2)
|
73
79
|
json (~> 1.4)
|
74
|
-
recursive-open-struct (0.6.
|
80
|
+
recursive-open-struct (0.6.5)
|
75
81
|
shoulda (3.5.0)
|
76
82
|
shoulda-context (~> 1.0, >= 1.0.1)
|
77
83
|
shoulda-matchers (>= 1.4.1, < 3.0)
|
@@ -85,6 +91,7 @@ GEM
|
|
85
91
|
simplecov-html (~> 0.10.0)
|
86
92
|
simplecov-html (0.10.0)
|
87
93
|
slop (3.6.0)
|
94
|
+
thor (0.19.1)
|
88
95
|
thread_safe (0.3.5)
|
89
96
|
tzinfo (1.2.2)
|
90
97
|
thread_safe (~> 0.1)
|
@@ -96,9 +103,10 @@ PLATFORMS
|
|
96
103
|
|
97
104
|
DEPENDENCIES
|
98
105
|
activesupport
|
106
|
+
awesome_print
|
99
107
|
bundler (~> 1.0)
|
100
108
|
jeweler (~> 2.0.1)
|
101
|
-
notifier
|
109
|
+
notifier!
|
102
110
|
os
|
103
111
|
pidfile
|
104
112
|
pry
|
@@ -108,4 +116,5 @@ DEPENDENCIES
|
|
108
116
|
recursive-open-struct
|
109
117
|
shoulda
|
110
118
|
simplecov
|
119
|
+
thor
|
111
120
|
yard (~> 0.7)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
A general purpose popup notifier sender/receiver for using WebSockets (via [Pusher](https://pusher.com)).
|
3
3
|
|
4
4
|
## Overview
|
5
|
-
`notify-push` employs a Receiver
|
5
|
+
`notify-push` employs a Receiver and Sender(s) to push messages from the Sender(s) to the Receiver.
|
6
6
|
|
7
7
|
**Example Use Case**:
|
8
8
|
You have `irssi` set up in a `screen` on a remote machine and you want to be notified on your laptop/desktop whenever your name gets highlighted.
|
@@ -25,6 +25,14 @@ For the Receiver machine and the Sender machine(s):
|
|
25
25
|
$ gem install notify-push
|
26
26
|
```
|
27
27
|
|
28
|
+
Or, from source:
|
29
|
+
```Shell
|
30
|
+
$ git clone https://github.com/eriknomitch/notify-push.git
|
31
|
+
$ cd notify-push
|
32
|
+
$ bundle install
|
33
|
+
$ rake install
|
34
|
+
```
|
35
|
+
|
28
36
|
### Create & Distribute Configuration File
|
29
37
|
Next, create a configuration file with your Pusher App's credentials (found on your Pusher App's page under *App Credentials*) and distribute it to each machine (Receiver and Sender(s)).
|
30
38
|
|
@@ -45,7 +53,7 @@ pusher:
|
|
45
53
|
Invoke the Receiver with:
|
46
54
|
|
47
55
|
```Shell
|
48
|
-
$ notify-push
|
56
|
+
$ notify-push receive
|
49
57
|
```
|
50
58
|
|
51
59
|
TODO: There's a .plist launchd file in there but it's not ready.
|
@@ -55,13 +63,12 @@ TODO: There's a .plist launchd file in there but it's not ready.
|
|
55
63
|
### Usage
|
56
64
|
|
57
65
|
```Shell
|
58
|
-
$ notify-push <message> [title]
|
66
|
+
$ notify-push send <message> [title]
|
59
67
|
```
|
60
68
|
|
61
69
|
Alternatively, you can `curl` or use any Pusher tool to send on messages to your `notify-push` app on channel `"notifications"` with data:
|
62
70
|
|
63
71
|
```
|
64
|
-
message:
|
65
|
-
title:
|
66
|
-
subtitle: The subtitle of the notifier popup (Optional)
|
72
|
+
message: The message to notify you with in the notifier popup (REQUIRED)
|
73
|
+
title: The title of the notifier popup (Optional)
|
67
74
|
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/notify-push
CHANGED
@@ -1,10 +1,29 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# ------------------------------------------------
|
4
|
+
# TRAPS ------------------------------------------
|
5
|
+
# ------------------------------------------------
|
6
|
+
|
7
|
+
# We want to trap these signals early because loading
|
8
|
+
# everything takes a bit of time... The user could
|
9
|
+
# Ctrl-C before that happens.
|
10
|
+
trap "SIGINT" do
|
11
|
+
exit 130
|
12
|
+
end
|
13
|
+
|
14
|
+
trap "KILL" do
|
15
|
+
exit 143
|
16
|
+
end
|
17
|
+
|
18
|
+
# ------------------------------------------------
|
19
|
+
# MAIN -------------------------------------------
|
20
|
+
# ------------------------------------------------
|
21
|
+
|
22
|
+
# Requiring "notify-push" will subsequently require the Thor app (CLI)
|
23
|
+
# and run everything.
|
2
24
|
begin
|
3
25
|
require "notify-push"
|
4
26
|
rescue LoadError
|
5
27
|
require "rubygems"
|
6
28
|
require "notify-push"
|
7
29
|
end
|
8
|
-
|
9
|
-
exit NotifyPush.main
|
10
|
-
|
@@ -1,26 +1,38 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
|
3
|
+
_envs_passed=0
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
function _require_environment_variable() {
|
6
|
+
[ -z "${!1}" ] && echo "Need to set $1 environment variable." && _env_passed=1 && return 1
|
7
|
+
return 0
|
8
|
+
}
|
9
|
+
|
10
|
+
_require_environment_variable "PUSHER_KEY"
|
11
|
+
_require_environment_variable "PUSHER_SECRET"
|
12
|
+
_require_environment_variable "PUSHER_APP_ID"
|
13
|
+
|
14
|
+
if (( $_env_passed != 0 )) ; then
|
15
|
+
echo "fatal: One or more environment variables are not set."
|
16
|
+
exit 1
|
17
|
+
fi
|
8
18
|
|
9
19
|
message=$1
|
10
20
|
title=$2
|
11
21
|
timestamp=$(date +%s)
|
12
22
|
|
23
|
+
[ -z "$message" ] && echo "fatal: No message supplied." && exit 1
|
24
|
+
|
13
25
|
data='{"name":"notification","channel":"notify-push","data":"{\"message\":\"'$message'\",\"title\":\"'$title'\"}"}'
|
14
26
|
|
15
27
|
# Be sure to use `printf %s` to prevent a trailing \n from being added to the data.
|
16
28
|
md5data=$(printf '%s' "$data" | md5sum | awk '{print $1}')
|
17
|
-
path="/apps/${
|
18
|
-
queryString="auth_key=${
|
29
|
+
path="/apps/${$PUSHER_APP_ID}/events"
|
30
|
+
queryString="auth_key=${$PUSHER_KEY}&auth_timestamp=${timestamp}&auth_version=1.0&body_md5=${md5data}"
|
19
31
|
|
20
32
|
# Be sure to use a multi-line, double quoted string that doesn't end in \n as
|
21
33
|
# input for the SHA-256 HMAC.
|
22
34
|
authSig=$(printf '%s' "POST
|
23
35
|
$path
|
24
|
-
$queryString" | openssl dgst -sha256 -hex -hmac "$
|
36
|
+
$queryString" | openssl dgst -sha256 -hex -hmac "$PUSHER_SECRET")
|
25
37
|
curl -s -H "Content-Type:application/json" -d "$data" "http://api.pusherapp.com${path}?${queryString}&auth_signature=${authSig}" > /dev/null 2>&1 &
|
26
38
|
|
data/lib/notify-push.rb
CHANGED
@@ -1,15 +1,29 @@
|
|
1
|
+
# ================================================
|
2
|
+
# NOTIFY-PUSH ====================================
|
3
|
+
# ================================================
|
1
4
|
require "json"
|
2
5
|
require "shellwords"
|
3
6
|
require "yaml"
|
4
7
|
require "recursive-open-struct"
|
5
8
|
require "os"
|
6
9
|
require "notifier"
|
10
|
+
require "thor"
|
11
|
+
require "thor/group"
|
12
|
+
require "awesome_print"
|
7
13
|
|
8
|
-
|
14
|
+
# FIX: Development only
|
15
|
+
require "pry" if Gem::Specification::find_all_by_name("pry").any?
|
9
16
|
|
10
17
|
require "active_support/core_ext/hash/reverse_merge"
|
11
18
|
require "active_support/core_ext/module"
|
12
19
|
require "active_support/core_ext/object/blank"
|
20
|
+
require "active_support/core_ext/object/try"
|
21
|
+
require "active_support/inflector/inflections"
|
22
|
+
|
23
|
+
# ------------------------------------------------
|
24
|
+
# TRAP->ANY-EXIT ---------------------------------
|
25
|
+
# ------------------------------------------------
|
26
|
+
at_exit { NotifyPush.on_at_exit }
|
13
27
|
|
14
28
|
# ------------------------------------------------
|
15
29
|
# ->CLASS->OS ------------------------------------
|
@@ -27,6 +41,18 @@ end
|
|
27
41
|
# MODULE->NOTIFY-PUSH ----------------------------
|
28
42
|
# ------------------------------------------------
|
29
43
|
module NotifyPush
|
44
|
+
|
45
|
+
# ----------------------------------------------
|
46
|
+
# CONSTANTS ------------------------------------
|
47
|
+
# ----------------------------------------------
|
48
|
+
VERSION = Gem.loaded_specs["notify-push"].version
|
49
|
+
CHANNEL_NAME = "notify-push"
|
50
|
+
CONFIGURATION_FILE_PATH = "#{ENV["HOME"]}/.notify-pushrc"
|
51
|
+
|
52
|
+
# ----------------------------------------------
|
53
|
+
# ATTRIBUTES -----------------------------------
|
54
|
+
# ----------------------------------------------
|
55
|
+
mattr_accessor :configuration, :acting_as
|
30
56
|
|
31
57
|
# ----------------------------------------------
|
32
58
|
# MODULE->UTILITY ------------------------------
|
@@ -36,18 +62,7 @@ module NotifyPush
|
|
36
62
|
system "command -v #{command} >/dev/null 2>&1" or raise "The command '#{command}' cannot be found and is required."
|
37
63
|
end
|
38
64
|
end
|
39
|
-
|
40
|
-
# ----------------------------------------------
|
41
|
-
# ATTRIBUTES -----------------------------------
|
42
|
-
# ----------------------------------------------
|
43
|
-
mattr_accessor :configuration
|
44
65
|
|
45
|
-
# ----------------------------------------------
|
46
|
-
# CONSTANTS ------------------------------------
|
47
|
-
# ----------------------------------------------
|
48
|
-
CHANNEL_NAME = "notify-push"
|
49
|
-
CONFIGURATION_FILE_PATH = "#{ENV["HOME"]}/.notify-pushrc"
|
50
|
-
|
51
66
|
# ----------------------------------------------
|
52
67
|
# USER-CONFIGURATION ---------------------------
|
53
68
|
# ----------------------------------------------
|
@@ -59,153 +74,44 @@ module NotifyPush
|
|
59
74
|
self.configuration = RecursiveOpenStruct.new(YAML.load_file(CONFIGURATION_FILE_PATH))
|
60
75
|
end
|
61
76
|
|
77
|
+
# ----------------------------------------------
|
78
|
+
# CALLBACKS ------------------------------------
|
79
|
+
# ----------------------------------------------
|
80
|
+
def self.on_at_exit
|
81
|
+
self.acting_as.try(:on_at_exit)
|
82
|
+
end
|
83
|
+
|
62
84
|
# ----------------------------------------------
|
63
85
|
# MAIN -----------------------------------------
|
64
86
|
# ----------------------------------------------
|
65
|
-
def self.main()
|
87
|
+
def self.main(type, *args)
|
66
88
|
begin
|
67
89
|
initialize_configuration
|
68
90
|
|
69
|
-
|
70
|
-
|
91
|
+
case type
|
92
|
+
when :receiver, :receive
|
93
|
+
return NotifyPush::Receiver.start *args
|
94
|
+
when :sender, :send
|
95
|
+
return NotifyPush::Sender.send_notification *args
|
71
96
|
end
|
72
97
|
|
73
|
-
NotifyPush::Sender.start
|
74
98
|
rescue => exception
|
75
99
|
puts "fatal: #{exception.to_s}"
|
76
100
|
exit 1
|
77
101
|
end
|
78
102
|
end
|
79
103
|
|
80
|
-
# ----------------------------------------------
|
81
|
-
# MODULE->SENDER -------------------------------
|
82
|
-
# ----------------------------------------------
|
83
|
-
module Sender
|
84
|
-
|
85
|
-
class << self
|
86
|
-
delegate :configuration, to: :parent
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.start()
|
90
|
-
|
91
|
-
# The only thing we require is a message.
|
92
|
-
# The others will be nil if not supplied.
|
93
|
-
raise "No message supplied." if ARGV[0].blank?
|
94
|
-
|
95
|
-
notification = {
|
96
|
-
message: ARGV[0],
|
97
|
-
title: ARGV[1],
|
98
|
-
subtitle: ARGV[2]
|
99
|
-
}
|
100
|
-
|
101
|
-
puts "Sending notification (backgrounded) with data:"
|
102
|
-
puts " message-> #{notification[:message]}"
|
103
|
-
puts " title-> #{notification[:title]}"
|
104
|
-
puts " subtitle-> #{notification[:subtitle]}"
|
105
|
-
|
106
|
-
# Daemonize now.
|
107
|
-
Process.daemon true
|
108
|
-
|
109
|
-
require "pusher"
|
110
|
-
|
111
|
-
# Strip the nil key/value pairs out so we don't have to
|
112
|
-
# worry about them on the Receiver end.
|
113
|
-
notification.delete_if {|key, value| value.blank?}
|
114
|
-
|
115
|
-
# Connect to Pusher and trigger the notification
|
116
|
-
Pusher.url = "http://#{configuration.pusher.key}:#{configuration.pusher.secret}@api.pusherapp.com/apps/#{configuration.pusher.app_id}"
|
117
|
-
|
118
|
-
Pusher[CHANNEL_NAME].trigger("notification", notification)
|
119
|
-
|
120
|
-
0
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
# ----------------------------------------------
|
126
|
-
# MODULE->RECEIVER -----------------------------
|
127
|
-
# ----------------------------------------------
|
128
|
-
module Receiver
|
129
|
-
|
130
|
-
class << self
|
131
|
-
delegate :configuration, to: :parent
|
132
|
-
end
|
133
|
-
|
134
|
-
# --------------------------------------------
|
135
|
-
# PID ----------------------------------------
|
136
|
-
# --------------------------------------------
|
137
|
-
def self.pid_lock
|
138
|
-
require "pidfile"
|
139
|
-
|
140
|
-
PidFile.new
|
141
|
-
end
|
142
|
-
|
143
|
-
# --------------------------------------------
|
144
|
-
# NOTIFY -------------------------------------
|
145
|
-
# --------------------------------------------
|
146
|
-
def self.notify(title: "notify-push", subtitle: nil, message:)
|
147
|
-
|
148
|
-
message = "#{subtitle} - #{message}" if subtitle
|
149
|
-
|
150
|
-
Notifier.notify({
|
151
|
-
title: title,
|
152
|
-
message: message
|
153
|
-
})
|
154
|
-
end
|
155
|
-
|
156
|
-
# --------------------------------------------
|
157
|
-
# START --------------------------------------
|
158
|
-
# --------------------------------------------
|
159
|
-
def self.start()
|
160
|
-
|
161
|
-
pid_lock
|
162
|
-
|
163
|
-
require "pusher-client"
|
164
|
-
|
165
|
-
socket = PusherClient::Socket.new configuration.pusher.key, {
|
166
|
-
secure: true
|
167
|
-
}
|
168
|
-
|
169
|
-
# Subscribe to main channel
|
170
|
-
socket.subscribe(CHANNEL_NAME)
|
171
|
-
|
172
|
-
# Bind to the main channel event
|
173
|
-
socket[CHANNEL_NAME].bind("notification") do |data|
|
174
|
-
|
175
|
-
begin
|
176
|
-
data = JSON.parse(data, symbolize_names: true)
|
177
|
-
|
178
|
-
notify **data
|
179
|
-
|
180
|
-
rescue => exception
|
181
|
-
puts "Warning: Failed to process notification."
|
182
|
-
puts exception
|
183
|
-
ensure
|
184
|
-
puts "----------"
|
185
|
-
puts data
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
# Bind to the error event
|
190
|
-
socket.bind("pusher:error") do |data|
|
191
|
-
puts "----------"
|
192
|
-
puts "Warning: Pusher Error"
|
193
|
-
puts data
|
194
|
-
end
|
195
|
-
|
196
|
-
# Connect
|
197
|
-
socket.connect
|
198
|
-
|
199
|
-
0
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
104
|
end
|
204
105
|
|
205
106
|
# ------------------------------------------------
|
206
|
-
#
|
107
|
+
# REQUIRES ---------------------------------------
|
207
108
|
# ------------------------------------------------
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
109
|
+
require "notify-push/receiver"
|
110
|
+
require "notify-push/sender"
|
111
|
+
require "notify-push/cli"
|
112
|
+
|
113
|
+
# ------------------------------------------------
|
114
|
+
# MAIN -------------------------------------------
|
115
|
+
# ------------------------------------------------
|
116
|
+
NotifyPush::CLI.start(ARGV)
|
117
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# ------------------------------------------------
|
2
|
+
# MODULE->NOTIFY-PUSH ----------------------------
|
3
|
+
# ------------------------------------------------
|
4
|
+
module NotifyPush
|
5
|
+
|
6
|
+
#class Sub < Thor
|
7
|
+
## --------------------------------------------
|
8
|
+
## CONFIGURATION ------------------------------
|
9
|
+
## --------------------------------------------
|
10
|
+
##package_name "receiver"
|
11
|
+
|
12
|
+
## --------------------------------------------
|
13
|
+
## COMMAND->RECEIVE ---------------------------
|
14
|
+
## --------------------------------------------
|
15
|
+
#desc "Starts the Receiver server (in the foreground)."
|
16
|
+
##option :silence_events, type: :boolean, default: false
|
17
|
+
#def foo()
|
18
|
+
#puts "foo"
|
19
|
+
#end
|
20
|
+
#end
|
21
|
+
|
22
|
+
# ----------------------------------------------
|
23
|
+
# CLASS->CLI-RECEIVER (THOR) -------------------
|
24
|
+
# ----------------------------------------------
|
25
|
+
#class CLIReceiver < Thor
|
26
|
+
|
27
|
+
## --------------------------------------------
|
28
|
+
## CONFIGURATION ------------------------------
|
29
|
+
## --------------------------------------------
|
30
|
+
##package_name "receiver"
|
31
|
+
|
32
|
+
## --------------------------------------------
|
33
|
+
## COMMAND->RECEIVE ---------------------------
|
34
|
+
## --------------------------------------------
|
35
|
+
##desc "Starts the Receiver server (in the foreground)."
|
36
|
+
#desc "foo", "Starts the Receiver server (in the foreground)."
|
37
|
+
##option :silence_events, type: :boolean, default: false
|
38
|
+
#def foo()
|
39
|
+
#puts "foo"
|
40
|
+
#end
|
41
|
+
|
42
|
+
#end
|
43
|
+
|
44
|
+
# ----------------------------------------------
|
45
|
+
# CLASS->CLI (THOR) ----------------------------
|
46
|
+
# ----------------------------------------------
|
47
|
+
class CLI < Thor
|
48
|
+
|
49
|
+
# --------------------------------------------
|
50
|
+
# CONFIGURATION ------------------------------
|
51
|
+
# --------------------------------------------
|
52
|
+
package_name "notify-push"
|
53
|
+
|
54
|
+
# --------------------------------------------
|
55
|
+
# COMMAND->UNINSTALL -------------------------
|
56
|
+
# --------------------------------------------
|
57
|
+
desc "version|--version", "Displays the current version of notify-push"
|
58
|
+
def version()
|
59
|
+
puts ::NotifyPush::VERSION
|
60
|
+
end
|
61
|
+
|
62
|
+
map "--version" => "version"
|
63
|
+
|
64
|
+
# --------------------------------------------
|
65
|
+
# COMMAND->RECEIVE ---------------------------
|
66
|
+
# --------------------------------------------
|
67
|
+
desc "receive", "Starts the Receiver server (in the foreground) (short-cut alias: \"r\")"
|
68
|
+
option :silence_events, type: :boolean, default: false
|
69
|
+
|
70
|
+
def receive()
|
71
|
+
NotifyPush.main :receive
|
72
|
+
end
|
73
|
+
|
74
|
+
map "r" => "send"
|
75
|
+
|
76
|
+
# --------------------------------------------
|
77
|
+
# COMMAND->SEND ------------------------------
|
78
|
+
# --------------------------------------------
|
79
|
+
desc "send MESSAGE <TITLE>", "Sends data to any listening Receivers (short-cut alias: \"s\")"
|
80
|
+
def send(message, title="notify-push")
|
81
|
+
|
82
|
+
# FIX: Use these arguments instead of ARGV
|
83
|
+
NotifyPush.main :send
|
84
|
+
end
|
85
|
+
|
86
|
+
map "s" => "send"
|
87
|
+
|
88
|
+
# --------------------------------------------
|
89
|
+
# COMMAND->INSTALL ---------------------------
|
90
|
+
# --------------------------------------------
|
91
|
+
desc "install COMPONENT", "Installs a notify-push component. Available COMPONENT(s): receiver-daemon"
|
92
|
+
def install(component)
|
93
|
+
puts "installing..."
|
94
|
+
end
|
95
|
+
|
96
|
+
# --------------------------------------------
|
97
|
+
# COMMAND->UNINSTALL -------------------------
|
98
|
+
# --------------------------------------------
|
99
|
+
desc "uninstall COMPONENT", "Uninstalls a notify-push component."
|
100
|
+
def uninstall(component)
|
101
|
+
puts "uninstalling..."
|
102
|
+
end
|
103
|
+
|
104
|
+
#desc "subbb", "Installs a notify-push component. Available COMPONENT(s): receiver-daemon"
|
105
|
+
#register CLIReceiver, :receiver, "receiver", "Do something else"
|
106
|
+
#subcommand "sub", CLIReceiver
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# ------------------------------------------------
|
2
|
+
# MODULE->NOTIFY-PUSH ----------------------------
|
3
|
+
# ------------------------------------------------
|
4
|
+
module NotifyPush
|
5
|
+
|
6
|
+
# ----------------------------------------------
|
7
|
+
# MODULE->RECEIVER -----------------------------
|
8
|
+
# ----------------------------------------------
|
9
|
+
module Receiver
|
10
|
+
|
11
|
+
class << self
|
12
|
+
delegate :configuration, to: :parent
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.on_at_exit
|
16
|
+
notify title: "notify-push", message: "Receiver: Exiting.", sound: :Submarine
|
17
|
+
end
|
18
|
+
|
19
|
+
# --------------------------------------------
|
20
|
+
# PID ----------------------------------------
|
21
|
+
# --------------------------------------------
|
22
|
+
def self.pid_lock
|
23
|
+
require "pidfile"
|
24
|
+
|
25
|
+
PidFile.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# --------------------------------------------
|
29
|
+
# NOTIFY -------------------------------------
|
30
|
+
# --------------------------------------------
|
31
|
+
def self.notify(title: "notify-push", subtitle: nil, sound: :Bottle, message:)
|
32
|
+
|
33
|
+
message = "#{subtitle} - #{message}" if subtitle
|
34
|
+
|
35
|
+
Notifier.notify({
|
36
|
+
title: title,
|
37
|
+
message: message,
|
38
|
+
sound: sound
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
# --------------------------------------------
|
43
|
+
# START --------------------------------------
|
44
|
+
# --------------------------------------------
|
45
|
+
def self.start()
|
46
|
+
|
47
|
+
pid_lock
|
48
|
+
|
49
|
+
::NotifyPush.acting_as = self
|
50
|
+
|
51
|
+
require "pusher-client"
|
52
|
+
|
53
|
+
socket = PusherClient::Socket.new configuration.pusher.key, {
|
54
|
+
secure: true
|
55
|
+
}
|
56
|
+
|
57
|
+
# Subscribe to main channel
|
58
|
+
# ------------------------------------------
|
59
|
+
socket.subscribe(CHANNEL_NAME)
|
60
|
+
|
61
|
+
# Bind to: Main Channel Notification
|
62
|
+
# ------------------------------------------
|
63
|
+
socket[CHANNEL_NAME].bind("notification") do |data|
|
64
|
+
|
65
|
+
begin
|
66
|
+
data = JSON.parse(data, symbolize_names: true)
|
67
|
+
|
68
|
+
notify **data
|
69
|
+
|
70
|
+
rescue => exception
|
71
|
+
puts "Warning: Failed to process notification."
|
72
|
+
puts exception
|
73
|
+
ensure
|
74
|
+
puts "--------------------------------------------------"
|
75
|
+
puts "-> Received Push Notification at: #{Time.now.to_s}"
|
76
|
+
puts "--------------------------------------------------"
|
77
|
+
ap data
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Bind to: Pusher Errors
|
82
|
+
# ------------------------------------------
|
83
|
+
socket.bind("pusher:error") do |data|
|
84
|
+
puts "----------"
|
85
|
+
puts "Warning: Pusher Error"
|
86
|
+
puts data
|
87
|
+
end
|
88
|
+
|
89
|
+
# Bind to: Pusher Connection Established
|
90
|
+
# ------------------------------------------
|
91
|
+
socket.bind("pusher:connection_established") do |data|
|
92
|
+
self.notify({
|
93
|
+
title: "notify-push",
|
94
|
+
message: "Receiver: Started & connected.",
|
95
|
+
sound: :default
|
96
|
+
})
|
97
|
+
end
|
98
|
+
|
99
|
+
# Connect the Socket
|
100
|
+
# ------------------------------------------
|
101
|
+
socket.connect
|
102
|
+
|
103
|
+
0
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# ------------------------------------------------
|
2
|
+
# MODULE->NOTIFY-PUSH ----------------------------
|
3
|
+
# ------------------------------------------------
|
4
|
+
module NotifyPush
|
5
|
+
|
6
|
+
# ----------------------------------------------
|
7
|
+
# MODULE->SENDER -------------------------------
|
8
|
+
# ----------------------------------------------
|
9
|
+
module Sender
|
10
|
+
|
11
|
+
class << self
|
12
|
+
delegate :configuration, to: :parent
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.send_notification()
|
16
|
+
|
17
|
+
ARGV.shift
|
18
|
+
|
19
|
+
# The only thing we require is a message.
|
20
|
+
# The others will be nil if not supplied.
|
21
|
+
raise "No message supplied." if ARGV[0].blank?
|
22
|
+
|
23
|
+
::NotifyPush.acting_as = self
|
24
|
+
|
25
|
+
notification = {
|
26
|
+
message: ARGV[0],
|
27
|
+
title: ARGV[1],
|
28
|
+
subtitle: ARGV[2]
|
29
|
+
}
|
30
|
+
|
31
|
+
puts "Sending notification (backgrounded) with data:"
|
32
|
+
puts " message-> #{notification[:message]}"
|
33
|
+
puts " title-> #{notification[:title]}"
|
34
|
+
puts " subtitle-> #{notification[:subtitle]}"
|
35
|
+
|
36
|
+
# Daemonize now.
|
37
|
+
Process.daemon true
|
38
|
+
|
39
|
+
require "pusher"
|
40
|
+
|
41
|
+
# Strip the nil key/value pairs out so we don't have to
|
42
|
+
# worry about them on the Receiver end.
|
43
|
+
notification.delete_if {|key, value| value.blank?}
|
44
|
+
|
45
|
+
# Connect to Pusher and trigger the notification
|
46
|
+
Pusher.url = "http://#{configuration.pusher.key}:#{configuration.pusher.secret}@api.pusherapp.com/apps/#{configuration.pusher.app_id}"
|
47
|
+
|
48
|
+
Pusher[CHANNEL_NAME].trigger("notification", notification)
|
49
|
+
|
50
|
+
0
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/notify-push.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: notify-push 0.
|
5
|
+
# stub: notify-push 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "notify-push"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Erik Nomitch"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-07-08"
|
15
15
|
s.description = "A general purpose popup notifier sender/receiver using WebSockets (via Pusher)"
|
16
16
|
s.email = "erik@nomitch.com"
|
17
17
|
s.executables = ["notify-push"]
|
@@ -32,6 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"contrib/shell/notify-push-curl",
|
33
33
|
"images/doc/terminal-notifier.png",
|
34
34
|
"lib/notify-push.rb",
|
35
|
+
"lib/notify-push/cli.rb",
|
36
|
+
"lib/notify-push/receiver.rb",
|
37
|
+
"lib/notify-push/sender.rb",
|
35
38
|
"notify-push.gemspec",
|
36
39
|
"ofe.json",
|
37
40
|
"system/com.notify-push.receiver.plist",
|
@@ -55,6 +58,8 @@ Gem::Specification.new do |s|
|
|
55
58
|
s.add_runtime_dependency(%q<pidfile>, [">= 0"])
|
56
59
|
s.add_runtime_dependency(%q<os>, [">= 0"])
|
57
60
|
s.add_runtime_dependency(%q<notifier>, [">= 0"])
|
61
|
+
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
|
58
63
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
59
64
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
60
65
|
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
@@ -70,6 +75,8 @@ Gem::Specification.new do |s|
|
|
70
75
|
s.add_dependency(%q<pidfile>, [">= 0"])
|
71
76
|
s.add_dependency(%q<os>, [">= 0"])
|
72
77
|
s.add_dependency(%q<notifier>, [">= 0"])
|
78
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
79
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
73
80
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
74
81
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
75
82
|
s.add_dependency(%q<yard>, ["~> 0.7"])
|
@@ -86,6 +93,8 @@ Gem::Specification.new do |s|
|
|
86
93
|
s.add_dependency(%q<pidfile>, [">= 0"])
|
87
94
|
s.add_dependency(%q<os>, [">= 0"])
|
88
95
|
s.add_dependency(%q<notifier>, [">= 0"])
|
96
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
97
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
89
98
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
90
99
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
91
100
|
s.add_dependency(%q<yard>, ["~> 0.7"])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notify-push
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Nomitch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pusher
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: thor
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: awesome_print
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: shoulda
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,6 +256,9 @@ files:
|
|
228
256
|
- contrib/shell/notify-push-curl
|
229
257
|
- images/doc/terminal-notifier.png
|
230
258
|
- lib/notify-push.rb
|
259
|
+
- lib/notify-push/cli.rb
|
260
|
+
- lib/notify-push/receiver.rb
|
261
|
+
- lib/notify-push/sender.rb
|
231
262
|
- notify-push.gemspec
|
232
263
|
- ofe.json
|
233
264
|
- system/com.notify-push.receiver.plist
|