pushover 0.4.0 → 0.5.0

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/Gemfile CHANGED
@@ -1,4 +1,24 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in pushover.gemspec
4
3
  gemspec
4
+
5
+ group :development do
6
+ gem "pry"
7
+ gem "pry-debugger"
8
+ gem "redcarpet"
9
+ gem "guard"
10
+ gem "guard-bundler"
11
+ gem "guard-rspec"
12
+ gem "guard-yard"
13
+ gem "guard-shell"
14
+ gem 'libnotify', :require => false
15
+ gem 'growl', :require => false
16
+ gem 'rb-inotify', :require => false
17
+ gem 'rb-fsevent', :require => false
18
+ gem 'rb-fchange', :require => false
19
+ end
20
+
21
+ group :test do
22
+ gem "rspec"
23
+ gem "rake"
24
+ end
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby
2
+ # A sample Guardfile
3
+ # More info at https://github.com/guard/guard#readme
4
+
5
+ guard :bundler do
6
+ watch 'Gemfile'
7
+ watch '*.gemspec'
8
+ end
9
+
10
+ guard :rspec do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec spec/lib/#{m[1]}_spec.rb" }
13
+ watch(%r{^bin/(.+)\.rb$}) { |m| "spec/bin/#{m[1]}_spec.rb" }
14
+ watch('spec/spec_helper.rb') { "spec" }
15
+ end
16
+
17
+ # guard :yard do
18
+ # watch(%r{^lib/(.+)\.rb$})
19
+ # end
data/LICENSE CHANGED
@@ -1,22 +1,36 @@
1
- Copyright (c) 2012 Ernie Brodeur
1
+ All software in this package is covered by the MIT license and beerware (rev42).
2
2
 
3
- MIT License
3
+ Copyright (c) 2011 Ernie Brodeur
4
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:
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the "Software"), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
12
13
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
15
16
 
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.
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ /*
27
+ * ----------------------------------------------------------------------------
28
+ * "THE BEER-WARE LICENSE" (Revision 42):
29
+ * Ernie Brodeur wrote this package. As long as you retain this notice you
30
+ * can do whatever you want with this stuff. If we meet some day, and you think
31
+ * this stuff is worth it, you can buy me a beer in return.
32
+ * ----------------------------------------------------------------------------
33
+ */
34
+
35
+ All contributed code is licensed accordingly and accredited whenever possible.
36
+ If I make any mistake about this, please feel free to contact me at ebrodeur@ujami.net.
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
- #!/usr/bin/env rake
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
6
+
2
7
  require "bundler/gem_tasks"
data/bin/pushover CHANGED
@@ -2,7 +2,17 @@
2
2
 
3
3
  require 'pushover'
4
4
 
5
+ include Bini
5
6
  include Pushover
7
+ Options.on("-u", "--user USER", "Which user, can be a saved name or token.") { |o| Options[:user] = o}
8
+ Options.on("-a", "--app APPKEY", "Which app to notify, can be a saved name or apikey.") { |o| Options[:appkey] = o}
9
+ Options.on("-t", "--title [TITLE]", "Set the title of the notification (optional).") { |o| Options[:title] = o}
10
+ Options.on("-p", "--priority [PRIORITY]", OptionParser::DecimalInteger , "Set the priority of the notification from -1 to 1 (optional).") { |o| Options[:priority] = o}
11
+ Options.on("-d", "--device [DEVICE]", "Specify the device to send the notifcation to. (optional).") { |o| Options[:device] = o}
12
+ Options.on("-c", "--config_file [FILE]", "Set the target config file.") {|o| Options[:config_file] = o}
13
+ Options.on("--save-app NAME", "Saves the application to the config file under NAME.") { |o| Options[:save_app] = [Options[:appkey], o]}
14
+ Options.on("--save-user NAME", "Saves the user to the config file under NAME.") { |o| Options[:save_user] = [Options[:user], o]}
15
+
6
16
  Options.parse!
7
17
 
8
18
  # Order is important.
@@ -13,14 +23,14 @@ end
13
23
 
14
24
  if Options[:save_app]
15
25
  puts "Saving application #{Options[:save_app][0]} to #{Options[:save_app][1]}."
16
- App.add Options[:save_app][0], Options[:save_app][1]
26
+ App.add Options[:save_app][1], Options[:save_app][0]
17
27
  puts "Save successful."
18
28
  exit
19
29
  end
20
30
 
21
31
  if Options[:save_user]
