pushover 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/bin/pushover +13 -0
- data/lib/pushover.rb +18 -0
- data/lib/pushover/config.rb +40 -0
- data/lib/pushover/optparser.rb +52 -0
- data/lib/pushover/version.rb +3 -0
- data/pushover.gemspec +18 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ernie Brodeur
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Pushover
|
2
|
+
|
3
|
+
This gem provides a CLI and an API interface to http://pushover.net
|
4
|
+
|
5
|
+
Currently it's a work in process and I haven't built out the CLI yet, that will happen shortly.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To install:
|
10
|
+
|
11
|
+
$ gem install pushover
|
12
|
+
|
13
|
+
To use inside of an application, add this to the your gemfile:
|
14
|
+
|
15
|
+
$ gem 'pushover'
|
16
|
+
|
17
|
+
and run bundle to make it available:
|
18
|
+
|
19
|
+
$ Bundle
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Progmatic usage:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'pushover'
|
27
|
+
|
28
|
+
Pushover.notification('your_token', 'app_token', 'message', 'title')
|
29
|
+
```
|
30
|
+
|
31
|
+
Title is currently optional, it doesn't do more then this yet.
|
32
|
+
|
33
|
+
CLI usage:
|
34
|
+
|
35
|
+
$ pushover -a apitoken -t token -m 'message goes in here' -t 'title is optional.'
|
36
|
+
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/pushover
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pushover'
|
4
|
+
|
5
|
+
include Pushover
|
6
|
+
Options.parse!
|
7
|
+
|
8
|
+
response = Pushover.notification Options[:token], Options[:appkey], Options[:message]
|
9
|
+
if response.code == 200
|
10
|
+
puts "Message sent successfully!"
|
11
|
+
else
|
12
|
+
puts "#{response.code}: #{response.body}"
|
13
|
+
end
|
data/lib/pushover.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "net/https"
|
2
|
+
|
3
|
+
require "pushover/version"
|
4
|
+
require "pushover/config"
|
5
|
+
require "pushover/optparser"
|
6
|
+
|
7
|
+
module Pushover
|
8
|
+
# push a message to across pushover, must supply all variables.
|
9
|
+
def self.notification(token, application, message, title = nil)
|
10
|
+
url = URI.parse("https://api.pushover.net/1/messages")
|
11
|
+
req = Net::HTTP::Post.new(url.path)
|
12
|
+
req.set_form_data({:token => token, :user => application, :message => message, :title => title})
|
13
|
+
res = Net::HTTP.new(url.host, url.port)
|
14
|
+
res.use_ssl = true
|
15
|
+
res.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
16
|
+
res.start {|http| http.request(req) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Pushover
|
4
|
+
class ConfigBlob < Hash
|
5
|
+
BaseDir = "#{Dir.home}/.config/pushover"
|
6
|
+
|
7
|
+
def initialize(load = true)
|
8
|
+
FileUtils.mkdir_p BaseDir if !Dir.exist? BaseDir
|
9
|
+
self.load if load
|
10
|
+
end
|
11
|
+
|
12
|
+
def file
|
13
|
+
"#{BaseDir}/config.json"
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
if any?
|
18
|
+
# I do this the long way because I want an immediate sync.
|
19
|
+
f = open(file, 'w')
|
20
|
+
f.write Yajl.dump self
|
21
|
+
f.sync
|
22
|
+
f.close
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def save!
|
27
|
+
FileUtils.rm file if File.file? file
|
28
|
+
save
|
29
|
+
end
|
30
|
+
|
31
|
+
def load
|
32
|
+
if File.exist? self.file
|
33
|
+
h = Yajl.load open(file, 'r').read
|
34
|
+
h.each { |k,v| self[k.to_sym] = v}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Config = ConfigBlob.new
|
40
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Pushover
|
4
|
+
class OptionParser < ::OptionParser
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@options = {}
|
8
|
+
|
9
|
+
on("-V", "--version", "Print version") { |version| @options[:version] = true}
|
10
|
+
on("-t", "--token TOKEN", "Set your identity token.") { |o| @options[:token] = o}
|
11
|
+
on("-a", "--app-key APPKEY", "Set the receiving application key.") { |o| @options[:appkey] = o}
|
12
|
+
on("-m", "--message MESSAGE", "The message to be sent.") { |o| @options[:message] = o}
|
13
|
+
on("-T", "--title [TITLE]", "Set the title of the notification (optional).") { |o| @options[:title] = o}
|
14
|
+
end
|
15
|
+
|
16
|
+
# This will build an on/off option with a default value set to false.
|
17
|
+
def bool_on(word, description = "")
|
18
|
+
Options[word.to_sym] = false
|
19
|
+
on "-#{word.chars.first}", "--[no]#{word}", description do |o|
|
20
|
+
Options[word.to_sym] == o
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse!
|
25
|
+
@banner = Pushover::VERSION
|
26
|
+
super
|
27
|
+
|
28
|
+
if @options[:version]
|
29
|
+
puts Pushover::VERSION
|
30
|
+
exit 0
|
31
|
+
end
|
32
|
+
|
33
|
+
# we need to mash in our config array. To do this we want to make config
|
34
|
+
# options that don't overwrite cli options.
|
35
|
+
Config.each do |k,v|
|
36
|
+
@options[k] = v if !@options[k]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def [](k = nil)
|
41
|
+
return @options[k] if k
|
42
|
+
return @options if @options.any?
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def []=(k,v)
|
47
|
+
@options[k] = v
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Options = OptionParser.new
|
52
|
+
end
|
data/pushover.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/pushover/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ernie Brodeur"]
|
6
|
+
gem.email = ["ebrodeur@ujami.net"]
|
7
|
+
gem.description = "App (and CLI) to interface with pushover.net"
|
8
|
+
gem.summary = "This gem will provide both an API and CLI interface to pushover.net."
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "pushover"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Pushover::VERSION
|
17
|
+
gem.add_development_dependency('pry')
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushover
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ernie Brodeur
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: App (and CLI) to interface with pushover.net
|
31
|
+
email:
|
32
|
+
- ebrodeur@ujami.net
|
33
|
+
executables:
|
34
|
+
- pushover
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/pushover
|
44
|
+
- lib/pushover.rb
|
45
|
+
- lib/pushover/config.rb
|
46
|
+
- lib/pushover/optparser.rb
|
47
|
+
- lib/pushover/version.rb
|
48
|
+
- pushover.gemspec
|
49
|
+
homepage: ''
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.21
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: This gem will provide both an API and CLI interface to pushover.net.
|
73
|
+
test_files: []
|
74
|
+
has_rdoc:
|