pushover 0.1.2 → 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.
- data/README.md +4 -13
- data/bin/pushover +35 -5
- data/lib/pushover.rb +5 -41
- data/lib/pushover/app.rb +37 -0
- data/lib/pushover/config.rb +1 -1
- data/lib/pushover/optparser.rb +9 -4
- data/lib/pushover/user.rb +33 -0
- data/lib/pushover/version.rb +1 -1
- data/pushover.gemspec +1 -0
- metadata +20 -2
data/README.md
CHANGED
@@ -22,23 +22,14 @@ and run bundle to make it available:
|
|
22
22
|
|
23
23
|
Progmatic usage:
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
Pushover.notification('message', 'title', user:'USER_TOKEN', token:'APP_TOKEN')
|
25
|
+
```ruby
|
26
|
+
require 'pushover'
|
28
27
|
|
28
|
+
Pushover.notification('your_token', 'app_token', 'message', 'title')
|
29
|
+
```
|
29
30
|
|
30
31
|
Title is currently optional, it doesn't do more then this yet.
|
31
32
|
|
32
|
-
Optional #configuration method:
|
33
|
-
|
34
|
-
Pushover.configure do |config|
|
35
|
-
config.user='USER_TOKEN'
|
36
|
-
config.token='APP_TOKEN'
|
37
|
-
end
|
38
|
-
|
39
|
-
Pushover.notification('message', 'title')
|
40
|
-
|
41
|
-
|
42
33
|
CLI usage:
|
43
34
|
|
44
35
|
$ pushover -a apitoken -t token -m 'message goes in here' -t 'title is optional.'
|
data/bin/pushover
CHANGED
@@ -5,9 +5,39 @@ require 'pushover'
|
|
5
5
|
include Pushover
|
6
6
|
Options.parse!
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
puts "#{response.code}: #{response.body}"
|
8
|
+
if Options[:save_app]
|
9
|
+
puts "Saving application #{Options[:save_app][0]} to #{Options[:save_app][1]}."
|
10
|
+
Pushover::App.add Options[:save_app][0], Options[:save_app][1]
|
11
|
+
exit
|
13
12
|
end
|
13
|
+
|
14
|
+
if Options[:save_user]
|
15
|
+
puts "Saving user #{Options[:save_user][0]} to #{Options[:save_user][1]}."
|
16
|
+
Pushover::User.add Options[:save_user][0], Options[:save_user][1]
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "Try pushover -h for help." if Options.empty? && ARGV.empty?
|
21
|
+
|
22
|
+
if ARGV
|
23
|
+
if !Options[:appkey]
|
24
|
+
puts "Must supply the api_key or keyname via --(a)pp"
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
if !Options[:user]
|
29
|
+
puts "Must supply the username or token via --(u)ser."
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
api_key = Pushover::App.find Options[:appkey]
|
34
|
+
user = Pushover::User.find Options[:user]
|
35
|
+
|
36
|
+
response = Pushover.notification user, api_key, ARGV.join(" ")
|
37
|
+
if response.code == 200
|
38
|
+
puts "Message sent successfully!"
|
39
|
+
else
|
40
|
+
puts "#{response.code}: #{response.body}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/lib/pushover.rb
CHANGED
@@ -1,57 +1,21 @@
|
|
1
1
|
require "net/https"
|
2
|
+
require "yajl"
|
2
3
|
|
3
4
|
require "pushover/version"
|
5
|
+
require "pushover/app"
|
6
|
+
require "pushover/user"
|
4
7
|
require "pushover/config"
|
5
8
|
require "pushover/optparser"
|
6
9
|
|
7
10
|
module Pushover
|
8
|
-
|
9
|
-
def params
|
10
|
-
Pushover.parameters
|
11
|
-
end
|
12
|
-
|
13
|
-
extend self
|
14
|
-
|
15
|
-
attr_accessor :token, :user
|
16
|
-
|
17
11
|
# push a message to across pushover, must supply all variables.
|
18
|
-
def notification(message, title = nil
|
12
|
+
def self.notification(token, application, message, title = nil)
|
19
13
|
url = URI.parse("https://api.pushover.net/1/messages")
|
20
14
|
req = Net::HTTP::Post.new(url.path)
|
21
|
-
req.set_form_data(
|
15
|
+
req.set_form_data({:token => token, :user => application, :message => message, :title => title})
|
22
16
|
res = Net::HTTP.new(url.host, url.port)
|
23
17
|
res.use_ssl = true
|
24
18
|
res.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
25
19
|
res.start {|http| http.request(req) }
|
26
20
|
end
|
27
|
-
|
28
|
-
# Adds a rails style configure method
|
29
|
-
def configure
|
30
|
-
yield self
|
31
|
-
parameters
|
32
|
-
end
|
33
|
-
|
34
|
-
# List available parameters and values in those params
|
35
|
-
def parameters
|
36
|
-
@values = {}
|
37
|
-
keys.each { |k| @values.merge! k => get_var("@#{k}") }
|
38
|
-
@values
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns true or false if all parameters are set.
|
42
|
-
def parameters?
|
43
|
-
parameters.values.all?
|
44
|
-
end
|
45
|
-
|
46
|
-
def keys
|
47
|
-
keys ||= [:token, :user]
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
# Helper to clean up recursive method in #parameters
|
53
|
-
def get_var(var)
|
54
|
-
self.instance_variable_get(var)
|
55
|
-
end
|
56
|
-
|
57
21
|
end
|
data/lib/pushover/app.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Pushover
|
2
|
+
module App
|
3
|
+
class App
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :api_key
|
6
|
+
|
7
|
+
def initialize(api_key, name)
|
8
|
+
@name = name
|
9
|
+
@api_key = api_key
|
10
|
+
Pushover::Config[:applications] = {} if !Pushover::Config[:applications]
|
11
|
+
if name
|
12
|
+
Pushover::Config[:applications][name] = api_key
|
13
|
+
else
|
14
|
+
Pushover::Config[:applications][api_key] = api_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
# Find the apikey in the applications, or pass on the word to try direct access.
|
21
|
+
# @param [String] word the search token, can be an apikey or appname.
|
22
|
+
# @return [String] return the apikey (if it can find one) or the word itself.
|
23
|
+
def self.find(word)
|
24
|
+
return Config[:applications][word] if Config[:applications] && Config[:applications].include?(word)
|
25
|
+
word
|
26
|
+
end
|
27
|
+
|
28
|
+
# Add an application to the config file and save it.
|
29
|
+
# @param [String] api_key is the api_key to be used.
|
30
|
+
# @param [String] name is the short name that can be referenced later.
|
31
|
+
# @return [Boolean] return the results of the save attempt.
|
32
|
+
def self.add(api_key, name)
|
33
|
+
App.new api_key, name
|
34
|
+
Pushover::Config.save!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/pushover/config.rb
CHANGED
data/lib/pushover/optparser.rb
CHANGED
@@ -7,10 +7,11 @@ module Pushover
|
|
7
7
|
@options = {}
|
8
8
|
|
9
9
|
on("-V", "--version", "Print version") { |version| @options[:version] = true}
|
10
|
-
on("-
|
11
|
-
on("-a", "--app
|
12
|
-
on("-m", "--message MESSAGE", "The message to be sent.") { |o| @options[:message] = o}
|
10
|
+
on("-u", "--user USER", "Which user, can be a saved name or token.") { |o| @options[:user] = o}
|
11
|
+
on("-a", "--app APPKEY", "Which app to notify, can be a saved name or apikey.") { |o| @options[:appkey] = o}
|
13
12
|
on("-T", "--title [TITLE]", "Set the title of the notification (optional).") { |o| @options[:title] = o}
|
13
|
+
on("--save-app NAME", "Saves the application to the config file under NAME.") { |o| @options[:save_app] = [@options[:appkey], o]}
|
14
|
+
on("--save-user NAME", "Saves the user to the config file under NAME.") { |o| @options[:save_user] = [@options[:user], o]}
|
14
15
|
end
|
15
16
|
|
16
17
|
# This will build an on/off option with a default value set to false.
|
@@ -33,7 +34,7 @@ module Pushover
|
|
33
34
|
# we need to mash in our config array. To do this we want to make config
|
34
35
|
# options that don't overwrite cli options.
|
35
36
|
Config.each do |k,v|
|
36
|
-
@options[k] = v if !@options[k]
|
37
|
+
@options[k] = v if !@options[k] && ["applications", "users"].include?(k)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -46,6 +47,10 @@ module Pushover
|
|
46
47
|
def []=(k,v)
|
47
48
|
@options[k] = v
|
48
49
|
end
|
50
|
+
|
51
|
+
def empty?
|
52
|
+
@options.empty?
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
Options = OptionParser.new
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Pushover
|
2
|
+
module User
|
3
|
+
class User
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :token
|
6
|
+
|
7
|
+
def initialize(token, name)
|
8
|
+
@name = name
|
9
|
+
@token = token
|
10
|
+
Pushover::Config[:users] = {} if !Pushover::Config[:users]
|
11
|
+
Pushover::Config[:users][name] = token
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
# Find the apikey in the applications, or pass on the word to try direct access.
|
17
|
+
# @param [String] word the search token, can be an apikey or appname.
|
18
|
+
# @return [String] return the apikey (if it can find one) or the word itself.
|
19
|
+
def self.find(word)
|
20
|
+
return Config[:users][word] if Config[:users] && Config[:users].include?(word)
|
21
|
+
word
|
22
|
+
end
|
23
|
+
|
24
|
+
# Add an application to the config file and save it.
|
25
|
+
# @param [String] token is the token to be used.
|
26
|
+
# @param [String] name is the short name that can be referenced later.
|
27
|
+
# @return [Boolean] return the results of the save attempt.
|
28
|
+
def self.add(token, name)
|
29
|
+
User.new token, name
|
30
|
+
Pushover::Config.save!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/pushover/version.rb
CHANGED
data/pushover.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yajl-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: App (and CLI) to interface with pushover.net
|
31
47
|
email:
|
32
48
|
- ebrodeur@ujami.net
|
@@ -42,8 +58,10 @@ files:
|
|
42
58
|
- Rakefile
|
43
59
|
- bin/pushover
|
44
60
|
- lib/pushover.rb
|
61
|
+
- lib/pushover/app.rb
|
45
62
|
- lib/pushover/config.rb
|
46
63
|
- lib/pushover/optparser.rb
|
64
|
+
- lib/pushover/user.rb
|
47
65
|
- lib/pushover/version.rb
|
48
66
|
- pushover.gemspec
|
49
67
|
homepage: ''
|