Skip to content

Commit

Permalink
feat: upgrade es6
Browse files Browse the repository at this point in the history
  • Loading branch information
caioagiani committed Feb 22, 2021
1 parent 96a6a69 commit 8f116d1
Show file tree
Hide file tree
Showing 22 changed files with 317 additions and 209 deletions.
8 changes: 1 addition & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ module.exports = {
'no-console': 0,
'linebreak-style': ['error', 'unix'],
'no-unused-vars': ['error', { argsIgnorePattern: 'next' }],
'no-restricted-syntax': [
'warn',
{
selector: 'ForOfStatement',
message: 'frowned upon using For...Of',
},
],
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'import-helpers/order-imports': [
'warn',
{
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<img alt="GitHub language count" src="https://img.shields.io/github/languages/count/caioagiani/mobizon-node">
<img alt="GitHub top language" src="https://img.shields.io/github/languages/top/caioagiani/mobizon-node">
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/caioagiani/mobizon-node">
<img alt="NPM downloads" src="https://img.shields.io/npm/dt/mobizon-node?color=blue">
<img alt="GitHub license" src="https://img.shields.io/badge/license-MIT-blue.svg">
</p>

Expand Down Expand Up @@ -50,14 +51,16 @@ Confira em [docs](https://github.com/caioagiani/mobizon-node/blob/master/docs) t
console.log(getBalance);

/** Encurtar URL */
const short = await mobizon.shortCreate({
fullLink: 'https://mobizon.com.br',
status: 1,
expirationDate: '',
comment: 'Shortened link.',
const createShort = await mobizon.createShort({
data: {
fullLink: 'https://mobizon.com.br',
status: 1,
expirationDate: '',
comment: 'Shortened link.',
},
});

console.log(short);
console.log(createShort);

/** Enviar SMS */
const sendSms = await mobizon.sendSms({
Expand Down
2 changes: 1 addition & 1 deletion __tests__/balance.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mobizon = require('./config');
import mobizon from './config';

describe('Mobizon balance', () => {
it('should receive the account balance', async () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/config/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const mobizon = require('../../src/index');
import mobizon from '../../src';

mobizon.setConfig({
apiServer: 'https://api.mobizon.com.br',
apiKey: process.env.API_KEY,
format: 'json',
});

module.exports = mobizon;
export default mobizon;
32 changes: 19 additions & 13 deletions __tests__/shortlink.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const mobizon = require('./config');
import mobizon from './config';

describe('Mobizon short methods', () => {
const responseValues = [];

it('should create short link', async () => {
const response = await mobizon.shortCreate({
fullLink: 'https://mobizon.com.br',
status: 1,
expirationDate: '',
comment: 'Created short link.',
const response = await mobizon.createShort({
data: {
fullLink: 'https://mobizon.com.br',
status: 1,
expirationDate: '',
comment: 'Created short link.',
},
});

responseValues.push(response.data);
Expand All @@ -17,25 +19,27 @@ describe('Mobizon short methods', () => {
});

it('should throw error when creating short link', async () => {
const response = await mobizon.shortCreate({});
const response = await mobizon.createShort({});

expect(response.code).not.toBe(0);
});

it('should get short link', async () => {
const response = await mobizon.shortGet([responseValues[0].code]);
const response = await mobizon.getShort({
code: responseValues[0].code,
});

expect(response.code).toBe(0);
});

it('should throw error when getting short link', async () => {
const response = await mobizon.shortGet([]);
const response = await mobizon.getShort({});

expect(response.code).not.toBe(0);
});

it('should update short link', async () => {
const response = await mobizon.shortUpdate({
const response = await mobizon.updateShort({
id: responseValues[0].id,
data: {
status: 0,
Expand All @@ -48,19 +52,21 @@ describe('Mobizon short methods', () => {
});

it('should throw an error when updating a short link', async () => {
const response = await mobizon.shortUpdate({});
const response = await mobizon.updateShort({});

expect(response.code).not.toBe(0);
});

it('should delete short link', async () => {
const response = await mobizon.shortDelete([responseValues[0].id]);
const response = await mobizon.deleteShort({
ids: [responseValues[0].id],
});

expect(response.code).toBe(0);
});

it('should throw an error when deleting a short link', async () => {
const response = await mobizon.shortDelete();
const response = await mobizon.deleteShort();

expect(response.code).not.toBe(0);
});
Expand Down
8 changes: 5 additions & 3 deletions __tests__/sms.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mobizon = require('./config');
import mobizon from './config';

describe('Mobizon sms methods', () => {
const recipient = process.env.NUMBER;
Expand All @@ -23,13 +23,15 @@ describe('Mobizon sms methods', () => {
});

it('should list the sms sent by id', async () => {
const response = await mobizon.getSms(responseValues[0].messageId);
const response = await mobizon.getSms({
ids: [responseValues[0].messageId],
});

expect(response.code).toBe(0);
});

it('should throw error when listing sms by id', async () => {
const response = await mobizon.getSms([]);
const response = await mobizon.getSms({});

expect(response.code).not.toBe(0);
});
Expand Down
21 changes: 21 additions & 0 deletions dist/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});exports. default = {
/**
* User API key.
* Each user has their key, it represents their access and allows access to API routes.
*/
apiKey: '',
/**
* User API server depends on user initial registration site.
* Correct API domain could be found in API quick start guide here: https://help.mobizon.com/help/api-docs/sms-api
*/
apiServer: '',
/**
* API response format - possible formats see in allowedFormats
*/
format: '',
/**
* API version.
* Default: v1.
*/
apiVersion: 'v1',
};
23 changes: 23 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _environment = require('./environment'); var _environment2 = _interopRequireDefault(_environment);
var _balance = require('./structures/balance'); var _balance2 = _interopRequireDefault(_balance);
var _shortlink = require('./structures/shortlink'); var _shortlink2 = _interopRequireDefault(_shortlink);
var _sms = require('./structures/sms'); var _sms2 = _interopRequireDefault(_sms);

exports. default = {
environment: _environment2.default,
setConfig({ apiServer, apiKey, format }) {
_environment2.default.apiKey = apiKey;
_environment2.default.format = format || 'json';
_environment2.default.apiServer = apiServer;
},
getBalance: () => _balance2.default.get(),
getSms: (data) => _sms2.default.get(data),
sendSms: (data) => _sms2.default.send(data),
listSms: (data) => _sms2.default.list(data),
getShort: (data) => _shortlink2.default.get(data),
listShort: (data) => _shortlink2.default.list(data),
createShort: (data) => _shortlink2.default.create(data),
deleteShort: (data) => _shortlink2.default.delete(data),
updateShort: (data) => _shortlink2.default.update(data),
getStatsShort: (data) => _shortlink2.default.getstats(data),
};
44 changes: 44 additions & 0 deletions dist/services/mobizon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _axios = require('axios');
var _https = require('https');
var _qs = require('qs');

var _environment = require('../environment'); var _environment2 = _interopRequireDefault(_environment);

exports. default = async (provider, method, postParams, queryParams) => {
const { format, apiVersion, apiKey, apiServer } = _environment2.default;

const request = _axios.create.call(void 0, {
baseURL: `${apiServer}/service`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
httpsAgent: new (0, _https.Agent)({
rejectUnauthorized: false,
}),
});

const queryDefault = _qs.stringify.call(void 0, {
output: format,
api: apiVersion,
apiKey,
});

if (postParams) {
const body = _qs.stringify.call(void 0, postParams);

const { data } = await request.post(
`${provider}/${method}?${queryDefault}`,
body
);

return data;
}

const query = queryParams
? `${_qs.stringify.call(void 0, queryParams)}&${queryDefault}`
: queryDefault;

const { data } = await request.get(`${provider}/${method}?${query}`);

return data;
};
5 changes: 5 additions & 0 deletions dist/structures/balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _mobizon = require('../services/mobizon'); var _mobizon2 = _interopRequireDefault(_mobizon);

exports. default = {
get: () => _mobizon2.default.call(void 0, 'user', 'getownbalance'),
};
10 changes: 10 additions & 0 deletions dist/structures/shortlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _mobizon = require('../services/mobizon'); var _mobizon2 = _interopRequireDefault(_mobizon);

exports. default = {
get: (body) => _mobizon2.default.call(void 0, 'link', 'get', body),
list: (body) => _mobizon2.default.call(void 0, 'link', 'list', body),
create: (body) => _mobizon2.default.call(void 0, 'link', 'create', body),
delete: (body) => _mobizon2.default.call(void 0, 'link', 'delete', body),
update: (body) => _mobizon2.default.call(void 0, 'link', 'update', body),
getstats: (body) => _mobizon2.default.call(void 0, 'link', 'getstats', body),
};
7 changes: 7 additions & 0 deletions dist/structures/sms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _mobizon = require('../services/mobizon'); var _mobizon2 = _interopRequireDefault(_mobizon);

exports. default = {
get: (body) => _mobizon2.default.call(void 0, 'message', 'getsmsstatus', body),
list: (body) => _mobizon2.default.call(void 0, 'message', 'list', body),
send: (query) => _mobizon2.default.call(void 0, 'message', 'sendsmsmessage', null, query),
};
Loading

0 comments on commit 8f116d1

Please sign in to comment.