pushover 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,14 +22,23 @@ and run bundle to make it available:
22
22
 
23
23
  Progmatic usage:
24
24
 
25
- ```ruby
26
- require 'pushover'
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 self.notification(token, application, message, title = nil)
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({:token => token, :user => application, :message => message, :title => title})
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
@@ -1,3 +1,3 @@
1
1
  module Pushover
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-08-27 00:00:00.000000000 Z
12
+ date: 2012-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry