ruby-notify-my-android 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,22 +4,40 @@ Send notifications to Android devices via the Notify My Android API. Details abo
4
4
 
5
5
  == Installation
6
6
 
7
- gem install ruby-notify-my-android
7
+ gem install ruby-notify-my-android
8
+
9
+ == Usage from command line
10
+
11
+ You can send notifications from the command line with the notify-my-android script:
12
+
13
+ $ notify-my-android -k 9d0538ab7b52360e906e0e766f34501b69edde92fe3409e9
14
+ Notification sent !
15
+
16
+ Here are the full set of parameters that it accepts:
17
+
18
+ Usage: notify-my-android [options]
19
+ -k, --apikey APIKEY Your API Key
20
+ -p, --priority PRIORITY Priority (-2,-1,0,1,2)
21
+ -a, --application APPNAME Name of app
22
+ -e, --event EVENTNAME Name of event
23
+ -d, --description DESCRIPTION Notify text
24
+
25
+ Any parameters unset will use default values except --apikey
8
26
 
9
27
  == Usage as a Gem
10
28
 
11
29
  Sending a notification via ruby-notify-my-android gem
12
30
 
31
+ require 'rubygems'
13
32
  require 'ruby-notify-my-android'
14
33
 
15
- NMA.notify do |n|
16
- n.apikey = "9d1538ab7b52360e906e0e766f34501b69edde92fe3409e9" # can also be list such as ["key1", "key2"]
17
- n.priority = NMA::Priority::MODERATE
18
- n.application = "NMA"
19
- n.event = "Notification"
20
- n.description = "Your server is under attack!!!"
21
- n.url = "http://www.nma.bz"
22
- end
34
+ NMA.notify do |n|
35
+ n.apikey = "9d1538ab7b52360e906e0e766f34501b69edde92fe3409e9" # can also be list such as ["key1", "key2"]
36
+ n.priority = NMA::Priority::MODERATE
37
+ n.application = "NMA"
38
+ n.event = "Notification"
39
+ n.description = "Your server is under attack!!!"
40
+ end
23
41
 
24
42
  == Using the API
25
43
 
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.description = %Q{Send notifications to Android devices via the Notify My Android API. Details about the API are available at https://nma.usk.bz/api.php .}
20
20
  gem.email = "ken.pepple@rabbityard.com"
21
21
  gem.authors = ["Ken Pepple"]
22
- # gem.executables = [ 'notify-my-android' ]
22
+ gem.executables = [ 'notify-my-android' ]
23
23
  # gem.add_runtime_dependency "xml-simple", ">= 1.0.15"
24
24
  # gem.add_development_dependency 'webmock'
25
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "rubygems"
5
+ require "ruby-notify-my-android"
6
+ require "optparse"
7
+ rescue LoadError
8
+ STDERR.puts "The ruby gems ruby-notify-my-android and optparse are required."
9
+ STDERR.puts "Please install them via gem install ruby-notify-my-android."
10
+ exit 1
11
+ end
12
+
13
+
14
+ # parse options
15
+ o = {}
16
+ opts = OptionParser.new
17
+ opts.on("-k", "--apikey APIKEY", "Your API Key", String) {|val| o[:apikey] = val }
18
+ opts.on("-p", "--priority PRIORITY", "Priority (-2,-1,0,1,2)", Integer) {|val| o[:priority] = val }
19
+ opts.on("-a", "--application APPNAME", "Name of app", String) {|val| o[:application] = val }
20
+ opts.on("-e", "--event EVENTNAME", "Name of event", String) {|val| o[:event] = val }
21
+ opts.on("-d", "--description DESCRIPTION", "Notify text", String) {|val| o[:priority] = val }
22
+ z = opts.parse(ARGV)
23
+
24
+ # set defaults
25
+ options = { :apikey => o[:apikey] || nil,
26
+ :description => o[:description] || nil,
27
+ :event => o[:event] || nil,
28
+ :application => o[:application] || nil,
29
+ :priority => o[:priority] || nil }
30
+
31
+ # send notification
32
+ unless options[:apikey].nil?
33
+ result = NMA.notify do |n|
34
+ n.apikey = options[:apikey]
35
+ n.priority = options[:priority] unless options[:priority].nil?
36
+ n.application = options[:application] unless options[:application].nil?
37
+ n.event = options[:event] unless options[:event].nil?
38
+ n.description = options[:description] unless options[:description].nil?
39
+ end
40
+ else
41
+ puts opts.to_s
42
+ exit 2
43
+ end
44
+
45
+ if result.succeeded?
46
+ puts "Notification sent !"
47
+ exit 0
48
+ else
49
+ puts "Error in notification: #{result.response["content"]}"
50
+ exit 3
51
+ end
@@ -5,9 +5,9 @@ require 'ruby-notify-my-android/notification'
5
5
  # This is the main Notify My Andoid module
6
6
 
7
7
  module NMA
8
-
8
+
9
9
  extend self
10
-
10
+
11
11
  def notify(notification = Notification.new)
12
12
  yield notification if block_given?
13
13
  Request.instance.call Request::Command::NOTIFY, notification.to_params
@@ -31,5 +31,7 @@ module NMA
31
31
  def version
32
32
  File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION]))
