Skip to content
The Releans Angular SDK allow you to get up an running with Releans API quickly in your project. # What you can do with Releans Services? 1- Send emails 2- On-time SMS 3- Automation for reminders and appointments
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
releansapilib
.jshintrc
LICENSE
README.md

README.md

Getting started

The Releans SDK enables developers to use Releans Services in their code. You can get started in minutes.

How to Build

The generated SDK requires AngularJS framework to work. If you do not already have angular downloaded, please go ahead and do it from here. You will also need to download and link angular-moment and moment.js with your project because the SDK internally uses moment.js.

How to Use

The following section describes how to use the generated SDK in an existing/new project.

1. Configure Angular and Generated SDK

Perform the following steps to configure angular and the SDK:

  • Make a scripts folder inside the root folder of the project. If you already have a scripts folder, skip to the next step.
  • Move the angular.min.js file inside the scripts folder.
  • Move the ReleansAPILib folder inside the scripts folder.
  • If any of the Custom Types in your API have Date/Datetime type fields or any endpoint has Date/Datetime response, you will need to download angular-moment and moment.js. Move these 2 files into the scripts folder as well.

folder-structure-image

2. Open Project Folder

Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on File and select Open Folder

Select the folder of your SDK and click on Select Folder to open it up in Sublime Text. The folder will become visible in the bar on the left.

open-folder-image

3. Create an Angular Application

Since Angular JS is used for client-side web development, in order to use the generated library, you will have to develop an application first. If you already have an angular application, skip to Step 6. Otherwise, follow these steps to create one:

  • In the IDE, click on File and choose New File to create a new file.
  • Add the following starting code in the file:
var app = angular.module('myApp', []);
app.controller('testController', function($scope) 
{

});
  • Save it with the name app.js in the scripts folder.

4. Create HTML File

Skip to the next step if you are working with an existing project and already have an html file. Otherwise follow the steps to create one:

  • Inside the IDE, right click on the project folder name and select the New File option to create a new test file.
  • Save it with an appropriate name such as index.html in the root of your project folder. index.html should look like this:
<!DOCTYPE html>
<html>
<head>
	<title>Angular Project</title>
	<script></script>
</head>

<body>
</body>

</html>

initial-html-code-image

5. Including links to Angular in HTML file

Your HTML file needs to have a link to angular.min.js file to use Angular-JS. Add the link using script tags inside the head section of index.html like:

<script src="scripts/angular.min.js" ></script>

If any of the Custom Types that you have defined have Date/Datetime type fields or any endpoint has Date/Datetime response, you will also need to link to angular-moment and moment.js like:

<script src="scripts/angular.min.js" ></script>
<script src="scripts/moment.min.js" ></script>
<script src="scripts/angular-moment.min.js" ></script>

6. Include SDK references in HTML file

Import the reference to the generated SDK files inside your html file like:

<head>
    ...
    <!-- Helper files -->
    <script src="scripts/ReleansAPILib/Module.js"></script>
    <script src="scripts/ReleansAPILib/Configuration.js"></script>
    <script src="scripts/ReleansAPILib/ModelFactory.js"></script>
    <script src="scripts/ReleansAPILib/ObjectMapper.js"></script>
    <script src="scripts/ReleansAPILib/APIHelper.js"></script>
    <script src="scripts/ReleansAPILib/Http/Client/HttpContext.js"></script>
    <script src="scripts/ReleansAPILib/Http/Client/HttpClient.js"></script>
    <script src="scripts/ReleansAPILib/Http/Request/HttpRequest.js"></script>
    <script src="scripts/ReleansAPILib/Http/Response/HttpResponse.js"></script>

    <!-- API Controllers -->
    <script src="scripts/ReleansAPILib/Controllers/BaseController.js"></script>
    <script src="scripts/ReleansAPILib/Controllers/MessageController.js"></script>
    <script src="scripts/ReleansAPILib/Controllers/SenderController.js"></script>
    <script src="scripts/ReleansAPILib/Controllers/BalanceController.js"></script>


    <!-- Models -->
    <script src="scripts/ReleansAPILib/Models/BaseModel.js"></script>
    <script src="scripts/ReleansAPILib/Models/Response2001.js"></script>
    <script src="scripts/ReleansAPILib/Models/Response200.js"></script>
    <script src="scripts/ReleansAPILib/Models/Response2002.js"></script>

    ...
</head>

The Module.js file should be imported before the other files. After Module.js, Configuration.js should be imported. The ModelFactory.js file is needed by ObjectMapper.js file. The ObjectMapper in turn, is needed by BaseController.js.

7. Including link to app.js in HTML file

Link your app.js file to your index.html file like:

<head>
	...
	<script src="scripts/app.js"></script>
</head>

The link to app.js needs to be included at the very end of the head tag, after the SDK references have been added

8. Initializing the Angular App

You need to initialize your app and the controller associated with your view inside your index.html file. Do so like:

  • Add ng-app directive to initialize your app inside the body tag.
<body ng-app="myApp">
  • Add ng-controller directive to initialize your controller and bind it with your view (index.html file).
...
<body ng-app="myApp">
	<div ng-controller="testController">
		...
	</div>
	...
</body>
...

9. Consuming the SDK

In order to use the generated SDK's modules, controllers and factories, the project needs to be added as a dependency in your angular app's module. This will be done inside the app.js file. Add the dependency like this:

var app = angular.module('myApp', ['ReleansAPILib']);

