Skip to content

Commit

Permalink
Merge pull request #3 from miqdadyyy/improvement
Browse files Browse the repository at this point in the history
Improvement
  • Loading branch information
miqdadyyy authored May 13, 2021
2 parents a33c1a1 + a124070 commit 3fd58fb
Show file tree
Hide file tree
Showing 9 changed files with 15,041 additions and 31 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [released]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea/
node_modules/
test/

.env
.DS_Store
69 changes: 54 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Movider
![NPM](https://img.shields.io/npm/l/movider?color=red)
![npm](https://img.shields.io/npm/v/movider?color=blue)
![npm](https://img.shields.io/npm/dy/movider)
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/miqdadyyy/movider/unit-test/master?color=green)

Unofficial package for Movider SMS Service

## Install
Expand All @@ -23,35 +28,69 @@ const moviderClient = new Movider(MOVIDER_API_KEY, MOVIDER_API_SECRET);
// Get Balance
moviderClient.getBalance()
.then(balance => {
console.log(balance);
console.log(balance.amount);
});

// Send SMS to number
moviderClient.sendSMS('62888888888', 'Hello World', {
from: 'MOVIDER', // Sender Name
moviderClient.sendSMS('+62888888888', 'Hello World', {
from: 'MOVIDER', // Sender Name ID
callback: { // Callback after message sended to deliver report / data
url: 'https://api.example.com/moivder-callback',
url: 'https://api.example.com/movider-callback',
method: 'POST'
}
})
```

### Usage Response
Check Balance
```json
{
"type": "USD",
"amount": 20.84
}
```
### Response
**Check Balance :**
| Property | Description |
|----------|--------------------------|
| amount | To get amount of balance |
| currency | Currency of balance |

Send SMS
```json
**Send SMS :**
| Property | Description |
|--------------------|---------------------------------------------|
| message | Your SMS Message |
| balance | Remaining balance after sending SMS |
| total | Get total of number |
| total_price | Get total of sms usage |
| sended_number_list | Get list of sended number (Array of object) |
| failed_number_list | Get list of failed number (Array of object) |

**Webhook Response :**
```
{
"status": 200,
"headers": {},
"body": {
"headers": {
"host": "your-webhook-url.com",
"x-amzn-trace-id": "Root=1-609cbf32-4ffc63d96531b6a744c8a481",
"content-length": "158",
"content-type": "application/x-www-form-urlencoded",
"accept-encoding": "gzip",
"user-agent": "Go-http-client/2.0"
},
"body": {
"detail": "DELIVERIED",
"message_id": "ABCDEFGHIJKLMNOP",
"message_price": "0.013",
"sent_date": "2021-05-13 05:52:55 +0000 UTC",
"status": "OK",
"to": "628123456789"
},
"inferred_body_type": "FORM",
"method": "POST",
"url": "https://your-webhook-url.com/",
"client_ip": "0.1.234.5",
"query": {}
}
}
```

## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
If you discover any security related issues, please email [email protected] or using the issue tracker.

## Credits
- [Miqdad Farcha](https://github.com/miqdadyyy)
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fetch = require('node-fetch');
const {URLSearchParams} = require('url');
const {BalanceResponse, SMSResponse} = require('./model');

const BASE_URL = 'https://api.movider.co/v1';

Expand All @@ -25,6 +26,10 @@ const Movider = class {
encodedParams.set('api_key', this.api_key);
encodedParams.set('api_secret', this.api_secret);

for(const key in data) {
encodedParams.set(key, data[key]);
}

const options = {
method: 'POST',
headers: {
Expand All @@ -49,7 +54,7 @@ const Movider = class {

getBalance() {
return this._fetch('/balance')
.then(balance => balance);
.then(response => new BalanceResponse(response));
}

/**
Expand All @@ -72,6 +77,7 @@ const Movider = class {
callback_url: options.callback.url,
callback_method: options.callback.method
})
.then(response => new SMSResponse(response, message));
}
}

Expand Down
58 changes: 58 additions & 0 deletions model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const BalanceResponse = class {
constructor(response) {
this._amount = response.amount;
this._currency = response.type;
}

get amount() {
return this._amount;
}

get currency() {
return this._currency;
}
}

const SMSResponse = class {
constructor(response, message) {
this._message = message;
this._balance = response.remaining_balance;
this._total = response.total_sms;
this._sended_number_list = response.phone_number_list;
this._failed_number_list = response.bad_phone_number_list;
}

get total_price() {
let totalPrice = 0;
for (const number of this._sended_number_list) {
totalPrice += number.price;
}

return totalPrice;
}

get message() {
return this._message;
}

get balance() {
return this._balance;
}

get total() {
return this._total;
}

get sended_number_list() {
return this._sended_number_list;
}

get failed_number_list() {
return this._failed_number_list;
}
}

module.exports = {
BalanceResponse,
SMSResponse
}
Loading

0 comments on commit 3fd58fb

Please sign in to comment.