33
33
  end
34
+
35
+ VERSION = self.version
34
36
 
35
37
  end
@@ -1,5 +1,10 @@
1
- require 'rubygems'
2
- require 'xmlsimple'
1
+ begin
2
+ require 'xmlsimple'
3
+ rescue LoadError
4
+ STDERR.puts "No valid xml-simple library detected, please install one of 'xml-simple'."
5
+ exit -2
6
+ end
7
+
3
8
 
4
9
  module NMA
5
10
 
@@ -14,10 +19,10 @@ module NMA
14
19
 
15
20
  # A hash of the returned XML response
16
21
  attr_accessor :body
17
-
22
+
18
23
  # A hash of the cooked XML
19
24
  attr_accessor :response
20
-
25
+
21
26
  def initialize(response)
22
27
  self.raw = response.body
23
28
  self.code = response.code
@@ -5,15 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-notify-my-android}
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ken Pepple"]
12
- s.date = %q{2011-04-18}
13
- s.default_executable = %q{notify-my-andoid}
12
+ s.date = %q{2011-04-21}
13
+ s.default_executable = %q{notify-my-android}
14
14
  s.description = %q{Send notifications to Android devices via the Notify My Android API. Details about the API are available at https://nma.usk.bz/api.php .}
15
15
  s.email = %q{ken.pepple@rabbityard.com}
16
- s.executables = ["notify-my-andoid"]
16
+ s.executables = ["notify-my-android"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
19
  "README.rdoc"
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  "README.rdoc",
26
26
  "Rakefile",
27
27
  "VERSION",
28
- "bin/notify-my-andoid",
28
+ "bin/notify-my-android",
29
29
  "lib/ruby-notify-my-android.rb",
30
30
  "lib/ruby-notify-my-android/notification.rb",
31
31
  "lib/ruby-notify-my-android/request.rb",
@@ -47,6 +47,7 @@ class TestRubyNotifyMyAndroid < Test::Unit::TestCase
47
47
  assert_equal("799", result.response["remaining"])
48
48
  assert_equal("200", result.response["code"])
49
49
  assert_equal("60", result.response["resettimer"])
50
+ assert(result.succeeded?)
50
51
  end
51
52
 
52
53
  def test_should_verify_bad_but_valid_size_apikey
@@ -115,6 +116,7 @@ class TestRubyNotifyMyAndroid < Test::Unit::TestCase
115
116
  def test_version
116
117
  v = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
117
118
  assert_equal(v, NMA.version)
119
+ assert_equal(NMA.version, NMA::VERSION)
118
120
  end
119
121
 
120
122
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-notify-my-android
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Pepple
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-18 00:00:00 -07:00
19
- default_executable: notify-my-andoid
18
+ date: 2011-04-21 00:00:00 -07:00
19
+ default_executable: notify-my-android
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  prerelease: false
@@ -111,7 +111,7 @@ dependencies:
111
111
  description: Send notifications to Android devices via the Notify My Android API. Details about the API are available at https://nma.usk.bz/api.php .
112
112
  email: ken.pepple@rabbityard.com
113
113
  executables:
114
- - notify-my-andoid
114
+ - notify-my-android
115
115
  extensions: []
116
116
 
117
117
  extra_rdoc_files:
@@ -124,7 +124,7 @@ files:
124
124
  - README.rdoc
125
125
  - Rakefile
126
126
  - VERSION
127
- - bin/notify-my-andoid
127
+ - bin/notify-my-android
128
128
  - lib/ruby-notify-my-android.rb
129
129
  - lib/ruby-notify-my-android/notification.rb
130
130
  - lib/ruby-notify-my-android/request.rb
data/bin/notify-my-andoid DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'ruby-notify-my-android'
6
- require 'yaml'
7
-
8
- # set defaults
9
- options = { :apikey => nil,
10
- :description => "test description",
11
- :event => "test event",
12
- :application => "NMA",
13
- :priority => Priority::NORMAL }
14
-
15
- # use first argument on command line as API key
16
- options[:apikey] = ARGV[0]
17
-
18
- # send notification
19
- result = NMA.notify do |n|
20
- n.apikey = options[:apikey]
21
- n.priority = options[:priority]
22
- n.application = options[:application]
23
- n.event = options[:event]
24
- n.description = options[:description]
25
- n.url = options[:url]
26
- end
27
-
28
- # putput raw XML response
29
- puts result.raw