guard-pushover 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - 2.0.0
6
+ branches:
7
+ only:
8
+ - master
9
+ script: rspec spec
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-pushover.gemspec
4
+ gemspec
5
+ gem 'rb-inotify', '~> 0.9', :require => false
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/guard/(.+)\.rb$}) { |m| "spec/guard/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 jonnev
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,40 @@
1
+ [![Build Status](https://travis-ci.org/joenas/preek.png)](https://travis-ci.org/joenas/guard-pushover)
2
+ [![Coverage Status](https://coveralls.io/repos/joenas/guard-pushover/badge.png?branch=master)](https://coveralls.io/r/joenas/guard-pushover)
3
+
4
+
5
+ # Guard::Pushover
6
+
7
+ Send [Pushover](https://pushover.net/) notifications with Guard!
8
+
9
+ ## Installation
10
+
11
+ Install it yourself as:
12
+
13
+ $ git clone git@github.com:joenas/preek.git
14
+
15
+ $ cd preek
16
+
17
+ $ rake install
18
+
19
+ Gem will be available soon.
20
+
21
+ ## Usage
22
+
23
+ To generate template: `guard init pushover`
24
+
25
+ ### Example
26
+
27
+ guard :pushover, :api_key => '', :user_key => '' do
28
+ watch(/lib\/(.*).rb/)
29
+ end
30
+
31
+ Guard::Pushover will send a message like "[filename] was changed/removed/added".
32
+ Support will be added for custom messages.
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/pushover/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "guard-pushover"
8
+ spec.version = Guard::PushoverVersion::VERSION
9
+ spec.authors = ["Jon Neverland"]
10
+ spec.email = ["jonwestin@gmail.com"]
11
+ spec.description = %q{Let Guard send Pushover notifications}
12
+ spec.summary = %q{}
13
+ spec.homepage = "https://github.com/joenas/guard-pushover/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rushover", ">= 0.3.0"
22
+ spec.add_dependency "guard", '>= 1.6'
23
+ spec.add_development_dependency "guard"
24
+ spec.add_development_dependency "guard-rspec"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency 'coveralls'
27
+ end
@@ -0,0 +1,7 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :pushover, :api_key => '', :user_key => '' do
5
+ watch(/lib\/(.*).rb/)
6
+ end
7
+
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module PushoverVersion
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,63 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/watcher'
4
+ require 'rushover'
5
+
6
+ module Guard
7
+ # Send notifications to Pushover
8
+ class Pushover < Guard
9
+
10
+ DEFAULTS = {
11
+ :title => 'Guard',
12
+ :priority => 0
13
+ }
14
+
15
+ def initialize(watchers = [], options = {})
16
+ options = DEFAULTS.merge(options)
17
+ @user_key = options.delete(:user_key)
18
+ @api_key = options.delete(:api_key)
19
+ super
20
+ end
21
+
22
+ def run_on_changes(paths)
23
+ send_notification "#{paths.first} was changed."
24
+ end
25
+
26
+ def run_on_removals(paths)
27
+ send_notification "#{paths.first} was removed."
28
+ end
29
+
30
+ def run_on_additions(paths)
31
+ send_notification "#{paths.first} was added."
32
+ end
33
+
34
+ private
35
+
36
+ def client
37
+ @client = options.delete(:client) || Rushover::Client.new(@api_key)
38
+ end
39
+
40
+ def send_notification(msg)
41
+ return unless api_keys_valid?
42
+ @resp = client.notify(@user_key, msg, options)
43
+ if @resp.ok?
44
+ UI.info "Pushover: message sent"
45
+ else
46
+ handle_error
47
+ end
48
+ end
49
+
50
+ def api_keys_valid?
51
+ return UI.error "No API key given." unless @api_key
52
+ return UI.error "No User key given." unless @user_key
53
+ true
54
+ end
55
+
56
+ def handle_error
57
+ if @resp[:user] == 'invalid' || @resp[:token] == 'invalid'
58
+ append = ', check API and User key'
59
+ end
60
+ UI.error "#{@resp[:errors].join()}#{append}"
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Pushover do
4
+
5
+ subject{Guard::Pushover.new([], options)}
6
+ let(:options){ {:user_key => user_key, :api_key => api_key} }
7
+ let(:paths){ ['file.rb'] }
8
+ let(:user_key){ 'user' }
9
+ let(:api_key){ 'api' }
10
+ let(:client){double('client', :notify => response)}
11
+ let(:response){double('response', :ok? => true)}
12
+ let(:options) { {:user_key => user_key, :api_key => api_key, :client => client} }
13
+ let(:expected_options){ { :title => 'Guard', :priority => 0 } }
14
+
15
+ context "with valid options and credentials" do
16
+ it "#run_on_removals sends a notification to client with correct parameters" do
17
+ message = "#{paths.first} was removed."
18
+ client.should_receive(:notify).with(user_key, message, expected_options)
19
+ Guard::UI.should_receive(:info).with(/Pushover: message sent/)
20
+ subject.run_on_removals(paths)
21
+ end
22
+
23
+ it "#run_on_additions_sends a notification to client with correct parameters" do
24
+ message = "#{paths.first} was added."
25
+ client.should_receive(:notify).with(user_key, message, expected_options)
26
+ Guard::UI.should_receive(:info).with(/Pushover: message sent/)
27
+ subject.run_on_additions(paths)
28
+ end
29
+ end
30
+
31
+ describe "#run_on_changes" do
32
+ let(:run_on_changes){subject.run_on_changes(paths)}
33
+
34
+ context "without api_key" do
35
+ let(:api_key){nil}
36
+ it "shows error message 'No API key given'" do
37
+ Guard::UI.should_receive(:error).with(/No API key given/)
38
+ run_on_changes
39
+ end
40
+ end
41
+
42
+ context "without user_key" do
43
+ let(:user_key) { nil }
44
+ it "shows error message 'No User key given'" do
45
+ Guard::UI.should_receive(:error).with(/No User key given/)
46
+ run_on_changes
47
+ end
48
+ end
49
+
50
+ context "with correct options" do
51
+ let(:message) { "#{paths.first} was changed." }
52
+
53
+ context "and valid credentials" do
54
+ it "shows an info message 'Pushover: message sent'" do
55
+ Guard::UI.should_receive(:info).with(/Pushover: message sent/)
56
+ run_on_changes
57
+ end
58
+
59
+ context "with default options" do
60
+ it "sends a notification to client with correct parameters" do
61
+ client.should_receive(:notify).with(user_key, message, expected_options)
62
+ Guard::UI.should_receive(:info).with(/Pushover: message sent/)
63
+ run_on_changes
64
+ end
65
+ end
66
+
67
+ context "with option :title => 'TITLE'" do
68
+ let(:expected_options){ { :title => 'TITLE', :priority => 0 } }
69
+ it "sends a notification to client with correct parameters" do
70
+ options[:title] = 'TITLE'
71
+ client.should_receive(:notify).with(user_key, message, expected_options)
72
+ Guard::UI.should_receive(:info).with(/Pushover: message sent/)
73
+ run_on_changes
74
+ end
75
+ end
76
+
77
+ context "with option :priority => 1" do
78
+ let(:expected_options){ { :title => 'Guard', :priority => 1 } }
79
+ it "sends a notification to client with correct parameters" do
80
+ options[:priority] = 1
81
+ client.should_receive(:notify).with(user_key, message, expected_options)
82
+ Guard::UI.should_receive(:info).with(/Pushover: message sent/)
83
+ run_on_changes
84
+ end
85
+ end
86
+ end
87
+
88
+ context "and invalid credentials" do
89
+ let(:response){double('response', :ok? => false)}
90
+
91
+ context "for 'user' key" do
92
+ it "shows error message 'user identifier is invalid'" do
93
+ response.stub(:[]).with(:user).and_return('invalid')
94
+ response.stub(:[]).with(:errors).and_return(['user identifier is invalid'])
95
+ Guard::UI.should_receive(:error).with(/user identifier is invalid/)
96
+ run_on_changes
97
+ end
98
+ end
99
+
100
+ context "for 'token' key" do
101
+ it "shows error message 'user identifier is invalid'" do
102
+ response.stub(:[]).with(:user).and_return(true)
103
+ response.stub(:[]).with(:token).and_return('invalid')
104
+ response.stub(:[]).with(:errors).and_return(['application token is invalid'])
105
+ Guard::UI.should_receive(:error).with(/application token is invalid/)
106
+ run_on_changes
107
+ end
108
+ end
109
+
110
+ context "for custom error" do
111
+ it "shows the error message from client " do
112
+ response.stub(:[]).with(:user).and_return(true)
113
+ response.stub(:[]).with(:token).and_return(true)
114
+ response.stub(:[]).with(:errors).and_return(['some random error'])
115
+ Guard::UI.should_receive(:error).with(/some random error/)
116
+ run_on_changes
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,26 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'coveralls'
9
+ Coveralls.wear!
10
+
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ require 'rspec'
14
+ require 'guard/pushover'
15
+
16
+ RSpec.configure do |config|
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.run_all_when_everything_filtered = true
19
+ config.filter_run :focus
20
+
21
+ # Run specs in random order to surface order dependencies. If you find an
22
+ # order dependency and want to debug it, you can fix the order by providing
23
+ # the seed, which is printed after each run.
24
+ # --seed 1234
25
+ config.order = 'random'
26
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-pushover
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Neverland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rushover
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '1.6'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '1.6'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: coveralls
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Let Guard send Pushover notifications
111
+ email:
112
+ - jonwestin@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .travis.yml
120
+ - Gemfile
121
+ - Guardfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - guard-pushover.gemspec
126
+ - lib/guard/pushover.rb
127
+ - lib/guard/pushover/templates/Guardfile
128
+ - lib/guard/pushover/version.rb
129
+ - spec/guard/pushover_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: https://github.com/joenas/guard-pushover/
132
+ licenses:
133
+ - MIT
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.24
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: ''
156
+ test_files:
157
+ - spec/guard/pushover_spec.rb
158
+ - spec/spec_helper.rb
159
+ has_rdoc: