JavaScript client which allows you to send SMS messages and manage your account in SMSAPI.com
JavaScript
Pull request Compare This branch is 14 commits ahead, 25 commits behind smsapi:master.
Latest commit 3b0e43c Oct 15, 2016 @adrian-olczyk adrian-olczyk committed on GitHub Merge pull request #1 from lahdekorpi/patch-1
Corrected a wrong character in example code

README.md

SMSAPI.com JavaScript (node.js) Client

npm version

JavaScript client for sending SMS and account management on SMSAPI.com

Installation (node.js)

$ npm install smsapicom --save

Example

var SMSAPI = require('smsapicom'),
    smsapi = new SMSAPI();

smsapi.authentication
    .login('username', 'password')
    .then(sendMessage)
    .then(displayResult)
    .catch(displayError);

function sendMessage(){
    return smsapi.message
        .sms()
        .from('Info')
        .to('+48605xxxxxx')
        .message('My first message!')
        .execute(); // return Promise
}

function displayResult(result){
    console.log(result);
}

function displayError(err){
    console.error(err);
}

Example (backup server)

var SMSAPI = require('smsapi'),
    smsapi = new SMSAPI({
        server: 'https://api2.smsapi.com/'
    });

smsapi.authentication
    .login('username', 'password')
    .then(sendMessage)
    .then(displayResult)
    .catch(displayError);

function sendMessage(){
    return smsapi.message
        .sms()
        .from('Info')
        .to('605xxxxxx')
        .message('My first message!')
        .execute(); // return Promise
}

function displayResult(result){
    console.log(result);
}

function displayError(err){
    console.error(err);
}

Authentication

Library supports plain text password and md5 hash as a method of authentication. By default Basic auth is used.

Plain text example

var promise = smsapi.authentication
    .login('username', 'password');

md5 hash example

var promise = smsapi.authentication
    .loginHashed('username', '5f4dcc3b5aa765d61d8327deb882cf99');

OAuth

To use OAuth add parameters while SMSAPI object creation:

  • oauth.clientId
  • oauth.clientSecret
  • oauth.grantType (opcjonalnie)
  • oauth.scope (opcjonalnie)
var SMSAPI = require('smsapi'),
    smsapi = new SMSAPI({
        oauth: {
            clientId: 'your-client-id',
            clientSecret: 'your-client-secret'
        }
    });

var promise = smsapi.authentication
    .login('username', 'password');

Library manages auth token internally.

Token will expire after 60 minutes. To refresh token use refreshToken() method.

var promise = smsapi.authentication
    .refreshToken();

Documentation

REST API documentation: http://www.smsapi.com/rest.

Requests are returning Promises/A+. Used implementation: https://github.com/tildeio/rsvp.js

List of available operations

  • message
    • sms
  • points
    • get
  • sender
    • add
    • delete
    • status
    • default
    • list
  • hlr
    • check
  • user
    • add
    • delete
    • update
    • get
    • list
  • contacts
    • list
    • add
    • get
    • update
    • delete
    • fields
      • list
      • add
      • update
      • delete
    • groups
      • list
      • add
      • get
      • update
      • delete
      • assignments
        • list
        • add
        • get
        • delete
      • permissions
        • list
        • add
        • get
        • update
        • delete
      • members
        • add
        • get
        • delete

Examples

Additional examples can be found in test folder (./test).

Testing

$ npm install mocha -g
$ npm install .
$ npm test

License

Apache 2.0 License