pushover 0.1.1 → 0.1.2
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 +13 -4
- data/lib/pushover.rb +41 -2
- data/lib/pushover/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -22,14 +22,23 @@ and run bundle to make it available:
|
|
22
22
|
|
23
23
|
Progmatic usage:
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
require 'pushover'
|
26
|
+
|
27
|
+
Pushover.notification('message', 'title', user:'USER_TOKEN', token:'APP_TOKEN')
|
27
28
|
|
28
|
-
Pushover.notification('your_token', 'app_token', 'message', 'title')
|
29
|
-
```
|
30
29
|
|
31
30
|
Title is currently optional, it doesn't do more then this yet.
|
32
31
|
|
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
|
+
|
33
42
|
CLI usage:
|
34
43
|
|
35
44
|
$ pushover -a apitoken -t token -m 'message goes in here' -t 'title is optional.'
|
data/lib/pushover.rb
CHANGED
@@ -5,14 +5,53 @@ require "pushover/config"
|
|
5
5
|
require "pushover/optparser"
|
6
6
|
|
7
7
|
module Pushover
|
8
|
+
|
9
|
+
def params
|
10
|
+
Pushover.parameters
|
11
|
+
end
|
12
|
+
|
13
|
+
extend self
|
14
|
+
|
15
|
+
attr_accessor :token, :user
|
16
|
+
|
8
17
|
# push a message to across pushover, must supply all variables.
|
9
|
-
def
|
18
|
+
def notification(message, title = nil, tokens={})
|
10
19
|
url = URI.parse("https://api.pushover.net/1/messages")
|
11
20
|
req = Net::HTTP::Post.new(url.path)
|
12
|
-
req.set_form_data({:
|
21
|
+
req.set_form_data((params.merge(tokens.merge({:message => message, :title => title}))))
|
13
22
|
res = Net::HTTP.new(url.host, url.port)
|
14
23
|
res.use_ssl = true
|
15
24
|
res.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
16
25
|
res.start {|http| http.request(req) }
|
17
26
|
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
|
+
|
18
57
|
end
|
data/lib/pushover/version.rb
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.1.
|
4
|
+
version: 0.1.2
|
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-
|
12
|
+
date: 2012-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|