NotifyMyAndroidLib

Java Library to access NotifyMyAndroid public API

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

de.tobj.nma
ArtifactId

ArtifactId

nmaclient
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

NotifyMyAndroidLib
Java Library to access NotifyMyAndroid public API
Project Organization

Project Organization

Tobias Johannes

Download nmaclient

How to add to project

<!-- https://jarcasting.com/artifacts/de.tobj.nma/nmaclient/ -->
<dependency>
    <groupId>de.tobj.nma</groupId>
    <artifactId>nmaclient</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/de.tobj.nma/nmaclient/
implementation 'de.tobj.nma:nmaclient:1.0.2'
// https://jarcasting.com/artifacts/de.tobj.nma/nmaclient/
implementation ("de.tobj.nma:nmaclient:1.0.2")
'de.tobj.nma:nmaclient:jar:1.0.2'
<dependency org="de.tobj.nma" name="nmaclient" rev="1.0.2">
  <artifact name="nmaclient" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.tobj.nma', module='nmaclient', version='1.0.2')
)
libraryDependencies += "de.tobj.nma" % "nmaclient" % "1.0.2"
[de.tobj.nma/nmaclient "1.0.2"]

Dependencies

compile (2)

Group / Artifact Type Version
de.tobj.http.simplerequest : httprequestsimple jar 1.0.2
org.apache.logging.log4j : log4j-api jar 2.1

test (2)

Group / Artifact Type Version
org.apache.logging.log4j : log4j-core jar 2.1
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

#NotifyMyAndroidLib (Java)

NotifyMyAndroid is a service which allows you to send push messages to android devices.

NotifyMyAndroidLib is an object-oriented library (written in Java), which covers the entire API. You only have to fill a request object and hand this object over to the library. For more information, see the chapter 'Usage'.

##Usage

At the moment, the NMA-API has two endpoints, verify and notify

###Verify

This will verify one API key against the NMA service:

public class VerifyMain {
    public static void main(String[] args) throws ConnectorException, ParserException {
        VerifyRequest request = new VerifyRequest();
        request.setApiKey("API_KEY");

        NMAClient nmaClient = new NMAClient();
        Result result = nmaClient.request(request);

        // isSuccess: true
        System.out.println("isSuccess: " + result.isSuccess());
        // isError: false
        System.out.println("isError: " + result.isError());
        // Code: 200
        System.out.println("Code: " + result.getCode());
        // Type: success
        System.out.println("Type: " + result.getType());
        // Message: null
        System.out.println("Message: " + result.getMessage());
        // ResultObject: Result{code='200', message='null', remaining=995, resettimer='50', type='success', isSuccess='true', isError='false'}
        System.out.println("ResultObject: " + result.toString());
    }
}

###Notify

This will send a push notification to the client(s) identified by the provided API key(s)

public class NotifyMain {
    public static void main(String[] args) throws ConnectorException, ParserException {
        NotifyRequest request = new NotifyRequest();
        request.addApiKey("API_KEY");
        request.setContentType(ContentType.TEXT_HTML);
        request.setPriority(Priority.NORMAL);
        request.setApplication("Test App");
        request.setEvent("Event");
        request.setDescription("Be<b>schrei</b>bung<br>Beschreibung2");
        request.setUrl("http://www.google.de");

        NMAClient nmaClient = new NMAClient();
        Result result = nmaClient.request(request);

        // isSuccess: true
        System.out.println("isSuccess: " + result.isSuccess());
        // isError: false
        System.out.println("isError: " + result.isError());
        // Code: 200
        System.out.println("Code: " + result.getCode());
        // Type: success
        System.out.println("Type: " + result.getType());
        // Message: null
        System.out.println("Message: " + result.getMessage());
        // ResultObject: Result{code='200', message='null', remaining=994, resettimer='46', type='success', isSuccess='true', isError='false'}
        System.out.println("ResultObject: " + result.toString());
    }
}

The NotifyRequest from above looks like this:

NotifyRequest in AndroidApp

Return Codes

All requests will be answered with the HTTP status code 200. This way you will know that you were able to contact the server and the error is an application error or something else.

The response contains a custom code:

Code Description
200 Notification submitted.
400 The data supplied is in the wrong format, invalid length or null.
401 None of the API keys provided were valid.
402 Maximum number of API calls per hour exceeded.
500 Internal server error. Please contact our support if the problem persists.

##Installation

###Maven

Using Maven is recommended and its dependencies will be downloaded automatically.

Add the following to the <dependencies> section in your pom.xml. Click here for Ivy, Gradle, and other configs.

<dependency>
    <groupId>de.tobj.nma.client</groupId>
    <artifactId>nmaclient</artifactId>
    <version>1.0.2</version>
</dependency>

##Configuration

NotifyMyAndroidLib requires no configuration files but you can define a custom NMA API URL. The default url points to https://www.notifymyandroid.com/publicapi/

new NMAClient("custom-url");

##TODO

  • check validity of data (required fields, length, etc...)

##Dependencies

de.tobj.http.httprequestsimple:1.0.2
org.apache.logging.log4j:log4j-api:2.1

##NotifyMyAndroid-API

Documentation is located at http://www.notifymyandroid.com/api.jsp

Authors

TobJ [email protected]

Versions

Version
1.0.2
1.0.1
1.0.0