pushover 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,71 +1,88 @@
1
1
  # Pushover
2
2
 
3
- This gem provides a CLI and an API interface to http://pushover.net
4
-
5
- It's main usage as a CLI, see below for specifics.
6
-
7
- Some CLI features:
8
-
9
- * Multiple users/applications can be stored.
10
- * Do not need to supply either, will find the first one available.
11
- * Supplying on the CLI will always override the stored variables.
3
+ This gem provides a CLI and an API interface to http://pushover.net.
12
4
 
13
5
  ## Installation
14
6
 
15
7
  To install:
16
8
 
17
- $ gem install pushover
9
+ % gem install pushover
18
10
 
19
11
  To use inside of an application, add this to the your gemfile:
20
12
 
21
- $ gem 'pushover'
13
+ % gem 'pushover'
22
14
 
23
15
  and run bundle to make it available:
24
16
 
25
- $ bundle
17
+ % bundle
26
18
 
27
19
  ## Usage
28
20
 
29
21
  ### API:
30
-
31
- require 'pushover'
22
+ ```ruby
23
+ require 'pushover'
24
+ ```
32
25
 
33
26
  To send with the very minimum amount of information.
34
27
 
35
- Pushover.notification('message', 'title', user:'USER_TOKEN', token:'APP_TOKEN')
28
+ ```ruby
29
+ Pushover.notification('message', 'title', user:'USER_TOKEN', token:'APP_TOKEN')
30
+ ```
36
31
 
37
32
  Optional #configuration method:
33
+ ```ruby
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
+ ### CLI:
38
42
 
39
- Pushover.configure do |config|
40
- config.user='USER_TOKEN'
41
- config.token='APP_TOKEN'
42
- end
43
+ To get help do, try ```--(h)elp```
43
44
 
44
- Pushover.notification('message', 'title')
45
45
 
46
- ### CLI:
46
+ % pushover --h
47
+
48
+ To send a message.
47
49
 
48
- To send a message. This will override any saved information available.
50
+ % pushover -u user_token -a app_key message is the rest of the cli.
49
51
 
50
- $ pushover -u user_token -a app_key message is the rest of the cli.
52
+ #### Optional parameters
53
+
54
+ * Title: Title of your notifcation
55
+ * Config_file: the file to use for stored credentials.
56
+ * Priority: Priority of the message, as an integer (for now).
57
+ * -1: low
58
+ * 0: normal
59
+ * 1: high
60
+ * Device: specific device to send the notification to.
61
+
62
+
63
+ #### Saving user and application.
51
64
 
52
65
  You can also save and use stored information. The username/application are titles. They can be anything you want to reference them.
53
66
 
54
67
  User:
55
68
 
56
- $ pushover -u user_token --save-user username
69
+ % pushover -u user_token --save-user email@somewhere.net
57
70
 
58
71
  Application:
59
72
 
60
- $ pushover -a app_key --save-user application
73
+ % pushover -a app_key --save-app myApp
61
74
 
62
- This will allow you to do:
75
+ Delete coming soon.
63
76
 
64
- $ pushover -a new_app -u username message body.
77
+ Now, you can use these to send messages instead of having to remeber the key:
65
78
 
66
- If you don't supply any credentials, and it has them saved, it will use the first set saved. This allows for a completely lazy mode ```pushover message body here``` for sending without having to constantly specify credentials.
79
+ % pushover -a myApp -u email@somewhere.net Hello from somewhere!
67
80
 
68
- Delete coming soon.
81
+ If you don't supply the application or user name, it will use the first one in the save file.
82
+
83
+ % pushover so now I can just send an app.
84
+
85
+ Anytime you supply token's directly to the cli, it will ignore any saved information and try them. This allows you to use it as a once-off tool while keeping credentials stored.
69
86
 
70
87
  ## Testing
71
88
 
@@ -24,8 +24,11 @@ if Options[:save_user]
24
24
  puts "Save successful."
25
25
  exit
26
26
  end
27
- puts "Try pushover -h for help." if Options.empty? && ARGV.empty?
28
27
 
28
+ if ARGV.empty?
29
+ puts "You must supply a message."
30
+ exit
31
+ end
29
32
  bail = false
30
33
  message = ARGV.join(" ")
31
34
 
@@ -44,11 +47,21 @@ if !User.current_user?
44
47
  bail = true
45
48
  end
46
49
  exit if bail
47
- title = nil
48
- response = Pushover.notification message, title, user:User.current_user, token:App.current_app
50
+
51
+ Pushover.configure do |c|
52
+ c.user = User.current_user
53
+ c.token = App.current_app
54
+ c.message = message
55
+ c.title = Options[:title]
56
+ c.priority = Options[:priority]
57
+ c.device = Options[:device]
58
+ end
59
+
60
+ response = Pushover.notification
49
61
 
50
62
  if response.code == "200"
51
63
  puts "Message sent successfully!"
52
64
  else
53
- puts "#{response.code} #{response.message}:#{response.body}"
65
+ j = Yajl.load response.body
66
+ puts "ErrorCode (#{response.code}): #{j['errors'].first}."
54
67
  end
@@ -10,27 +10,41 @@ require "pushover/optparser"
10
10
  # The primary pushover namespace.
11
11
  module Pushover
12
12
 
13
- def params
14
- Pushover.parameters
15
- end
16
-
17
- extend self
18
-
19
- attr_accessor :token, :user
20
-
21
- # push a message to across pushover, must supply all variables.
22
- def notification(message, title = nil, tokens={})
23
- url = URI.parse("https://api.pushover.net/1/messages.json")
24
- req = Net::HTTP::Post.new(url.path)
25
- req.set_form_data((params.merge(tokens.merge({:message => message, :title => title}))))
26
- res = Net::HTTP.new(url.host, url.port)
27
- res.use_ssl = true
28
- res.verify_mode = OpenSSL::SSL::VERIFY_PEER
29
- res.start {|http| http.request(req) }
30
- end
31
-
32
- # Adds a rails style configure method
33
- def configure
13
+ extend self
14
+
15
+ # [String] The api key to be used for the notifcation.
16
+ attr_accessor :token
17
+ # [String] of the user token currently being used.
18
+ attr_accessor :user
19
+ # [String] message the message to be sent.
20
+ attr_accessor :message
21
+ # [optional,String] Title of the message.
22
+ attr_accessor :title
23
+ # [optional,Fixnum] priority The priority of the message, from -1 to 1.
24
+ attr_accessor :priority
25
+ # [optional,String] device to recieve the message.
26
+ attr_accessor :device
27
+
28
+ # push a message to pushover, must supply all variables.
29
+ # @param [String] message The message to be sent
30
+ # @param [optional, String] title The title of the message
31
+ # @param [optional, Fixnum] priority of the message to be sent, from -1 to 1.
32
+ # @param [optional, String] device The specific device to be notified.
33
+ # @param [optional, String] app api key.
34
+ # @param [optional, String] user the user token.
35
+ # @return [String] the response from pushover.net, in json.
36
+ def notification(tokens={})
37
+ url = URI.parse("https://api.pushover.net/1/messages.json")
38
+ req = Net::HTTP::Post.new(url.path)
39
+ req.set_form_data(params.merge tokens)
40
+ res = Net::HTTP.new(url.host, url.port)
41
+ res.use_ssl = true
42
+ res.verify_mode = OpenSSL::SSL::VERIFY_PEER
43
+ res.start {|http| http.request(req) }
44
+ end
45
+
46
+ # Adds a rails style configure method
47
+ def configure
34
48
  yield self
35
49
  parameters
36
50
  end
@@ -41,14 +55,16 @@ module Pushover
41
55
  keys.each { |k| @values.merge! k => get_var("@#{k}") }
42
56
  @values
43
57
  end
58
+ alias_method :params, :parameters
44
59
 
45
60
  # Returns true or false if all parameters are set.
46
61
  def parameters?
47
62
  parameters.values.all?
48
63
  end
49
64
 
65
+ # A [Array] of keys available in Pushover.
50
66
  def keys
51
- keys ||= [:token, :user]
67
+ keys ||= [:token, :user, :message, :title, :priority, :device]
52
68
  end
53
69
 
54
70
  private
@@ -12,7 +12,9 @@ module Pushover
12
12
  on("-V", "--version", "Print version") { |version| @options[:version] = true}
13
13
  on("-u", "--user USER", "Which user, can be a saved name or token.") { |o| @options[:user] = o}
14
14
  on("-a", "--app APPKEY", "Which app to notify, can be a saved name or apikey.") { |o| @options[:appkey] = o}
15
- on("-T", "--title [TITLE]", "Set the title of the notification (optional).") { |o| @options[:title] = o}
15
+ on("-t", "--title [TITLE]", "Set the title of the notification (optional).") { |o| @options[:title] = o}
16
+ on("-p", "--priority [PRIORITY]", DecimalInteger , "Set the priority of the notification from -1 to 1 (optional).") { |o| @options[:priority] = o}
17
+ on("-d", "--device [DEVICE]", "Specify the device to send the notifcation to. (optional).") { |o| @options[:device] = o}
16
18
  on("-c", "--config_file [FILE]", "Set the target config file.") {|o| @options[:config_file] = o}
17
19
  on("--save-app NAME", "Saves the application to the config file under NAME.") { |o| @options[:save_app] = [@options[:appkey], o]}
18
20
  on("--save-user NAME", "Saves the user to the config file under NAME.") { |o| @options[:save_user] = [@options[:user], o]}
@@ -1,4 +1,4 @@
1
1
  module Pushover
2
2
  # The current version of Pushover.
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
@@ -2,18 +2,30 @@
2
2
  require File.expand_path('../lib/pushover/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
+ gem.name = "pushover"
5
6
  gem.authors = ["Ernie Brodeur"]
6
7
  gem.email = ["ebrodeur@ujami.net"]
8
+ gem.date = Time.now.strftime('%Y-%m-%d')
9
+ gem.version = Pushover::VERSION
10
+ gem.platform = Gem::Platform::RUBY
11
+
12
+ # descriptions
7
13
  gem.description = "App (and CLI) to interface with pushover.net"
8
14
  gem.summary = "This gem will provide both an API and CLI interface to pushover.net."
9
- gem.homepage = ""
15
+ gem.homepage = "https://github.com/erniebrodeur/pushover"
10
16
 
17
+ #files
11
18
  gem.files = `git ls-files`.split($\)
12
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
20
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "pushover"
15
21
  gem.require_paths = ["lib"]
16
- gem.version = Pushover::VERSION
22
+
23
+ # documentation
24
+ gem.extra_rdoc_files = Dir.glob("*.md")
25
+ gem.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pushover", "--main", "README.md", "--encoding=UTF-8"]
26
+ gem.has_rdoc = 'yard'
27
+
28
+ # dependencies.
17
29
  gem.add_development_dependency('pry')
18
30
  gem.add_runtime_dependency('yajl-ruby')
19
31
  end
@@ -1,7 +1,17 @@
1
+ Unreleased:
2
+ * Added priority and device specification.
3
+ * Moved all the variables, including message, into the configure block.
4
+ * Documentation push, 100% passage and updated for yardoc.
5
+ * Updated the gemspec with some more information.
6
+ * Better output for error messages.
7
+ 0.3.1
8
+ * Added benwoody's changes back to the system, this allows for some nifty generators.
9
+ * Fixed the nasty bug where it wasn't working once installed.
1
10
  0.3.0
2
11
  * No longer need to supply credentials at all if you have some saved.
3
12
  * Fixed up a ton of documentation and spelling mistakes.
4
13
  * Various bug fixes.
5
14
  * About thirty percent of the tests are complete.
6
- * Added convience methods for App.current_app and User.current_user to supply the correctly inherited credentials.
15
+ * Added convenience methods for App.current_app and User.current_user to supply the correctly inherited credentials.
7
16
  * Will only create the save directory if you attempt to save.
17
+ * You can specify config on the command line via --config_file
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.3.1
4
+ version: 0.4.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-10-27 00:00:00.000000000 Z
12
+ date: 2012-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -49,7 +49,10 @@ email:
49
49
  executables:
50
50
  - pushover
51
51
  extensions: []
52
- extra_rdoc_files: []
52
+ extra_rdoc_files:
53
+ - README.md
54
+ - whatsnew.md
55
+ - dev_notes.md
53
56
  files:
54
57
  - .gitignore
55
58
  - Gemfile
@@ -73,10 +76,17 @@ files:
73
76
  - spec/spec_helper.rb
74
77
  - spec/user_spec.rb
75
78
  - whatsnew.md
76
- homepage: ''
79
+ homepage: https://github.com/erniebrodeur/pushover
77
80
  licenses: []
78
81
  post_install_message:
79
- rdoc_options: []
82
+ rdoc_options:
83
+ - --line-numbers
84
+ - --inline-source
85
+ - --title
86
+ - Pushover
87
+ - --main
88
+ - README.md
89
+ - --encoding=UTF-8
80
90
  require_paths:
81
91
  - lib
82
92
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -105,4 +115,4 @@ test_files:
105
115
  - spec/pushover_spec.rb
106
116
  - spec/spec_helper.rb
107
117
  - spec/user_spec.rb
108
- has_rdoc:
118
+ has_rdoc: yard