At this point, the SDK has been successfully included in your project. Further steps include using a service/factory from the generated SDK. To see working example of this, please head on over here and choose any class to see its functions and example usage.

10. Running The App

To run the app, simply open up the index.html file in a browser.

app-running

Initialization

The Angular Application can be initialized as following:

var app = angular.module('myApp', [ReleansAPILib]);
// now controllers/services can be created which import
// the factories provided by the sdk

Authentication

In order to setup authentication and initialization of the Angular App, you need the following information.

Parameter Description
oAuthAccessToken OAuth 2.0 Access Token
var app = angular.module('myApp', [ReleansAPILib]);

app.run(function(Configuration) {
    // Configuration parameters and credentials
    Configuration.oAuthAccessToken = 'oAuthAccessToken'; // OAuth 2.0 Access Token
    
});

Class Reference

List of Controllers

Class: MessageController

Get singleton instance

The singleton instance of the MessageController class can be accessed via Dependency Injection.

	app.controller("testController", function($scope, MessageController){
	});

Method: getAllMessages

List all messages sent by the account.

function getAllMessages(accept)

Parameters

Parameter Tags Description
accept Required TODO: Add a parameter description

Example Usage

	app.controller("testController", function($scope, MessageController){
        var accept = '*/*';


		var result = MessageController.getAllMessages(accept);
        //Function call returns a promise
        result.then(function(success){
			//success case
			//getting context of response
			console.log(success.getContext());
		},function(err){
			//failure case
		});

	});

Method: getViewMessage

Return the details of the message.

function getViewMessage(id, accept)

Parameters

Parameter Tags Description
id Required TODO: Add a parameter description
accept Required TODO: Add a parameter description

Example Usage

	app.controller("testController", function($scope, MessageController){
        var id = 'id';
        var accept = '*/*';


		var result = MessageController.getViewMessage(id, accept);
        //Function call returns a promise
        result.then(function(success){
			//success case
			//getting context of response
			console.log(success.getContext());
		},function(err){
			//failure case
		});

	});

Method: createSendSMSMessage

Send a single message.

function createSendSMSMessage(accept, senderId, mobileNumber, message)

Parameters

Parameter Tags Description
accept Required TODO: Add a parameter description
senderId Required Sender id to send the message from.
mobileNumber Required The mobile number supposed to receive the message.
message Required Message text.

Example Usage

	app.controller("testController", function($scope, MessageController){
        var accept = 'Accept';
        var senderId = 'senderId';
        var mobileNumber = 'mobileNumber';
        var message = 'message';


		var result = MessageController.createSendSMSMessage(accept, senderId, mobileNumber, message);
        //Function call returns a promise
        result.then(function(success){
			//success case
			//getting context of response
			console.log(success.getContext());
		},function(err){
			//failure case
		});

	});

Back to List of Controllers

Class: SenderController

Get singleton instance

The singleton instance of the SenderController class can be accessed via Dependency Injection.

	app.controller("testController", function($scope, SenderController, Response200, Response2001){
	});

Method: getSenderNameDetails

Return the details of the sender name.

function getSenderNameDetails(id, accept)

Parameters

Parameter Tags Description
id Required TODO: Add a parameter description
accept Required TODO: Add a parameter description

Example Usage

	app.controller("testController", function($scope, SenderController){
        var id = 'sender-id';
        var accept = '*/*';


		var result = SenderController.getSenderNameDetails(id, accept);
        //Function call returns a promise
        result.then(function(success){
			//success case
			//getting context of response
			console.log(success.getContext());
		},function(err){
			//failure case
		});

	});

Method: createSenderName

Create a new sender id to send messages using it

function createSenderName(accept, contentType, body)

Parameters

Parameter Tags Description
accept Required TODO: Add a parameter description
contentType Required TODO: Add a parameter description
body Required TODO: Add a parameter description

Example Usage

	app.controller("testController", function($scope, SenderController, Response200){
        var accept = 'text/plain';
        var contentType = 'text/plain';
        var body = 'Your sender name';


		var result = SenderController.createSenderName(accept, contentType, body);
        //Function call returns a promise
        result.then(function(success){
			//success case
			//getting context of response
			console.log(success.getContext());
		},function(err){
			//failure case
		});

	});

Method: getAllSenders

List all senders names associated with the account

function getAllSenders(accept)

Parameters

Parameter Tags Description
accept Required TODO: Add a parameter description

Example Usage

	app.controller("testController", function($scope, SenderController, Response2001){
        var accept = '*/*';


		var result = SenderController.getAllSenders(accept);
        //Function call returns a promise
        result.then(function(success){
			//success case
			//getting context of response
			console.log(success.getContext());
		},function(err){
			//failure case
		});

	});

Back to List of Controllers

Class: BalanceController

Get singleton instance

The singleton instance of the BalanceController class can be accessed via Dependency Injection.

	app.controller("testController", function($scope, BalanceController, Response2002){
	});

Method: getBalance

Get your available balance

function getBalance(accept)

Parameters

Parameter Tags Description
accept Required TODO: Add a parameter description

Example Usage

	app.controller("testController", function($scope, BalanceController, Response2002){
        var accept = 'text/plain';


		var result = BalanceController.getBalance(accept);
        //Function call returns a promise
        result.then(function(success){
			//success case
			//getting context of response
			console.log(success.getContext());
		},function(err){
			//failure case
		});

	});

Back to List of Controllers

You can’t perform that action at this time.