22
32
  puts "Saving user #{Options[:save_user][0]} to #{Options[:save_user][1]}."
23
- User.add Options[:save_user][0], Options[:save_user][1]
33
+ User.add Options[:save_user][1], Options[:save_user][0]
24
34
  puts "Save successful."
25
35
  exit
26
36
  end
@@ -48,16 +58,16 @@ if !User.current_user?
48
58
  end
49
59
  exit if bail
50
60
 
61
+ # I do both just as an example, you can configure it this way and have it
62
+ # pre-configured:
51
63
  Pushover.configure do |c|
52
64
  c.user = User.current_user
53
65
  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
66
  end
59
67
 
60
- response = Pushover.notification
68
+ # Or in real time, which will also overwrite the .configure block.
69
+ response = Pushover.notification message:message, title:Options[:title],
70
+ priority:Options[:priority], device:Options[:device]
61
71
 
62
72
  if response.code == "200"
63
73
  puts "Message sent successfully!"
@@ -65,3 +75,4 @@ else
65
75
  j = Yajl.load response.body
66
76
  puts "ErrorCode (#{response.code}): #{j['errors'].first}."
67
77
  end
78
+
data/lib/pushover.rb CHANGED
@@ -1,14 +1,17 @@
1
1
  require "net/https"
2
2
  require "yajl"
3
+ require 'bini'
4
+ require 'bini/config'
5
+ require 'bini/optparser'
3
6
 
4
7
  require "pushover/version"
5
8
  require "pushover/app"
6
9
  require "pushover/user"
7
- require "pushover/config"
8
- require "pushover/optparser"
9
-
10
10
  # The primary pushover namespace.
11
11
  module Pushover
12
+ # lets save our config to it's own dir, just because.
13
+ Bini.config.file = "#{Dir.home}/.config/pushover/credentials.yaml"
14
+ Bini.config.load
12
15
 
13
16
  extend self
14
17
 
data/lib/pushover/app.rb CHANGED
@@ -10,14 +10,14 @@ module Pushover
10
10
  attr_accessor :name
11
11
  attr_accessor :api_key
12
12
 
13
- def initialize(api_key, name)
13
+ def initialize(name, api_key)
14
14
  @name = name
15
15
  @api_key = api_key
16
- Config[:applications] = {} if !Config[:applications]
16
+ Bini.config[:applications] = {} if !Bini.config[:applications]
17
17
  if name
18
- Config[:applications][name] = api_key
18
+ Bini.config[:applications][name] = api_key
19
19
  else
20
- Config[:applications][api_key] = api_key
20
+ Bini.config[:applications][api_key] = api_key
21
21
  end
22
22
  end
23
23
  end
@@ -28,7 +28,7 @@ module Pushover
28
28
  # @param [String] word the search token, can be an apikey or appname.
29
29
  # @return [String] return the apikey (if it can find one) or the word itself.
30
30
  def find(word)
31
- return Config[:applications][word] if Config[:applications][word]
31
+ return Bini.config[:applications][word] if Bini.config[:applications][word]
32
32
  word
33
33
  end
34
34
 
@@ -36,23 +36,26 @@ module Pushover
36
36
  # @param [String] api_key is the api_key to be used.
37
37
  # @param [String] name is the short name that can be referenced later.
38
38
  # @return [Boolean] return the results of the save attempt.
39
- def add(api_key, name)
40
- App.new api_key, name
41
- Pushover::Config.save!
39
+ def add(name, api_key)
40
+ App.new name, api_key
41
+ Bini.config.save!
42
42
  end
43
43
 
44
+ def remove(name)
45
+ Bini.config[:applications].delete name if Bini.config[:applications]
46
+ end
44
47
  # Return the current app selected, or the first one saved.
45
48
  def current_app
46
49
  return @current_app if @current_app
47
50
 
48
51
  # did something get supplied on the cli? try to find it.
49
52
  if Options[:appkey]
50
- @current_app = Pushover::App.find Options[:appkey]
53
+ @current_app = find Options[:appkey]
51
54
  end
52
55
 
53
56
  # no? do we have anything we can return?
54
57
  if !@current_app
55
- @current_app = Config[:applications].first
58
+ @current_app = find Bini.config[:applications].first[0]
56
59
  end
57
60
  @current_app
58
61
  end
data/lib/pushover/user.rb CHANGED
@@ -10,22 +10,22 @@ module Pushover
10
10
  attr_accessor :name
11
11
  attr_accessor :token
12
12
 
13
- def initialize(token, name)
13
+ def initialize(name, token)
14
14
  @name = name
