Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sreyantha-plivo committed Oct 24, 2017
0 parents commit 6dab403
Show file tree
Hide file tree
Showing 52 changed files with 5,930 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "flow"]
}
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"plugin:flowtype/recommended"
],
"plugins": [
"flowtype"
]
}
Empty file added .flowconfig
Empty file.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docs/
.DS_Store
.idea/
node_modules
coverage
dist
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
service_name: travis-ci
language: node_js
node_js:
- "node"
- "lts/*"
- "8"
- "7"
- "6"
- "5"
- "4"
5 changes: 5 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Authors
- [Aviral Dasgupta](http://www.aviraldg.com) ([@aviraldg](http://github.com/aviraldg))
- Ketan Tada [@ketantada](https://github.com/ketantada)
- Abhishek [@abhishek-plivo](https://github.com/abhishek-plivo)
- [Sreyantha Chary](https://sreyanth.com?ref=github/plivo-python) ([@sreyanth](https://github.com/sreyanth))
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Change Log

## [0.4.0](Integrate patch from [email protected] and fix travis test)(2016-09-09)
- Added an entry to the .gitignore for WebStorm IDE's, this prevents un-needed files from being checked in.
- Updated Request to version 2.71.0
- Some logic for how JSON serialazation has changed, I have updated the request method to reflect that changed
- Updated xmlBuilder to 8.0.0
- Slight update to syntax for creating a new xml doc : xmlBuilder.begin().ele(this.element);
- Had to update Utility.areEqual to reflect a change in how xmlBuild stores values of child elements
- Updated nock to version 8.0.0,
- Updated Mocha to 2.4.5
- Fix Travis tests (node v6 and v4)

## Other changes
- 2015-01-14 Adds support for PhoneNumber API
- 2013-09-25 Added relayDTMF to <Conference> and async to <DTMF>
- 2013-07-23 addRecord Response mandatory parameter 'body' dropped
- 2013-02-23 pricing API added
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2017, Plivo Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# plivo-node
The Node.js SDK makes it simpler to integrate communications into your Node.js applications using the Plivo REST API. Using the SDK, you will be able to make voice calls, send SMS and generate Plivo XML to control your call flows.

## Installation
Install the SDK using [npm](https://www.npmjs.com/package/plivo)

$ npm install plivo@beta

If you have the `0.4.1` version (a.k.a legacy) already installed, you may have to first uninstall it before installing the new version.

## Getting started

### Authentication
To make the API requests, you need to create a `Client` and provide it with authentication credentials (which can be found at [https://manage.plivo.com/dashboard/](https://manage.plivo.com/dashboard/)).

We recommend that you store your credentials in the `PLIVO_AUTH_ID` and the `PLIVO_AUTH_TOKEN` environment variables, so as to avoid the possibility of accidentally committing them to source control. If you do this, you can initialise the client with no arguments and it will automatically fetch them from the environment variables:

```javascript
let plivo = require('plivo');
let client = new plivo.Client();
```
Alternatively, you can specifiy the authentication credentials while initializing the `Client`.

```javascript
let plivo = require('plivo');
let client = new plivo.Client('your_auth_id', 'your_auth_token');
```

### The basics
The SDK uses consistent interfaces to create, retrieve, update, delete and list resources. The pattern followed is as follows:

```javascript
client.resources.create(name,params); // Create
client.resources.get(id); // Get
client.resources.update(params); // Update
client.resources.delete(id); // Delete
client.resources.list({limit:5,offset:0}); // List all resources, max 20 at a time
```

Also, using `client.resources.list()` would list the first 20 resources by default (which is the first page, with `limit` as 20, and `offset` as 0). To get more, you will have to use `limit` and `offset` to get the second page of resources.

## Examples

### Send a message

```javascript
let plivo = require('plivo');
let client = new plivo.Client();

client.messages.create(
'your_source_number',
'your_destination_number',
'Hello, world!'
).then(function(message_created) {
console.log(message_created)
});

```

### Make a call

```javascript
let plivo = require('plivo');
let client = new plivo.Client();

client.calls.create(
'your_source_number',
'your_destination_number',
'http://answer.url'
).then(function(call_created) {
console.log(call_created)
});

```

### Generate Plivo XML

```javascript
let plivo = require('plivo');
let response = new plivo.Response();
let speak_body = "Hello, world!";

response.addSpeak(speak_body);
console.log(response.toXML());
```

This generates the following XML:

```xml
<Response>
<Speak>Hello, world!</Speak>
</Response>
```

### More examples
Refer to the [Plivo API Reference](https://api-reference.plivo.com/latest/node/introduction/overview) for more examples. Also refer to the [guide to setting up dev environment](https://developers.plivo.com/getting-started/setting-up-dev-environment/) on [Plivo Developers Portal](https://developers.plivo.com) to setup an Express server & use it to test out your integration in under 5 minutes.

## Reporting issues
Report any feedback or problems with this beta version by [opening an issue on Github](https://github.com/plivo/plivo-node/issues).
25 changes: 25 additions & 0 deletions examples/accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();

var name;
//================== Accounts =============
client.accounts.get()
.then(function(account) {
console.log("\n============ Account Detail ===========\n", account)
name = account.name;
return account.update({
name: 'newName'
})
})
.then(function(account) {
console.log("\n============ updated ===========\n", account)
return account.update({
name
})
})
.then(function(account) {
console.log("\n============ original ===========\n", account)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response, response.message);
});
28 changes: 28 additions & 0 deletions examples/applications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();

client.applications.create("http://google.com/", "MyNewApplication" + Math.random(1000))
.then(function(application) {
console.log("\n============ created ===========\n", application)
return client.applications.update(application.id, {
answer_url: 'http://google1.com/'
});
})
.then(function(application) {
console.log("\n============ updated ===========\n", application)
return client.applications.get(application.id);
})
.then(function(application){
console.log("\n============ list with id ===========\n", application)
return application.delete();
})
.then(function(result){
console.log("\n============ deleted ===========\n", result)
return client.applications.list()
})
.then(function(applications){
console.log("\n============ list all ===========\n", applications)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response);
});
15 changes: 15 additions & 0 deletions examples/calls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();


client.calls.create('', '', 'http://localhost/')
.then(function(call) {
console.log("\n============ make call ===========\n", call)
return client.calls.hangup(call.id)
})
.then(function(call){
console.log("\n============ hangup ===========\n", call)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response);
});
37 changes: 37 additions & 0 deletions examples/endpoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();

var create = {
username: "thisistestendpoint",
password: "thisistestpassword",
alias: "this is test alias"
};

var update = {
password: "hi new password",
alias: "hi new alias"
};

client.endpoints.create(create.username, create.password, create.alias)
.then(function(endpoint) {
console.log("\n============ created ===========\n", endpoint)
return client.endpoints.update(endpoint.id, update.username, update.password, update.alias);
})
.then(function(endpoint) {
console.log("\n============ updated ===========\n", endpoint)
return client.endpoints.get(endpoint.id);
})
.then(function(endpoint){
console.log("\n============ list with id ===========\n", endpoint)
return endpoint.delete();
})
.then(function(result){
console.log("\n============ deleted ===========\n", result)
return client.endpoints.list()
})
.then(function(endpoints){
console.log("\n============ list all ===========\n", endpoints)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response);
});
26 changes: 26 additions & 0 deletions examples/numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();

client.numbers.search('US')
.then(function(numbers) {
console.log("\n============ search ===========\n", numbers)
return client.numbers.list()
})
.then(function(numbers){
console.log("\n============ all ===========\n", numbers)
return client.numbers.get(numbers[0].id)
})
.then(function(number){
console.log("\n============ get ===========\n", number)
return number.update(null, null, 'new alias')
})
.then(function(number){
console.log("\n============ update ===========\n", number)
return client.numbers.get(number.id)
})
.then(function(number){
console.log("\n============ get update ===========\n", number)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response);
});
10 changes: 10 additions & 0 deletions examples/pricings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();

client.pricings.get('US')
.then(function(price) {
console.log("\n============ get ===========\n", price)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response);
});
10 changes: 10 additions & 0 deletions examples/recordings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();

client.recordings.list()
.then(function(recordings) {
console.log("\n============ list ===========\n", recordings)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response);
});
30 changes: 30 additions & 0 deletions examples/subaccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var Plivo = require('../dist/rest/client.js');
var client = new Plivo.Client();

client.subAccounts.create(new Date().getTime().toString())
.then(function(response) {
console.log("\n============ Sub Account Detail ===========\n", response)
return client.subAccounts.get(response.auth_id)
})
.then(function(response) {
console.log("\n============ Sub Account Detail ===========\n", response)
return response.update(new Date().getTime().toString(), true)
})
.then(function(response) {
console.log("\n============ Sub Account Detail ===========\n", response)
return client.subAccounts.get(response.auth_id)
})
.then(function(response) {
console.log("\n============ updated ===========\n", response)
return response.delete()
})
.then(function(response) {
console.log("\n============ deleted ===========\n", response)
return client.subAccounts.list()
})
.then(function(response) {
console.log("\n============ All Subaccounts ===========\n", response)
})
.catch(function(response) {
console.log("\n============ Error :: ===========\n", response, response.message);
});
Loading

0 comments on commit 6dab403

Please sign in to comment.