How to Integrate SMSBump In Your Application

How to Integrate SMSBump in your application

SMSBump is a web service for sending SMS messages. It is perfect if you want to send transactional messages to your customers internationally. You can use the service through a REST API, which has a simple and easy to use interface. In this blog post we will go through some of the API’s methods and provide implementation examples.

Prerequisites

You will need to sign up at http://smsbump.com/users/signup and create an app in order to follow the examples in this blog post. Creating an account is free and requires only a valid e-mail and a phone number. No charges are being made upon registration. You will even get a bonus of $1 which you can use to test the service.

Create an App

After you sign-up, go to your dashboard and hit the Create App button. Give your app a name and choose Java for the Platform. Make sure the Status is set to Enabled and hit the Create this app button. You are now ready to begin using SmsBump, so let’s get to work.

 

The API

The API documentation for SMSBump can be found at http://smsbump.com/pages/docs. It operates using standard HTTP requests like this “http://api.smsbump.com/send/XXXXXXXXXXXX.json?to=xxxxxxxxxxxx&message=Let's bump!” We can divide this API request into 4 main parts:

 

  1. API URL - http://api.smsbump.com/send/XXXXXXXXXXXX.json?to=xxxxxxxxxxxx&message=Let's bump!

  2. Method - http://api.smsbump.com/send/XXXXXXXXXXXX.json?to=xxxxxxxxxxxx&message=Let's bump!

  3. API Key - http://api.smsbump.com/send/XXXXXXXXXXXX.json?to=xxxxxxxxxxxx&message=Let's bump!

  4. Parameters - http://api.smsbump.com/send/XXXXXXXXXXXX.json?to=xxxxxxxxxxxx&message=Let's bump!

 

The API URL is always the same, the Method can be any of the following: send,estimate,balance and the API Key is different for each application. Each method takes different parameters, more information about which can be found in the API docs. We will be focusing on the send method today.

 

How to use the API?

We will show you how to send a message to a single recipient, but you will see that sending to more than one recipient is just as easy and straightforward. However, have in mind that the support for multiple recipients is something implemented in our client libraries and not in the service itself. We are working on native support for multiple recipients, so expect this feature soon. Our client libraries for Java, JavaScript, PHP and Python will all take care of the multiple recipients abstraction for you. In today's example we will be using the Java library.

 

Code examples

You need to go to http://smsbump.com/pages/docs/library-java and get yourself a copy of the Java library. The library works on Android as well, so feel free to use it in your Android project.

Ok, so let’s send a message. The code in Java, using our library, will look like this:

import com.smsbump.SmsBump;

public class SmsBumpExample {
   public static void main(String[] args) throws Exception {
       SmsBump smsbump = new SmsBump("{your_api_key}}", "{recipient}", "Hello World from SmsBump!");
       smsbump.send();
   }
}

 

Let’s go through this example briefly. The library’s code is contained in the com.smsbump.SmsBump package, so we need to import it first. Then we create an instance of the SmsBump class. Four constructors are available for instantiating an object from the SmsBump class:

public SmsBump(String APIKey, String recipient, String message)
public SmsBump(String APIKey, String[] recipients, String message)
public SmsBump(String APIKey, String recipient, String message, SmsBumpRunnable callback)
public SmsBump(String APIKey, String[] recipients, String message, SmsBumpRunnable callback)

In our case we used the first one. As you can see you can also pass an array for the recipients, and the library will make sure that each of them will get the same message.

You might expect that the SMSBump service responds to each API call, and you are correct. The responses are strings in the JSON format and they carry information about what happened with your request. For example you can tell if it was successful or not. A response will also tell you the amount you were charged on a successful request, or an error message on fail. So you probably want to know the response to each request, right? You can get it by setting a callback method to your smsbump object like this:

import com.smsbump.SmsBump;
import com.smsbump.SmsBumpRunnable;

public class SmsBumpExample {
   public static void main(String[] args) throws Exception {
       SmsBump smsbump = new SmsBump("{your_api_key}}", "{recipient(s)}", "Hello World from SmsBump!");
       smsbump.setCallback(new SmsBumpRunnable() {
           private String response;
           
           public void setResponse(String response) { this.response = response; }

           public void run() {
               System.out.println( this.response );
           }
       });
       smsbump.send();
   }
}

This example is almost identical with the first one, but here we implement a callback method to allow ourselves to read the response of each request. Notice that we had to import the com.smsbump.SmsBumpRunnable interface. The SmsBumpRunnable interface needs you to implement a setResponse(String response) method and since it extends Runnable, you will also need to implement the run() method. Something that you need to be aware of is that callbacks will always be run on their separate threads, even if the sending process is not multi-threaded. Have in mind that by default, every SmsBump object uses threads when sending to multiple recipients (5 threads maximum).

Finally, if you need to turn off multi-threading, add this line before the call to the send() method:

smsbump.multithreading = false;

 

Finishing words

I hope this will help you get started with SMSBump. We have a lot of new and exciting features coming soon, so stay tuned. If you are an e-commerce owner you may check our OpenCart integration which can be downloaded from: https://isenselabs.com/products/view/smsbump-the-best-sms-solution-for-opencart.

Join 11,000+ subscribers receiving actionable E-commerce advice

* Unsubscribe any time

Trending blogs

comments powered by Disqus