15
15
  @token = token
16
- Config[:users] = {} if !Config[:users]
17
- Config[:users][name] = token
16
+ Bini.config[:users] = {} if !Bini.config[:users]
17
+ Bini.config[:users][name] = token
18
18
  end
19
19
 
20
20
  end
21
21
 
22
22
  extend self
23
23
 
24
- # Find the apikey in the applications, or pass on the word to try direct access.
24
+ # Find the token in the users, or pass on the word to try direct access.
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 Config[:users][word] if Config[:users][word]
28
+ return Bini.config[:users][word] if Bini.config[:users][word]
29
29
  word
30
30
  end
31
31
 
@@ -33,9 +33,13 @@ module Pushover
33
33
  # @param [String] token is the token to be used.
34
34
  # @param [String] name is the short name that can be referenced later.
35
35
  # @return [Boolean] return the results of the save attempt.
36
- def add(token, name)
37
- User.new token, name
38
- Pushover::Config.save!
36
+ def add(name, token)
37
+ User.new name, token
38
+ Bini.config.save!
39
+ end
40
+
41
+ def remove(name)
42
+ Bini.config[:users].delete name if Bini.config[:users]
39
43
  end
40
44
 
41
45
  # Return the current user selected, or the first one saved.
@@ -44,12 +48,12 @@ module Pushover
44
48
 
45
49
  # did something get supplied on the cli? try to find it.
46
50
  if Options[:user]
47
- @current_user = Pushover::User.find Options[:user]
51
+ @current_user = find Options[:user]
48
52
  end
49
53
 
50
54
  # no? do we have anything we can return?
51
55
  if !@current_user
52
- @current_user = Config[:users].first
56
+ @current_user = find Bini.config[:users].first[0]
53
57
  end
54
58
  @current_user
55
59
  end
@@ -1,4 +1,4 @@
1
1
  module Pushover
2
2
  # The current version of Pushover.
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
data/pushover.gemspec CHANGED
@@ -26,6 +26,6 @@ Gem::Specification.new do |gem|
26
26
  gem.has_rdoc = 'yard'
27
27
 
28
28
  # dependencies.
29
- gem.add_development_dependency('pry')
30
- gem.add_runtime_dependency('yajl-ruby')
29
+ gem.add_runtime_dependency 'yajl-ruby'
30
+ gem.add_runtime_dependency 'bini'
31
31
  end
@@ -0,0 +1,42 @@
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
+
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
+ # end
42
+
@@ -0,0 +1,26 @@
1
+ require 'pushover'
2
+
3
+ include Pushover
4
+
5
+ describe "application" do
6
+ before(:each) do
7
+ Bini.config.file = "tmp/test.save"
8
+ Bini.config.clear
9
+ end
10
+
11
+ it "can add a application to the Config[:application] hash." do
12
+ App.add "foo", "bar"
13
+ Bini.config[:applications]["foo"].should eq("bar")
14
+ end
15
+
16
+ it "can remove a application from the hash." do
17
+ App.add "foo", "bar"
18
+ App.remove "foo"
19
+ Bini.config[:applications]["foo"].should be_nil
20
+ end
21
+
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
+ end
@@ -0,0 +1,28 @@
1
+ require 'pushover'
2
+
3
+ include Pushover
4
+
5
+ describe "user" do
6
+ before(:each) do
7
+ Bini.config.file = "tmp/test.save"
8
+ Bini.config.clear
9
+ end
10
+
11
+ it "can add a user to the Config[:application] hash." do
12
+ User.add "foo", "bar"
13
+ Bini.config[:users]["foo"].should eq("bar")
14
+ end
15
+
16
+ it "can remove a user from the hash." do
17
+ User.add "foo", "bar"
18
+ User.remove "foo"
19
+ Bini.config[:users]["foo"].should be_nil
20
+ end
21
+
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
+ end
27
+
28
+
data/whatsnew.md CHANGED
@@ -1,7 +1,11 @@
1
- Unreleased:
1
+ 0.5.0:
2
+ * Switched the order of App and it's derivatives so that it's name, api_key to make it more human readable.
3
+ * Ditto for User.
4
+ * Merged in me bones.
5
+ * Using bini's logic whenever possible now instead of reinventing the wheel.
6
+ 0.4.0:
2
7
  * Added priority and device specification.
3
8
  * Moved all the variables, including message, into the configure block.
4
- * Documentation push, 100% passage and updated for yardoc.
5
9
  * Updated the gemspec with some more information.
