pushover 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +78 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +0 -37
- data/Guardfile +37 -27
- data/LICENSE +17 -32
- data/README.md +26 -153
- data/Rakefile +2 -3
- data/bin/pushover +0 -154
- data/lib/pushover.rb +8 -144
- data/lib/pushover/api.rb +35 -0
- data/lib/pushover/message.rb +38 -0
- data/lib/pushover/receipt.rb +5 -0
- data/lib/pushover/request.rb +12 -0
- data/lib/pushover/response.rb +40 -0
- data/lib/pushover/version.rb +2 -2
- data/pushover.gemspec +38 -25
- data/spec/lib/pushover/api_spec.rb +41 -0
- data/spec/lib/pushover/message_spec.rb +81 -0
- data/spec/lib/pushover/receipt_spec.rb +6 -0
- data/spec/lib/pushover/request_spec.rb +60 -0
- data/spec/lib/pushover/response_spec.rb +98 -0
- data/spec/lib/pushover_spec.rb +1 -116
- data/spec/spec_helper.rb +14 -39
- metadata +234 -36
- data/.travis.yml +0 -15
- data/lib/pushover/app.rb +0 -64
- data/lib/pushover/mixins.rb +0 -7
- data/lib/pushover/priority.rb +0 -63
- data/lib/pushover/user.rb +0 -68
- data/spec/bin/pushover_spec.rb +0 -108
- data/spec/cli_spec_helper.rb +0 -99
- data/spec/lib/pushover/app_spec.rb +0 -54
- data/spec/lib/pushover/user_spec.rb +0 -53
- data/whatsnew.md +0 -69
data/lib/pushover/mixins.rb
DELETED
data/lib/pushover/priority.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
module Pushover
|
2
|
-
module Priority
|
3
|
-
extend self
|
4
|
-
|
5
|
-
# A sash for our receipts.
|
6
|
-
Receipts = Bini::Sash.new options:{
|
7
|
-
file:"#{Bini.cache_dir}/receipts.yaml", auto_load:true, auto_save:true
|
8
|
-
}
|
9
|
-
LEVELS = {
|
10
|
-
low:-1,
|
11
|
-
normal:0,
|
12
|
-
high:1,
|
13
|
-
emergency:2
|
14
|
-
}
|
15
|
-
|
16
|
-
def priority=(level)
|
17
|
-
@priority = parse level
|
18
|
-
end
|
19
|
-
|
20
|
-
def parse(level)
|
21
|
-
return level if level.class == Fixnum
|
22
|
-
if level.class == String
|
23
|
-
LEVELS.each { |k,v| return v if k.to_s.start_with? level.downcase }
|
24
|
-
end
|
25
|
-
|
26
|
-
return 0
|
27
|
-
end
|
28
|
-
|
29
|
-
# Pull one from cache, or fetch one if not available.
|
30
|
-
def find_receipt(prefix)
|
31
|
-
results = Receipts.select { |k,v| k =~ /^#{prefix}/ }
|
32
|
-
return nil if results.empty?
|
33
|
-
return results.first_pair
|
34
|
-
end
|
35
|
-
|
36
|
-
def update_receipts
|
37
|
-
updates = Receipts.select {|k,v| v["acknowledged"] == 0 && v["expired"] == 0}
|
38
|
-
updates.keys.each do |key|
|
39
|
-
process_receipt key
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def process_receipt(receipt)
|
44
|
-
r = fetch_receipt(receipt)
|
45
|
-
|
46
|
-
return nil if !r
|
47
|
-
Receipts[receipt] = r.to_h
|
48
|
-
|
49
|
-
return Receipts[receipt]
|
50
|
-
end
|
51
|
-
|
52
|
-
def is_emergency?(priority)
|
53
|
-
return true if priority && Pushover::Priority.parse(priority) == LEVELS[:emergency]
|
54
|
-
return false
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
def fetch_receipt(receipt)
|
59
|
-
HTTParty.get("https://api.pushover.net/1/receipts/#{receipt}.json",
|
60
|
-
body:{token:Pushover::App.current_app})
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/pushover/user.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
module Pushover
|
2
|
-
# The user module, saves any user information provided.
|
3
|
-
module User
|
4
|
-
# The User class, for a single instance of it.
|
5
|
-
# @!attribute name
|
6
|
-
# @return [String] the name of the user.
|
7
|
-
# @!attribute token
|
8
|
-
# @return [String] the token of the user.
|
9
|
-
class User
|
10
|
-
attr_accessor :name
|
11
|
-
attr_accessor :token
|
12
|
-
|
13
|
-
def initialize(name, token)
|
14
|
-
@name = name
|
15
|
-
@token = token
|
16
|
-
Bini::Config[:users] = {} if !Bini::Config[:users]
|
17
|
-
Bini::Config[:users][name] = token
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
extend self
|
23
|
-
|
24
|
-
# Find the token in the users, or pass on the word to try direct access.
|
25
|
-
# @param [String] word the search token, can be an apikey or appname.
|
26
|
-
# @return [String] return the apikey (if it can find one) or the word itself.
|
27
|
-
def find(word)
|
28
|
-
return Bini::Config[:users][word] if Bini::Config[:users] && Bini::Config[:users][word]
|
29
|
-
word
|
30
|
-
end
|
31
|
-
|
32
|
-
# Add an application to the config file and save it.
|
33
|
-
# @param [String] token is the token to be used.
|
34
|
-
# @param [String] name is the short name that can be referenced later.
|
35
|
-
# @return [Boolean] return the results of the save attempt.
|
36
|
-
def add(name, token)
|
37
|
-
User.new name, token
|
38
|
-
Bini::Config.save
|
39
|
-
end
|
40
|
-
|
41
|
-
def remove(name)
|
42
|
-
Bini::Config[:users].delete name if Bini::Config[:users]
|
43
|
-
end
|
44
|
-
|
45
|
-
# Return the current user selected, or the first one saved.
|
46
|
-
def current_user
|
47
|
-
# did something get supplied on the cli? try to find it.
|
48
|
-
if Bini::Options[:user]
|
49
|
-
@current_user = Bini::Options[:user]
|
50
|
-
elsif !@current_user
|
51
|
-
@current_user = find Bini::Config[:users].values.first if Bini::Config[:users]
|
52
|
-
end
|
53
|
-
|
54
|
-
@current_user
|
55
|
-
end
|
56
|
-
|
57
|
-
# Set the current_user to whatever you want it to be.
|
58
|
-
def current_user=(user)
|
59
|
-
@current_user = user
|
60
|
-
end
|
61
|
-
|
62
|
-
# Will return true if it can find a user either via the cli or save file.
|
63
|
-
def current_user?
|
64
|
-
return true if current_user
|
65
|
-
return nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/spec/bin/pushover_spec.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
# Since this testing requires an actual account, and a working internet, we don't
|
2
|
-
# run it as part of the standard suite.
|
3
|
-
# If you want to run these tests, add ENV["TEST_CLI"]
|
4
|
-
# If you have a credentials file already, you might find it beeps you.
|
5
|
-
|
6
|
-
# this should be a working cred file that can send messages for proper end to end testing.
|
7
|
-
CRED_FILE = "#{Dir.home}/.config/pushover/credentials.yaml"
|
8
|
-
FAKE_CRED_FILE = 'tmp/fake_credentials.yaml'
|
9
|
-
CMD = 'bundle exec bin/pushover'
|
10
|
-
|
11
|
-
require 'spec_helper.rb'
|
12
|
-
require 'cli_spec_helper.rb'
|
13
|
-
|
14
|
-
if ENV["TEST_CLI"] =~ /^t/
|
15
|
-
describe "CLI Interface" do
|
16
|
-
describe 'help' do
|
17
|
-
it 'has options' do
|
18
|
-
p = CLIProcess.new "#{CMD} --help"
|
19
|
-
p.run!
|
20
|
-
words = /user|app|title|priority|url|url_title|save-app|save-user|time|version/
|
21
|
-
p.stdout.should =~ words
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "send" do
|
26
|
-
it "sends messages" do
|
27
|
-
p = CLIProcess.new "#{CMD} --config_file #{CRED_FILE} a message", 3, 3
|
28
|
-
p.run!
|
29
|
-
p.stdout.should include("success"), "#{p.stderr}"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "sends messages (no credentials file)" do
|
33
|
-
# for this trick, lets extract our creds from the cred file manually.
|
34
|
-
# store them locally,then pass them back as app/user arguments.
|
35
|
-
creds = YAML.load open(CRED_FILE).read
|
36
|
-
|
37
|
-
app = creds[:applications].first.values.first
|
38
|
-
user = creds[:users].first.values.first
|
39
|
-
p = CLIProcess.new "#{CMD} -a #{app} -u #{user} a message", 3, 3
|
40
|
-
p.run!
|
41
|
-
p.stdout.should include("success"), "#{p.stderr}"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "lets me know when a message fails" do
|
45
|
-
p = CLIProcess.new "#{CMD} --app fail --user now message goes here", 3, 3
|
46
|
-
p.run!
|
47
|
-
p.stdout.should include "ErrorCode"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "saving" do
|
52
|
-
it "saves app:key pairs" do
|
53
|
-
p = CLIProcess.new "#{CMD} --config_file #{FAKE_CRED_FILE} --save-app saveapp --app application"
|
54
|
-
p.run!
|
55
|
-
p.stdout.should include 'Saved'
|
56
|
-
output = YAML.load open(FAKE_CRED_FILE).read
|
57
|
-
output[:applications]["saveapp"].should eq 'application'
|
58
|
-
end
|
59
|
-
it "saves user:token pairs" do
|
60
|
-
p = CLIProcess.new "#{CMD} --config_file #{FAKE_CRED_FILE} --save-user saveuser --user user"
|
61
|
-
p.run!
|
62
|
-
p.stdout.should include 'Saved'
|
63
|
-
output = YAML.load open(FAKE_CRED_FILE).read
|
64
|
-
output[:users]["saveuser"].should eq 'user'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
describe "sounds" do
|
68
|
-
it "will list sounds" do
|
69
|
-
p = CLIProcess.new "#{CMD} --config_file #{CRED_FILE} --sound_list", 3, 3
|
70
|
-
p.run!
|
71
|
-
p.stdout.should include "Current Sound"
|
72
|
-
p.stdout.should include "Pushover (default)"
|
73
|
-
p.stdout.should include "None (silent)"
|
74
|
-
end
|
75
|
-
it "will play a sound (based on partial string)" do
|
76
|
-
p = CLIProcess.new "#{CMD} --config_file #{CRED_FILE} a message --sound none", 3, 3
|
77
|
-
p.run!
|
78
|
-
p.stdout.should include "success"
|
79
|
-
end
|
80
|
-
it "will fail if the sound is unavailble" do
|
81
|
-
p = CLIProcess.new "#{CMD} --config_file #{CRED_FILE} a message --sound slkdjg", 3, 3
|
82
|
-
p.run!
|
83
|
-
p.stdout.should include "No such sound"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
describe "emergency notifications" do
|
87
|
-
it "will respond to emergency parameters" do
|
88
|
-
p = CLIProcess.new "#{CMD} --config_file #{CRED_FILE} an emergency message retry test --priority em --emergency_retry 180", 3, 3
|
89
|
-
p.run!
|
90
|
-
p.stdout.should include "success"
|
91
|
-
|
92
|
-
p = CLIProcess.new "#{CMD} --config_file #{CRED_FILE} an emergency message expires test --priority em --emergency_expire 7200", 3, 3
|
93
|
-
p.run!
|
94
|
-
p.stdout.should include "success"
|
95
|
-
end
|
96
|
-
|
97
|
-
it "will print the receipt" do
|
98
|
-
p = CLIProcess.new "#{CMD} --config_file #{CRED_FILE} an emergency message --priority em", 3, 3
|
99
|
-
p.run!
|
100
|
-
p.stdout.should include "receipt"
|
101
|
-
end
|
102
|
-
|
103
|
-
it "will accept a callback url"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
|
data/spec/cli_spec_helper.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
# Ripped without remorse from: https://github.com/cucumber/aruba/blob/master/lib/aruba/process.rb
|
2
|
-
# slightly modified for my purposes.
|
3
|
-
require 'childprocess'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'shellwords'
|
6
|
-
|
7
|
-
class CLIProcess
|
8
|
-
include Shellwords
|
9
|
-
|
10
|
-
def initialize(cmd, exit_timeout = 0, io_wait = 1)
|
11
|
-
@exit_timeout = exit_timeout
|
12
|
-
@io_wait = io_wait
|
13
|
-
@io_waited = false
|
14
|
-
|
15
|
-
@cmd = cmd
|
16
|
-
@process = nil
|
17
|
-
@exit_code = nil
|
18
|
-
end
|
19
|
-
|
20
|
-
def run!(&block)
|
21
|
-
@process = ChildProcess.build(*shellwords(@cmd))
|
22
|
-
@out = Tempfile.new("binary-out")
|
23
|
-
@err = Tempfile.new("binary-err")
|
24
|
-
@process.io.stdout = @out
|
25
|
-
@process.io.stderr = @err
|
26
|
-
@process.duplex = true
|
27
|
-
@exit_code = nil
|
28
|
-
begin
|
29
|
-
@process.start
|
30
|
-
rescue ChildProcess::LaunchError => e
|
31
|
-
raise LaunchError.new(e.message)
|
32
|
-
end
|
33
|
-
yield self if block_given?
|
34
|
-
end
|
35
|
-
|
36
|
-
def stdin
|
37
|
-
@process.io.stdin
|
38
|
-
end
|
39
|
-
|
40
|
-
def output(keep_ansi = false)
|
41
|
-
stdout(keep_ansi) + stderr(keep_ansi)
|
42
|
-
end
|
43
|
-
|
44
|
-
def stdout(keep_ansi = false)
|
45
|
-
wait_for_io do
|
46
|
-
@out.rewind
|
47
|
-
filter_ansi(@out.read, keep_ansi)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def stderr(keep_ansi = false)
|
52
|
-
wait_for_io do
|
53
|
-
@err.rewind
|
54
|
-
filter_ansi(@err.read, keep_ansi)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def read_stdout(keep_ansi = false)
|
59
|
-
wait_for_io do
|
60
|
-
@process.io.stdout.flush
|
61
|
-
content = filter_ansi(open(@out.path).read, keep_ansi)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def stop(reader, keep_ansi)
|
66
|
-
return @exit_code unless @process
|
67
|
-
unless @process.exited?
|
68
|
-
@process.poll_for_exit(@exit_timeout)
|
69
|
-
end
|
70
|
-
reader.stdout stdout(keep_ansi)
|
71
|
-
reader.stderr stderr(keep_ansi)
|
72
|
-
@exit_code = @process.exit_code
|
73
|
-
@process = nil
|
74
|
-
@exit_code
|
75
|
-
end
|
76
|
-
|
77
|
-
def terminate(keep_ansi = false)
|
78
|
-
if @process
|
79
|
-
stdout(keep_ansi = false) && stderr(keep_ansi) # flush output
|
80
|
-
@process.stop
|
81
|
-
stdout(keep_ansi) && stderr(keep_ansi) # flush output
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def wait_for_io(&block)
|
88
|
-
if @process && !@io_waited
|
89
|
-
sleep @io_wait
|
90
|
-
@io_waited = true
|
91
|
-
end
|
92
|
-
yield
|
93
|
-
end
|
94
|
-
|
95
|
-
def filter_ansi(string, keep_ansi)
|
96
|
-
keep_ansi ? string : string.gsub(/\e\[\d+(?>(;\d+)*)m/, '')
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "application" do
|
4
|
-
before(:each) do
|
5
|
-
Bini::Config.clear
|
6
|
-
Bini::Options.clear
|
7
|
-
App.current_app = nil
|
8
|
-
end
|
9
|
-
|
10
|
-
it "can add a application to the Config[:application] hash." do
|
11
|
-
App.add "foo", "bar"
|
12
|
-
Bini::Config[:applications]["foo"].should eq("bar")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "can remove a application from the hash." do
|
16
|
-
App.add "foo", "bar"
|
17
|
-
App.remove "foo"
|
18
|
-
Bini::Config[:applications]["foo"].should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#find" do
|
22
|
-
it "can find the apikey from the name" do
|
23
|
-
App.add "foo", "bar"
|
24
|
-
App.find("foo").should eq("bar")
|
25
|
-
end
|
26
|
-
it "If it can't find the apikey, it will still try whatever was passed" do
|
27
|
-
App.find("tryme").should eq "tryme"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#current_app" do
|
32
|
-
it "will look on the cli first" do
|
33
|
-
Bini::Options[:token] = 'anapikey'
|
34
|
-
App.current_app.should eq "anapikey"
|
35
|
-
end
|
36
|
-
it "will grab the first app in the config as a last resort" do
|
37
|
-
App.add "foo", "bar2"
|
38
|
-
Bini::Config.save
|
39
|
-
Bini::Options[:token] = nil
|
40
|
-
App.current_app.should eq "bar2"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#current_app?" do
|
45
|
-
it "Will return true if we have a current_app" do
|
46
|
-
Bini::Options[:token] = 'somethingsilly'
|
47
|
-
App.current_app.should eq 'somethingsilly'
|
48
|
-
end
|
49
|
-
it "Will return nil otherwise" do
|
50
|
-
App.current_app?.should be_nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "user" do
|
4
|
-
before(:each) do
|
5
|
-
Bini::Config.clear
|
6
|
-
Bini::Options.clear
|
7
|
-
User.current_user = nil
|
8
|
-
end
|
9
|
-
|
10
|
-
it "can add a user to the Config[:users] hash." do
|
11
|
-
User.add "foo", "bar"
|
12
|
-
Bini::Config[:users]["foo"].should eq("bar")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "can remove a user from the hash." do
|
16
|
-
User.add "foo", "bar"
|
17
|
-
User.remove "foo"
|
18
|
-
Bini::Config[:users]["foo"].should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#find" do
|
22
|
-
it "can find the token from the name" do
|
23
|
-
User.add "foo", "bar"
|
24
|
-
User.find("foo").should eq("bar")
|
25
|
-
end
|
26
|
-
it "If it can't find the token, it will still try whatever was passed" do
|
27
|
-
User.find("tryme").should eq "tryme"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#current_user" do
|
32
|
-
it "will look on the cli first" do
|
33
|
-
Bini::Options[:user] = 'atoken'
|
34
|
-
User.current_user.should eq "atoken"
|
35
|
-
end
|
36
|
-
it "will grab the first user in the config as a last resort" do
|
37
|
-
User.add "foo", "bar2"
|
38
|
-
Bini::Config.save
|
39
|
-
Bini::Options[:user] = nil
|
40
|
-
User.current_user.should eq "bar2"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#current_user?" do
|
45
|
-
it "Will return true if we have a current_user" do
|
46
|
-
Bini::Options[:user] = 'somethingsilly'
|
47
|
-
User.current_user?.should be_true
|
48
|
-
end
|
49
|
-
it "Will return nil otherwise" do
|
50
|
-
User.current_user?.should be_nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|