pushover 0.5.0 → 0.5.1
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/.travis.yml +11 -0
- data/Gemfile +10 -6
- data/Guardfile +0 -2
- data/README.md +12 -0
- data/lib/pushover.rb +11 -11
- data/lib/pushover/app.rb +10 -12
- data/lib/pushover/user.rb +10 -7
- data/lib/pushover/version.rb +1 -1
- data/spec/bin/pushover_spec.rb +0 -38
- data/spec/lib/pushover/app_spec.rb +37 -9
- data/spec/lib/pushover/pushover_spec.rb +45 -2
- data/spec/lib/pushover/user_spec.rb +36 -11
- data/spec/spec_helper.rb +35 -11
- data/whatsnew.md +5 -0
- metadata +3 -4
- data/dev_notes.md +0 -1
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
|
6
|
+
gem "pry"
|
7
7
|
gem "pry-debugger"
|
8
8
|
gem "redcarpet"
|
9
9
|
gem "guard"
|
@@ -11,14 +11,18 @@ group :development do
|
|
11
11
|
gem "guard-rspec"
|
12
12
|
gem "guard-yard"
|
13
13
|
gem "guard-shell"
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
gem 'libnotify', :require => false
|
15
|
+
gem 'growl', :require => false
|
16
|
+
gem 'rb-inotify', :require => false
|
17
17
|
gem 'rb-fsevent', :require => false
|
18
18
|
gem 'rb-fchange', :require => false
|
19
19
|
end
|
20
20
|
|
21
21
|
group :test do
|
22
|
-
|
23
|
-
|
22
|
+
gem "rspec"
|
23
|
+
gem "rake"
|
24
|
+
gem "webmock"
|
25
|
+
gem 'simplecov', :require => false
|
26
|
+
gem 'simplecov-rcov', :require => false
|
24
27
|
end
|
28
|
+
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
This gem provides a CLI and an API interface to http://pushover.net.
|
4
4
|
|
5
|
+
#### Build Status
|
6
|
+
<table border="0">
|
7
|
+
<tr>
|
8
|
+
<td>master</td>
|
9
|
+
<td><a href=http://travis-ci.org/erniebrodeur/pushover?branch=master><img src="https://secure.travis-ci.org/erniebrodeur/pushover.png?branch=master"/></h> </td>
|
10
|
+
</tr>
|
11
|
+
<tr>
|
12
|
+
<td>development</td>
|
13
|
+
<td><a href=http://travis-ci.org/erniebrodeur/pushover?branch=development><img src="https://secure.travis-ci.org/erniebrodeur/pushover.png?branch=development"/></h> </td>
|
14
|
+
</tr>
|
15
|
+
</table>
|
16
|
+
|
5
17
|
## Installation
|
6
18
|
|
7
19
|
To install:
|
data/lib/pushover.rb
CHANGED
@@ -54,9 +54,9 @@ module Pushover
|
|
54
54
|
|
55
55
|
# List available parameters and values in those params
|
56
56
|
def parameters
|
57
|
-
|
58
|
-
keys.each { |k|
|
59
|
-
|
57
|
+
h = {}
|
58
|
+
keys.each { |k| h[k.to_sym] = Pushover.instance_variable_get("@#{k}") }
|
59
|
+
return h
|
60
60
|
end
|
61
61
|
alias_method :params, :parameters
|
62
62
|
|
@@ -65,16 +65,16 @@ module Pushover
|
|
65
65
|
parameters.values.all?
|
66
66
|
end
|
67
67
|
|
68
|
+
# Clear all the currently set parameters
|
69
|
+
def clear
|
70
|
+
keys.each do |k|
|
71
|
+
Pushover.instance_variable_set("@#{k}", nil)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
68
75
|
# A [Array] of keys available in Pushover.
|
69
76
|
def keys
|
70
77
|
keys ||= [:token, :user, :message, :title, :priority, :device]
|
71
78
|
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
# Helper to clean up recursive method in #parameters
|
76
|
-
def get_var(var)
|
77
|
-
self.instance_variable_get(var)
|
78
|
-
end
|
79
|
-
|
80
79
|
end
|
80
|
+
|
data/lib/pushover/app.rb
CHANGED
@@ -14,11 +14,7 @@ module Pushover
|
|
14
14
|
@name = name
|
15
15
|
@api_key = api_key
|
16
16
|
Bini.config[:applications] = {} if !Bini.config[:applications]
|
17
|
-
|
18
|
-
Bini.config[:applications][name] = api_key
|
19
|
-
else
|
20
|
-
Bini.config[:applications][api_key] = api_key
|
21
|
-
end
|
17
|
+
Bini.config[:applications][name] = api_key
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
@@ -28,7 +24,7 @@ module Pushover
|
|
28
24
|
# @param [String] word the search token, can be an apikey or appname.
|
29
25
|
# @return [String] return the apikey (if it can find one) or the word itself.
|
30
26
|
def find(word)
|
31
|
-
return Bini.config[:applications][word] if Bini.config[:applications][word]
|
27
|
+
return Bini.config[:applications][word] if Bini.config[:applications] && Bini.config[:applications][word]
|
32
28
|
word
|
33
29
|
end
|
34
30
|
|
@@ -46,23 +42,25 @@ module Pushover
|
|
46
42
|
end
|
47
43
|
# Return the current app selected, or the first one saved.
|
48
44
|
def current_app
|
49
|
-
return @current_app if @current_app
|
50
|
-
|
51
45
|
# did something get supplied on the cli? try to find it.
|
52
|
-
if Options[:
|
53
|
-
@current_app = find Options[:
|
46
|
+
if Bini::Options[:apikey]
|
47
|
+
@current_app = find Bini::Options[:apikey]
|
54
48
|
end
|
55
49
|
|
56
50
|
# no? do we have anything we can return?
|
57
51
|
if !@current_app
|
58
|
-
@current_app = find Bini.config[:applications].first[0]
|
52
|
+
@current_app = find Bini.config[:applications].first[0] if Bini.config[:applications]
|
59
53
|
end
|
60
54
|
@current_app
|
61
55
|
end
|
62
56
|
|
57
|
+
def current_app=(app)
|
58
|
+
@current_app = app
|
59
|
+
end
|
60
|
+
|
63
61
|
# Will return true if we can find an application either via the cli or save file.
|
64
62
|
def current_app?
|
65
|
-
return true if current_app
|
63
|
+
return true if @current_app
|
66
64
|
return nil
|
67
65
|
end
|
68
66
|
end
|
data/lib/pushover/user.rb
CHANGED
@@ -25,7 +25,7 @@ module Pushover
|
|
25
25
|
# @param [String] word the search token, can be an apikey or appname.
|
26
26
|
# @return [String] return the apikey (if it can find one) or the word itself.
|
27
27
|
def find(word)
|
28
|
-
return Bini.config[:users][word] if Bini.config[:users][word]
|
28
|
+
return Bini.config[:users][word] if Bini.config[:users] && Bini.config[:users][word]
|
29
29
|
word
|
30
30
|
end
|
31
31
|
|
@@ -44,23 +44,26 @@ module Pushover
|
|
44
44
|
|
45
45
|
# Return the current user selected, or the first one saved.
|
46
46
|
def current_user
|
47
|
-
return @current_user if @current_user
|
48
|
-
|
49
47
|
# did something get supplied on the cli? try to find it.
|
50
|
-
if Options[:
|
51
|
-
@current_user = find Options[:
|
48
|
+
if Bini::Options[:token]
|
49
|
+
@current_user = find Bini::Options[:token]
|
52
50
|
end
|
53
51
|
|
54
52
|
# no? do we have anything we can return?
|
55
53
|
if !@current_user
|
56
|
-
@current_user = find Bini.config[:users].first[0]
|
54
|
+
@current_user = find Bini.config[:users].first[0] if Bini.config[:users]
|
57
55
|
end
|
58
56
|
@current_user
|
59
57
|
end
|
60
58
|
|
59
|
+
# Set the current_user to whatever you want it to be.
|
60
|
+
def current_user=(user)
|
61
|
+
@current_user = user
|
62
|
+
end
|
63
|
+
|
61
64
|
# Will return true if it can find a user either via the cli or save file.
|
62
65
|
def current_user?
|
63
|
-
return true if current_user
|
66
|
+
return true if @current_user
|
64
67
|
return nil
|
65
68
|
end
|
66
69
|
end
|
data/lib/pushover/version.rb
CHANGED
data/spec/bin/pushover_spec.rb
CHANGED
@@ -1,42 +1,4 @@
|
|
1
1
|
# describe "CLI Interface" do
|
2
|
-
# # the save file to be used.
|
3
|
-
# SaveFile = 'spec/test_config'
|
4
|
-
# # the exact string to execute the test version of pushover.
|
5
|
-
# Exec = "bundle exec bin/pushover"
|
6
|
-
# ExecConfig = Exec + " -c #{SaveFile}"
|
7
|
-
# describe "Can select the config file" do
|
8
|
-
# it "short form (-c)" do
|
9
|
-
# output = `#{ExecConfig}`
|
10
|
-
# output.include? "Selecting config file: #{SaveFile}"
|
11
|
-
# end
|
12
2
|
|
13
|
-
# it "long form (--config_file)" do
|
14
|
-
# output = `#{Exec} -c #{SaveFile}`
|
15
|
-
# output.include? "Selecting config file: #{SaveFile}"
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
# describe "Saving" do
|
19
|
-
# it "Application." do
|
20
|
-
# output = `#{ExecConfig} --app 'test_app_api_key' --save-app test_app`
|
21
|
-
# output.include?("Save successful").should be_true
|
22
|
-
# end
|
23
|
-
# it "User." do
|
24
|
-
# output = `#{ExecConfig} --user 'test_user_key' --save-app test_user`
|
25
|
-
# output.include?("Save successful").should be_true
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
# describe "Sending a message" do
|
29
|
-
# it "With no saved info."
|
30
|
-
# context "With saved information" do
|
31
|
-
# it "With a saved user"
|
32
|
-
# it "With a saved app"
|
33
|
-
# it "With both"
|
34
|
-
# end
|
35
|
-
# describe "Title" do
|
36
|
-
# it "can send with a title"
|
37
|
-
# it "can send without a title"
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
# it "provides the proper version number"
|
41
3
|
# end
|
42
4
|
|
@@ -1,11 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
include Pushover
|
1
|
+
require 'spec_helper'
|
4
2
|
|
5
3
|
describe "application" do
|
6
4
|
before(:each) do
|
7
5
|
Bini.config.file = "tmp/test.save"
|
8
6
|
Bini.config.clear
|
7
|
+
App.current_app = nil
|
9
8
|
end
|
10
9
|
|
11
10
|
it "can add a application to the Config[:application] hash." do
|
@@ -15,12 +14,41 @@ describe "application" do
|
|
15
14
|
|
16
15
|
it "can remove a application from the hash." do
|
17
16
|
App.add "foo", "bar"
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
App.remove "foo"
|
18
|
+
Bini.config[:applications]["foo"].should be_nil
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
describe "#find" do
|
22
|
+
it "can find the apikey from the name" do
|
23
|
+
App.add "foo", "bar"
|
24
|
+
App.find("foo").should eq("bar")
|
25
|
+
end
|
26
|
+
it "If it can't find the apikey, it will still try whatever was passed" do
|
27
|
+
App.find("tryme").should eq "tryme"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#current_app" do
|
32
|
+
it "will look on the cli first" do
|
33
|
+
Bini::Options[:apikey] = 'anapikey'
|
34
|
+
App.current_app.should eq "anapikey"
|
35
|
+
end
|
36
|
+
it "will grab the first app in the config as a last resort" do
|
37
|
+
App.add "foo", "bar2"
|
38
|
+
Bini.config.save
|
39
|
+
Bini::Options[:apikey] = nil
|
40
|
+
App.current_app.should eq "bar2"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#current_app?" do
|
45
|
+
it "Will return true if we have a current_app" do
|
46
|
+
Bini::Options[:apikey] = 'somethingsilly'
|
47
|
+
App.current_app.should eq 'somethingsilly'
|
48
|
+
end
|
49
|
+
it "Will return nil otherwise" do
|
50
|
+
App.current_app?.should be_nil
|
51
|
+
end
|
25
52
|
end
|
26
53
|
end
|
54
|
+
|
@@ -1,5 +1,48 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Pushover" do
|
4
|
-
|
4
|
+
before :each do
|
5
|
+
App.current_app = nil
|
6
|
+
User.current_user = nil
|
7
|
+
Pushover.clear
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#clear" do
|
11
|
+
it "will erase all the attributes in Pushover" do
|
12
|
+
Pushover.send("#{keys.first}=", "something")
|
13
|
+
Pushover.clear
|
14
|
+
parameters.each {|k,v| v.should be_nil}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#parameters?" do
|
19
|
+
it 'will return true only if every key is set to something.' do
|
20
|
+
keys.each {|k| Pushover.send("#{k}=", 'ladeda')}
|
21
|
+
parameters?.should eq true
|
22
|
+
end
|
23
|
+
it 'will return false otherwise.' do
|
24
|
+
Pushover.send("#{keys.first}=", "something")
|
25
|
+
parameters?.should eq false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#configure" do
|
30
|
+
Pushover.keys.each do |key|
|
31
|
+
it "#{key} can be configured via .configure" do
|
32
|
+
r = "acdfef"
|
33
|
+
Pushover.configure do |c|
|
34
|
+
c.instance_variable_set "@#{key}", r
|
35
|
+
end
|
36
|
+
Pushover.send(key).should eq r
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#notification" do
|
42
|
+
it "can send a notification" do
|
43
|
+
setup_webmocks
|
44
|
+
resp = Pushover.notification message:'a message', token:'good_token', user:'good_user'
|
45
|
+
resp.code.should eq "200"
|
46
|
+
end
|
47
|
+
end
|
5
48
|
end
|
@@ -1,28 +1,53 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
include Pushover
|
1
|
+
require 'spec_helper'
|
4
2
|
|
5
3
|
describe "user" do
|
6
4
|
before(:each) do
|
7
5
|
Bini.config.file = "tmp/test.save"
|
8
6
|
Bini.config.clear
|
7
|
+
User.current_user = nil
|
9
8
|
end
|
10
9
|
|
11
|
-
it "can add a user to the Config[:
|
10
|
+
it "can add a user to the Config[:users] hash." do
|
12
11
|
User.add "foo", "bar"
|
13
12
|
Bini.config[:users]["foo"].should eq("bar")
|
14
13
|
end
|
15
14
|
|
16
15
|
it "can remove a user from the hash." do
|
17
16
|
User.add "foo", "bar"
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
User.remove "foo"
|
18
|
+
Bini.config[:users]["foo"].should be_nil
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
describe "#find" do
|
22
|
+
it "can find the token from the name" do
|
23
|
+
User.add "foo", "bar"
|
24
|
+
User.find("foo").should eq("bar")
|
25
|
+
end
|
26
|
+
it "If it can't find the token, it will still try whatever was passed" do
|
27
|
+
User.find("tryme").should eq "tryme"
|
28
|
+
end
|
25
29
|
end
|
26
|
-
end
|
27
30
|
|
31
|
+
describe "#current_user" do
|
32
|
+
it "will look on the cli first" do
|
33
|
+
Bini::Options[:token] = 'atoken'
|
34
|
+
User.current_user.should eq "atoken"
|
35
|
+
end
|
36
|
+
it "will grab the first user in the config as a last resort" do
|
37
|
+
User.add "foo", "bar2"
|
38
|
+
Bini.config.save
|
39
|
+
Bini::Options[:token] = nil
|
40
|
+
User.current_user.should eq "bar2"
|
41
|
+
end
|
42
|
+
end
|
28
43
|
|
44
|
+
describe "#current_user?" do
|
45
|
+
it "Will return true if we have a current_user" do
|
46
|
+
Bini::Options[:token] = 'somethingsilly'
|
47
|
+
User.current_user.should eq 'somethingsilly'
|
48
|
+
end
|
49
|
+
it "Will return nil otherwise" do
|
50
|
+
User.current_user?.should be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
if ENV["COVERAGE"] == 'true'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'simplecov-rcov'
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
SimpleCov::Formatter::RcovFormatter
|
8
|
+
]
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter "/spec/"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
require 'webmock/rspec'
|
14
|
+
|
15
|
+
require 'pushover'
|
16
|
+
|
17
|
+
include Pushover
|
18
|
+
|
7
19
|
RSpec.configure do |config|
|
8
20
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
21
|
config.run_all_when_everything_filtered = true
|
10
22
|
config.filter_run :focus
|
11
|
-
|
12
|
-
# Run specs in random order to surface order dependencies. If you find an
|
13
|
-
# order dependency and want to debug it, you can fix the order by providing
|
14
|
-
# the seed, which is printed after each run.
|
15
|
-
# --seed 1234
|
16
23
|
config.order = 'random'
|
17
24
|
end
|
25
|
+
|
26
|
+
def setup_webmocks
|
27
|
+
WebMock.reset!
|
28
|
+
good_result = '{"status":1}'
|
29
|
+
bad_token = '{"token":"invalid","errors":["application token is invalid"],"status":0}'
|
30
|
+
bad_user = '{"user":"invalid","errors":["user identifier is invalid"],"status":0}'
|
31
|
+
|
32
|
+
stub_http_request(:post, "https://api.pushover.net/1/messages.json").to_return(:status => 200,
|
33
|
+
:headers => {}, :body => good_result).with(:body => hash_including({token:'good_token', user:'good_user'}))
|
34
|
+
stub_http_request(:post, "https://api.pushover.net/1/messages.json").to_return(:status => 200,
|
35
|
+
:headers => {}, :body => bad_token).with(:body => hash_including({token:'bad_token', user:'good_user'}))
|
36
|
+
stub_http_request(:post, "https://api.pushover.net/1/messages.json").to_return(:status => 200,
|
37
|
+
:headers => {}, :body => bad_user).with(:body => hash_including({token:'good_token', user:'bad_user'}))
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
data/whatsnew.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
0.5.1:
|
2
|
+
* SimpleCov and 100% test coverage
|
3
|
+
* Webmock based testing for Pushover#notification.
|
4
|
+
* Added intergration to http://travis-ci.org
|
5
|
+
|
1
6
|
0.5.0:
|
2
7
|
* Switched the order of App and it's derivatives so that it's name, api_key to make it more human readable.
|
3
8
|
* Ditto for User.
|
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.5.
|
4
|
+
version: 0.5.1
|
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-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
@@ -52,16 +52,15 @@ extensions: []
|
|
52
52
|
extra_rdoc_files:
|
53
53
|
- README.md
|
54
54
|
- whatsnew.md
|
55
|
-
- dev_notes.md
|
56
55
|
files:
|
57
56
|
- .gitignore
|
57
|
+
- .travis.yml
|
58
58
|
- Gemfile
|
59
59
|
- Guardfile
|
60
60
|
- LICENSE
|
61
61
|
- README.md
|
62
62
|
- Rakefile
|
63
63
|
- bin/pushover
|
64
|
-
- dev_notes.md
|
65
64
|
- lib/pushover.rb
|
66
65
|
- lib/pushover/app.rb
|
67
66
|
- lib/pushover/user.rb
|
data/dev_notes.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
* the file spec/test_config is ignored intentionally, you can load your personal pushover details into this file for running specs successfully.
|