6
10
  * Better output for error messages.
7
11
  0.3.1
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.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,17 +9,17 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-28 00:00:00.000000000 Z
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: pry
15
+ name: yajl-ruby
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :development
22
+ type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: yajl-ruby
31
+ name: bini
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -56,6 +56,7 @@ extra_rdoc_files:
56
56
  files:
57
57
  - .gitignore
58
58
  - Gemfile
59
+ - Guardfile
59
60
  - LICENSE
60
61
  - README.md
61
62
  - Rakefile
@@ -63,18 +64,14 @@ files:
63
64
  - dev_notes.md
64
65
  - lib/pushover.rb
65
66
  - lib/pushover/app.rb
66
- - lib/pushover/config.rb
67
- - lib/pushover/optparser.rb
68
67
  - lib/pushover/user.rb
69
68
  - lib/pushover/version.rb
70
69
  - pushover.gemspec
71
- - spec/app_spec.rb
72
- - spec/cli_spec.rb
73
- - spec/config_spec.rb
74
- - spec/optparser_spec.rb
75
- - spec/pushover_spec.rb
70
+ - spec/bin/pushover_spec.rb
71
+ - spec/lib/pushover/app_spec.rb
72
+ - spec/lib/pushover/pushover_spec.rb
73
+ - spec/lib/pushover/user_spec.rb
76
74
  - spec/spec_helper.rb
77
- - spec/user_spec.rb
78
75
  - whatsnew.md
79
76
  homepage: https://github.com/erniebrodeur/pushover
80
77
  licenses: []
@@ -108,11 +105,9 @@ signing_key:
108
105
  specification_version: 3
109
106
  summary: This gem will provide both an API and CLI interface to pushover.net.
110
107
  test_files:
111
- - spec/app_spec.rb
112
- - spec/cli_spec.rb
113
- - spec/config_spec.rb
114
- - spec/optparser_spec.rb
115
- - spec/pushover_spec.rb
108
+ - spec/bin/pushover_spec.rb
109
+ - spec/lib/pushover/app_spec.rb
110
+ - spec/lib/pushover/pushover_spec.rb
111
+ - spec/lib/pushover/user_spec.rb
116
112
  - spec/spec_helper.rb
117
- - spec/user_spec.rb
118
113
  has_rdoc: yard
