nimbasms / nimbasms-java

A Java module for communicating with Nimba SMS API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nimbasms-java

A Java module for communicating with Nimba SMS API.

Usage

First, instantiate the client using your API key:

Installation

System Requirements

  • JDK 11 or higher.
  • subscription via Nimba SMS Partner portal

Add Maven Dependency

If you use Maven, add the following configuration to your project's pom.xml

<dependency>
  <groupId>com.nimbasms</groupId>
  <artifactId>nimbasms</artifactId>
  <version>0.0.1</version>
</dependency>

Configuration of Credentials

Before instantiating a NimbaSMSClient object, ensure you have the required credentials. Obtain these credentials (ACCOUNT_SID and AUTH_TOKEN) from your SMS service provider.

String ACCOUNT_SID = "Your_ACCOUNT_SID";
String AUTH_TOKEN = "Your_AUTH_TOKEN";

Get your Access token

import com.nimbasms.nimbasms.NimbaSMSClient;

NimbaSMSClient client = new NimbaSMSClient(ACCOUNT_SID, AUTH_TOKEN)

Accounts

Retrieve the account information using the getAccount() method:

AccountResponse account = client.getAccount().get();
System.out.println(account);

Check balance

AccountResponse account = client.getAccount().get();
System.out.println(account.getBalance());

Groups

This code retrieves a list of all groups.

GroupResponse groups = client.getGroup().list();
System.out.println(groups);

You can also retrieve the last 10 Group by passing in the limit and offset:

GroupResponse last10groups = client.getGroup().list(10, 1);
System.out.println(last10groups);

The next method returns the next item in a list.

GroupResponse nextGroups = client.getGroup().next();
System.out.println(nextGroups);

The previous method returns the previous item in the list.

GroupResponse previousGroups = client.getGroup().previous();
System.out.println(previousGroups);

Sendernames

Retrieve the sender names using the getSenderName() method:

SenderNameResponse senderNames = client.getSenderName().list();
System.out.println(senderNames);

You can also retrieve the last 10 sender names by passing in the limit and offset:

SenderNameResponse last10SenderNames = client.getSenderName().list(10, 1);
System.out.println(last10SenderNames);

The next method returns the next item in a list.

SenderNameResponse nextSenderNames = client.getSenderName().next();
System.out.println(nextSenderNames);

The previous method returns the previous item in the list.

SenderNameResponse previousSenderNames = client.getSenderName().previous();
System.out.println(previousSenderNames);

Contacts

This code retrieves a list of all contacts.

ContactResponse contacts = client.getContact().list();
System.out.println(contacts);

You can also retrieve the last 10 contacts by passing in the limit and offset:

ContactResponse last10contacts = client.getContact().list(10, 1);
System.out.println(last10contacts);

The next method returns the next item in a list.

ContactResponse nextContacts = client.getContact().next();
System.out.println(nextContacts);

The previous method returns the previous item in the list.

ContactResponse previousContacts = client.getContact().previous();
System.out.println(previousContacts);

Create Contact. This contact will be added to the default contact list:

ContactDto createContactResponse = client.getContact().create("+224XXXXXXXXX", null, null);
System.out.println(createContactResponse)

Create with groups and name - name and groups are optional.

ContactDto contactResponseWithGroupsAndName = client.getContact().create("+224XXXXXXXXX", "Foo", List.of("API", "Facebook Client"));
System.out.println(contactResponseWithGroupsAndName);

Messages

Get All messages

MessageResponse messages = client.getMessage().list();
System.out.println(messages);

Get only last 10 messages

MessageResponse last10Messages = client.getMessage().list(10, 1);
System.out.println(last10Messages);

The next method returns the next item in a list.

MessageResponse nextMessages = client.getMessage().next();
System.out.println(nextMessages);

The previous method returns the previous item in the list.

MessageResponse previousMessages = client.getMessage().previous();
System.out.println(previousMessages);

Send a message

MessageResponse messageResponse = client.getMessage().create("sender_name", List.of("+224XXXXXXXXX"), "Hello nimba");
System.out.println(messageResponse);

Retrieve message

MessageDetails messageDetails = client.getMessage().retrieve("123");
System.out.println(messageDetails);

About

A Java module for communicating with Nimba SMS API.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Java 100.0%