Skip to content
This repository

send notifications to Notify My Android application

branch: master
README.rdoc

ruby-notify-my-android

Send notifications to Android devices via the Notify My Android API. Details about the API are available at www.notifymyandroid.com/api.php.

Test Status

Build Status

Installation

gem install ruby-notify-my-android

Usage from command line

You can send notifications from the command line with the notify-my-android script:

$ notify-my-android -k 9d0538ab7b52360e906e0e766f34501b69edde92fe3409e9
Notification sent !

Here are the full set of parameters that it accepts:

Usage: notify-my-android [options]
    -k, --apikey APIKEY              Your API Key
    -p, --priority PRIORITY          Priority (-2,-1,0,1,2)
    -a, --application APPNAME        Name of app
    -e, --event EVENTNAME            Name of event
    -d, --description DESCRIPTION     Notify text

Any parameters unset will use default values except –apikey

Usage as a Gem

Sending a notification via ruby-notify-my-android gem

require 'rubygems'
require 'ruby-notify-my-android'

NMA.notify do |n| 
  n.apikey = "9d1538ab7b52360e906e0e766f34501b69edde92fe3409e9" # can also be list such as ["key1", "key2"]
  n.priority = NMA::Priority::MODERATE
  n.application = "NMA"
  n.event = "Notification"
  n.description = "Your server is under attack!!!"
end

Using the API

There are only a few commands that are available:

  • notify(notification block): send a notification via the block given (see above) and returns standard API response.

  • verify(apikey): send API call to verify key. returns standard API response.

  • valid_key?(apikey): send API call to verify key. returns true or false.

  • remaining_calls(apikey): send API call to verify key. returns number of remaining calls as integer.

  • version: returns version of this gem

The standard API response for a successful call is as follows:

#<NMA::Response:0x1059682b8
 @body={"success"=>[{"resettimer"=>"59", "code"=>"200", "remaining"=>"798"}]},
 @code="200",
 @raw=
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?><nma><success code=\"200\" remaining=\"798\" resettimer=\"59\" /></nma>\r\n",
 @response={"resettimer"=>"59", "code"=>"200", "remaining"=>"798"}>

The standard API response for a unsuccessful call is as follows:

@body=
  {"error"=>
    [{"code"=>"400", "content"=>"Parameter 'apikey' length is invalid."}]},
 @code="200",
 @raw=
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?><nma><error code=\"400\" >Parameter 'apikey' length is invalid.</error></nma>\r\n",
 @response={"code"=>"400", "content"=>"Parameter 'apikey' length is invalid."}>

Note that the @code signifies the success or failure of the HTTP call, not the NMA call. Use the @response[“code”] for that determination.

Contributing to ruby-notify-my-android

  • Familiarize yourself with the documentation at www.notifymyandroid.com/api.php

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Make tests for your new feature(s). We can't accept non-tested features.

  • Commit and push until you are happy with your contribution

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Written by Ken Pepple

Based on Prowly gem (github.com/rafmagana/prowly) by Rafael Magana

See LICENSE.txt for further details.

Something went wrong with that request. Please try again.