@@ -1,62 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Pushover
4
- # This is an extended [Hash] that adds some saving features via yajl.
5
- class ConfigBlob < Hash
6
- attr_accessor :save_file
7
-
8
- # @return [String] the dirname of the save file.
9
- def save_dir
10
- File.dirname @save_file
11
- end
12
-
13
- def initialize(load = true)
14
- @save_file = "#{Dir.home}/.config/pushover/config.json"
15
-
16
- self.load if load
17
- end
18
-
19
- # Clear the config file (not implemented)
20
- def clear
21
- end
22
-
23
- # Save the config, will raise an exception if the file exists.
24
- def save
25
- FileUtils.mkdir_p save_dir if !Dir.exist? save_dir
26
- if any?
27
- # I do this the long way because I want an immediate sync.
28
- f = open(@save_file, 'w')
29
- f.write Yajl.dump self
30
- f.sync
31
- f.close
32
- end
33
- end
34
-
35
- # Backup our save file, will remove original in the process.
36
- def backupSave
37
- FileUtils.mv @save_file, "#{@save_file}.bak" if File.file? @save_file
38
- end
39
-
40
- # Save the config, removing the existing one if necessary.
41
- def save!(backup = true)
42
- if backup
43
- backupSave
44
- else
45
- FileUtils.rm @save_file if File.file? @save_file
46
- end
47
-
48
- save
49
- end
50
-
51
- # Load the config file if it is available.
52
- def load
53
- if File.exist?(@save_file) && File.stat(@save_file).size > 0
54
- h = Yajl.load open(@save_file, 'r').read
55
- h.each { |k,v| self[k.to_sym] = v}
56
- end
57
- end
58
- end
59
-
60
- # A convenience instance of config, provides Pushover.Config.
61
- Config = ConfigBlob.new
62
- end
@@ -1,71 +0,0 @@
1
- require 'optparse'
2
-
3
- module Pushover
4
- # override the built-in [OptionParser], adding some nifty features.
5
- # Options[] is a hash value designed to collect the contents added to @options.
6
-
7
- class OptionParser < ::OptionParser
8
- def initialize
9
- super
10
- @options = {}
11
-
12
- on("-V", "--version", "Print version") { |version| @options[:version] = true}
13
- on("-u", "--user USER", "Which user, can be a saved name or token.") { |o| @options[:user] = o}
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}
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}
18
- on("-c", "--config_file [FILE]", "Set the target config file.") {|o| @options[:config_file] = o}
19
- on("--save-app NAME", "Saves the application to the config file under NAME.") { |o| @options[:save_app] = [@options[:appkey], o]}
20
- on("--save-user NAME", "Saves the user to the config file under NAME.") { |o| @options[:save_user] = [@options[:user], o]}
21
- end
22
-
23
- # This will build an on/off option with a default value set to false.
24
- def bool_on(word, description = "")
25
- Options[word.to_sym] = false
26
- on "-#{word.chars.first}", "--[no]#{word}", description do |o|
27
- Options[word.to_sym] == o
28
- end
29
- end
30
-
31
- # Build out the banner and calls the built in parse!
32
- # Loads any saved options automatically.
33
- def parse!
34
- @banner = "Send notifications over to pushover.net.\n\n"
35
- super
36
-
37
- if @options[:version]
38
- puts Pushover::VERSION
39
- exit 0
40
- end
41
-
42
- # we need to mash in our config array. To do this we want to make config
43
- # options that don't overwrite cli options.
44
- Config.each do |k,v|
45
- @options[k] = v if !@options[k] && ["applications", "users"].include?(k)
46
- end
47
- end
48
-
49
- # Entry point to the options hash
50
- # @return will return the value of key if provided, else the entire [Hash]
51
- def [](k = nil)
52
- return @options[k] if k
53
- return @options if @options.any?
54
- nil
55
- end
56
-
57
- # Set a value in the option array, used as a way to store the results of the parsed value.
58
- def []=(k,v)
59
- @options[k] = v
60
- end
61
-
62
- # Check to see if the option hash has any k/v pairs.
63
- # @return [Boolean] true if any pairs at all, false otherwise.
64
- def empty?
65
- @options.empty?
66
- end
67
- end
68
-
69
- # Add a built in Options to the Pushover namespace, purely a convenience thing.
70
- Options = OptionParser.new
71
- end
data/spec/app_spec.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'pushover'
2
-
3
- describe "application" do
4
- before(:each) do
5
- Pushover::Config.save_file = "test.save"
6
- Pushover::Config.clear
7
- end
8
-
9
- it "can add a application to the Config[:application] hash." do
10
- Pushover::App.add "bar", "foo"
11
- Pushover::Config[:applications]["foo"].should eq("bar")
12
- end
13
-
14
- it "can remove a application from the hash."
15
- it "can find the apikey from the name" do
16
- Pushover::App.add "bar", "foo"
17
- Pushover::App.find("foo").should eq("bar")
18
- end
19
- end
data/spec/cli_spec.rb DELETED
@@ -1,42 +0,0 @@
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
-
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
- end
42
-
data/spec/config_spec.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'pushover'
2
-
3
- describe "Config" do
4
- before(:all) do
5
- Pushover::Config.save_file = "config_spec.tmp"
6
- Pushover::Config.clear
7
- Pushover::Config[:test] = true
8
- Pushover::Config.save!
9
- end
10
-
11
- it "should exist" do
12
- expect { Pushover::Config }.to_not be(nil)
13
- end
14
-
15
- it "should have a save_file" do
16
- Pushover::Config.save_file.should eq("config_spec.tmp")
17
- end
18
-
19
- it "save_dir should be the basename of save_file" do
20
- Pushover::Config.save_dir.should eq(File.dirname Pushover::Config.save_file)
21
- end
22
-
23
- it "should save if not empty"
24
- it "should make a backup"
25
- it "should load" do
26
- Pushover::Config.load
27
- Pushover::Config[:test].should eq(true)
28
- end
29
- end
File without changes
data/spec/user_spec.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'pushover'
2
-
3
- describe "user" do
4
- before(:each) do
5
- Pushover::Config.save_file = "test.save"
6
- Pushover::Config.clear
7
- end
8
-
9
- it "can add a user to the Config[:application] hash." do
10
- Pushover::User.add "bar", "foo"
11
- Pushover::Config[:users]["foo"].should eq("bar")
12
- end
13
-
14
- it "can remove a user from the hash."
15
- it "can find the token from the name" do
16
- Pushover::User.add "bar", "foo"
17
- Pushover::User.find("foo").should eq("bar")
18
- end
19
- end
20
-
21
-