diff --git a/package.json b/package.json index 104d855..1b460a4 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "homepage": "https://github.com/FrankAst/sms-sender", "license": "MIT", "dependencies": { - "axios": "^0.18.0", "isomorphic-fetch": "^2.2.1", "mongoose": "^5.0.4", "babel-runtime": "^6.26.0" diff --git a/src/index.js b/src/index.js index 2c504ff..d41e933 100644 --- a/src/index.js +++ b/src/index.js @@ -3,5 +3,3 @@ export { default as Smsc } from './transporters/Smsc'; export { default as Sns } from './transporters/Sns'; export { default as Mobizon } from './transporters/Mobizon'; -export { default as PlayMobile } from './transporters/PlayMobile'; -export { default as Aero } from './transporters/Aero'; diff --git a/src/transporters/Aero.js b/src/transporters/Aero.js deleted file mode 100644 index 5561238..0000000 --- a/src/transporters/Aero.js +++ /dev/null @@ -1,90 +0,0 @@ -// @flow -import 'isomorphic-fetch'; -import axios from 'axios'; -import type { SendSmsResponseT, GetStatusResponseT, SmsStatusT, ProviderI } from '../definitions'; - -type CredentialsT = {| - email: string, - apiKey: string, -|}; - -export default class PlayMobile implements ProviderI { - credentials: CredentialsT; - - constructor(credentials: CredentialsT) { - this.credentials = credentials; - } - - // make request to Aero API - async _send(cmd: 'sms/send' | 'sms/status', params: Object): Promise { - const { email, apiKey } = this.credentials || {}; - const extendedParams = { - ...params, - }; - const url = `https://${email}:${apiKey}@gate.smsaero.ru/v2/${cmd}`; - try { - const res = await axios.get(url, { - params: extendedParams, - }); - return res.data; - } catch (e) { - return { error: e.response.status, errMsg: e.response.statusText }; - } - } - // eslint-disable-next-line class-methods-use-this - _prepareStatus(status: number): SmsStatusT { - switch (status) { - case 2: - return 'error'; - case 6: - return 'error'; - case 0: - return 'pending'; // - case 4: - return 'pending'; // - Waiting for sending - case 8: - return 'pending'; // - Given to operator - case 1: - return 'ok'; // - Delivered - case 3: - return 'ok'; // - Delivered - default: - return 'error'; - } - } - - // send message - async sendSms(phone: string, message: string): Promise { - const params = { - number: phone, - text: message, - sign: 'SMS Aero', - channel: 'DIRECT', - }; - const rawResponse = await this._send('sms/send', params); - const res = { - messageId: `${rawResponse.id}-${phone}`, - rawResponse, - }; - return res; - } - - // get status of message (messageId format: id-phoneNumber) - async getStatus(messageId: string): Promise { - const params = { - id: messageId.trim().split('-')[0], - }; - const rawResponse = await this._send('sms/status', params); - const res = { - status: this._prepareStatus(rawResponse.status), - rawResponse, - }; - return res; - } - - // get current provider name - // eslint-disable-next-line class-methods-use-this - getProviderName(): string { - return 'Aero'; - } -} diff --git a/src/transporters/PlayMobile.js b/src/transporters/PlayMobile.js deleted file mode 100644 index 82e4ee0..0000000 --- a/src/transporters/PlayMobile.js +++ /dev/null @@ -1,117 +0,0 @@ -// @flow -import 'isomorphic-fetch'; -import axios from 'axios'; - -import type { SendSmsResponseT, GetStatusResponseT, SmsStatusT, ProviderI } from '../definitions'; - -type CredentialsT = {| - url: string, - in: string, - password: string, -|}; - -export default class PlayMobile implements ProviderI { - credentials: CredentialsT; - - constructor(credentials: CredentialsT) { - this.credentials = credentials; - } - - // make request to PlayMobile API - async _send(cmd: 'send' | 'get-status', params: Object): Promise { - const { login, password, url } = this.credentials || {}; - const stringToEncode = `${login}:${password}`; - try { - const response = await axios({ - method: 'post', - url: `${url}/${cmd}`, - data: params, - headers: { - 'Content-Type': 'application/json', - Authorization: `Basic ${Buffer.from(stringToEncode).toString('base64')}`, - }, - }); - return cmd === 'get-status' - ? { body: response.data } - : { statusCode: response.status, body: response.data }; - } catch (e) { - return { - statusCode: e.response.status, - errMsg: (e.response && e.response.statusText) || ' ', - }; - } - } - - // get more detailed description on https://smsc.kz/api/http/status_messages/statuses/#menu - // eslint-disable-next-line class-methods-use-this - _prepareStatus(status: string): SmsStatusT { - switch (status) { - case 'failed': - return 'error'; // - Not delivered - case 'notDelivered': - return 'pending'; // - Waiting for sending - case 'deferred': - return 'pending'; // - Given to operator - case 'transmitted': - return 'ok'; // - Delivered - case 'delivered': - return 'ok'; // - Delivered - default: - return 'error'; - } - } - - // send message - async sendSms(phone: string, message: string): Promise { - const mesId = Math.floor(100000 + Math.random() * 900000); - const params = this.createParams({ - mesId, - phone, - message, - }); - const rawResponse = await this._send('send', params); - const res = { - messageId: `${mesId}-${phone}`, - rawResponse, - }; - return res; - } - - // get status of message (messageId format: id-phoneNumber) - async getStatus(messageId: string): Promise { - const params = { - 'message-id': [messageId.trim().split('-')[0]], - }; - const rawResponse = await this._send('get-status', params); - const res = { - status: this._prepareStatus(rawResponse.status), - rawResponse, - }; - return res; - } - - // get current provider name - // eslint-disable-next-line class-methods-use-this - getProviderName(): string { - return 'PlayMobile'; - } - // eslint-disable-next-line class-methods-use-this - createParams(options): Object { - const { mesId, phone, message } = options || {}; - return { - messages: [ - { - 'message-id': mesId, - recipient: phone, - sms: { - ttl: '300', - originator: 'smsSender', - content: { - text: message, - }, - }, - }, - ], - }; - } -}