mirror of
https://github.com/valentineus/iii-client.git
synced 2025-04-28 01:41:25 +03:00
Release of version 0.0.3.
This commit is contained in:
parent
cb354fc098
commit
c43c75e3d1
25
.eslintrc.js
Normal file
25
.eslintrc.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
4
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
]
|
||||
}
|
||||
};
|
@ -59,3 +59,6 @@ typings/
|
||||
|
||||
# Source
|
||||
src/
|
||||
|
||||
# Documentation
|
||||
docs/
|
||||
|
@ -79,4 +79,6 @@ Description of the internal kitchen can be seen on the [documentation page](http
|
||||
Found out a mistake or feel a lack of functionality? [issues](https://github.com/valentineus/iii-client/issues)
|
||||
|
||||
## License
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
[MIT](LICENSE.md). Copyright (c) [Valentin Popov](https://valentineus.link/).
|
@ -1 +0,0 @@
|
||||
theme: jekyll-theme-minimal
|
@ -234,7 +234,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line149">line 149</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line140">line 140</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -471,7 +471,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line98">line 98</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line92">line 92</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -631,7 +631,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line113">line 113</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line106">line 106</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -791,7 +791,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line83">line 83</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line78">line 78</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -951,7 +951,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line128">line 128</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line120">line 120</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -1111,7 +1111,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line175">line 175</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line165">line 165</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -1267,7 +1267,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line14">line 14</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line15">line 15</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -1428,7 +1428,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line50">line 50</a>
|
||||
<a href="index.js.html">index.js</a>, <a href="index.js.html#line48">line 48</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -1635,7 +1635,7 @@
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 02:00:06 GMT+0300 (MSK) using the Minami theme.
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 07:00:49 GMT+0300 (MSK) using the Minami theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
@ -57,7 +57,7 @@
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 02:00:06 GMT+0300 (MSK) using the Minami theme.
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 07:00:49 GMT+0300 (MSK) using the Minami theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
@ -47,12 +47,13 @@
|
||||
|
||||
var http = require('http');
|
||||
|
||||
exports.connect = connect;
|
||||
/**
|
||||
* Connects to the server and returns the connection data.
|
||||
* @param {String} uuid - The bot UUID.
|
||||
* @param {requestCallback} callback - The callback that handles the response.
|
||||
*/
|
||||
var connect = function(uuid, callback) {
|
||||
function connect(uuid, callback) {
|
||||
uuid = uuid || '';
|
||||
|
||||
if (!_verification(uuid)) {
|
||||
@ -64,7 +65,7 @@ var connect = function(uuid, callback) {
|
||||
hostname: 'iii.ru',
|
||||
path: '/api/2.0/json/Chat.init/' + uuid + '/',
|
||||
method: 'GET',
|
||||
}
|
||||
};
|
||||
|
||||
const request = http.request(query, function(response) {
|
||||
var json = '';
|
||||
@ -72,15 +73,12 @@ var connect = function(uuid, callback) {
|
||||
response.on('end', () => callback(json.result));
|
||||
});
|
||||
|
||||
request.on('error', function(error) {
|
||||
console.error('Error connecting to the server!\n', error.message);
|
||||
});
|
||||
request.on('error', (error) => Error(error.message));
|
||||
|
||||
request.end();
|
||||
}
|
||||
|
||||
exports.connect = connect;
|
||||
|
||||
exports.send = send;
|
||||
/**
|
||||
* Send a message to the server and return a response.
|
||||
* @param {Object} raw - The data to send.
|
||||
@ -88,7 +86,7 @@ exports.connect = connect;
|
||||
* @param {String} raw.text - Message text.
|
||||
* @param {requestCallback} callback - The callback that handles the response.
|
||||
*/
|
||||
var send = function(raw, callback) {
|
||||
function send(raw, callback) {
|
||||
raw = raw || {};
|
||||
|
||||
const query = {
|
||||
@ -96,7 +94,7 @@ var send = function(raw, callback) {
|
||||
hostname: 'iii.ru',
|
||||
path: '/api/2.0/json/Chat.request',
|
||||
method: 'POST',
|
||||
}
|
||||
};
|
||||
|
||||
const data = _createPackage(raw);
|
||||
|
||||
@ -106,22 +104,19 @@ var send = function(raw, callback) {
|
||||
response.on('end', () => callback(json));
|
||||
});
|
||||
|
||||
request.on('error', function(error) {
|
||||
console.error('Error sending the package!\n', error.message);
|
||||
});
|
||||
request.on('error', (error) => Error(error));
|
||||
|
||||
request.write(data);
|
||||
request.end();
|
||||
}
|
||||
|
||||
exports.send = send;
|
||||
|
||||
exports._encrypt = _encrypt;
|
||||
/**
|
||||
* Encrypts the incoming data.
|
||||
* @param {String} raw - Decrypted data.
|
||||
* @returns {String} - Encrypted string.
|
||||
*/
|
||||
var _encrypt = function(raw) {
|
||||
function _encrypt(raw) {
|
||||
raw = raw || '';
|
||||
|
||||
var base64 = Buffer.from(raw).toString('base64');
|
||||
@ -129,14 +124,13 @@ var _encrypt = function(raw) {
|
||||
return _merger(string).toString('base64');
|
||||
}
|
||||
|
||||
exports._encrypt = _encrypt;
|
||||
|
||||
exports._decrypt = _decrypt;
|
||||
/**
|
||||
* Decrypts the incoming data.
|
||||
* @param {String} raw - Encrypted data.
|
||||
* @returns {String} - Decrypted string.
|
||||
*/
|
||||
var _decrypt = function(raw) {
|
||||
function _decrypt(raw) {
|
||||
raw = raw || '';
|
||||
|
||||
var string = Buffer.from(raw, 'base64');
|
||||
@ -144,14 +138,13 @@ var _decrypt = function(raw) {
|
||||
return Buffer.from(decrypted, 'base64');
|
||||
}
|
||||
|
||||
exports._decrypt = _decrypt;
|
||||
|
||||
exports._decryptJSON = _decryptJSON;
|
||||
/**
|
||||
* Decrypts an encrypted JSON object.
|
||||
* @param {String} raw - Encrypted data.
|
||||
* @returns {Object} - Decrypted JSON.
|
||||
*/
|
||||
var _decryptJSON = function(raw) {
|
||||
function _decryptJSON(raw) {
|
||||
raw = raw || '';
|
||||
|
||||
var string = raw.toString('ascii');
|
||||
@ -159,14 +152,13 @@ var _decryptJSON = function(raw) {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
exports._decryptJSON = _decryptJSON;
|
||||
|
||||
exports._merger = _merger;
|
||||
/**
|
||||
* Merge and convert a string.
|
||||
* @param {String} raw - The string to convert.
|
||||
* @returns {String} - The converted string.
|
||||
*/
|
||||
var _merger = function(data) {
|
||||
function _merger(data) {
|
||||
data = data || '';
|
||||
|
||||
const salt = Buffer.from('some very-very long string without any non-latin characters due to different string representations inside of variable programming languages');
|
||||
@ -178,8 +170,7 @@ var _merger = function(data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
exports._merger = _merger;
|
||||
|
||||
exports._createPackage = _createPackage;
|
||||
/**
|
||||
* Creates an encrypted package to send.
|
||||
* @param {Object} raw - The data to send.
|
||||
@ -187,7 +178,7 @@ exports._merger = _merger;
|
||||
* @param {String} raw.text - Message text.
|
||||
* @returns {String} - Encrypted string.
|
||||
*/
|
||||
var _createPackage = function(raw) {
|
||||
function _createPackage(raw) {
|
||||
raw = raw || {};
|
||||
|
||||
if (!raw.text) {
|
||||
@ -206,20 +197,17 @@ var _createPackage = function(raw) {
|
||||
return _encrypt(json);
|
||||
}
|
||||
|
||||
exports._createPackage = _createPackage;
|
||||
|
||||
exports._verification = _verification;
|
||||
/**
|
||||
* Validation UUID format string.
|
||||
* @param {String} data - The string to check.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
var _verification = function(data) {
|
||||
function _verification(data) {
|
||||
data = data || '';
|
||||
const regexp = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', 'i');
|
||||
return regexp.test(data);
|
||||
}
|
||||
|
||||
exports._verification = _verification;
|
||||
</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
@ -232,7 +220,7 @@ exports._verification = _verification;
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 02:00:06 GMT+0300 (MSK) using the Minami theme.
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon May 29 2017 07:00:49 GMT+0300 (MSK) using the Minami theme.
|
||||
</footer>
|
||||
|
||||
<script>prettyPrint();</script>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "iii-client",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"description": "Simple API for communicating with the bot of the \"iii.ru\" service.",
|
||||
"homepage": "https://github.com/valentineus/iii-client",
|
||||
"license": "MIT",
|
||||
@ -27,12 +27,14 @@
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.24.1",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"eslint": "^3.19.0",
|
||||
"jsdoc": "^3.4.3",
|
||||
"minami": "^1.2.3"
|
||||
},
|
||||
"scripts": {
|
||||
"check": "eslint ./src/*",
|
||||
"jsdoc": "jsdoc --template ./node_modules/minami --destination ./docs ./src/index.js",
|
||||
"compile": "babel --presets es2015 --minified --no-comments --source-maps --out-dir ./lib/ ./src/",
|
||||
"prepublish": "npm run compile && npm run jsdoc"
|
||||
"prepublish": "npm run check && npm run jsdoc && npm run compile"
|
||||
}
|
||||
}
|
||||
|
52
src/index.js
52
src/index.js
@ -6,12 +6,13 @@
|
||||
|
||||
var http = require('http');
|
||||
|
||||
exports.connect = connect;
|
||||
/**
|
||||
* Connects to the server and returns the connection data.
|
||||
* @param {String} uuid - The bot UUID.
|
||||
* @param {requestCallback} callback - The callback that handles the response.
|
||||
*/
|
||||
var connect = function(uuid, callback) {
|
||||
function connect(uuid, callback) {
|
||||
uuid = uuid || '';
|
||||
|
||||
if (!_verification(uuid)) {
|
||||
@ -23,7 +24,7 @@ var connect = function(uuid, callback) {
|
||||
hostname: 'iii.ru',
|
||||
path: '/api/2.0/json/Chat.init/' + uuid + '/',
|
||||
method: 'GET',
|
||||
}
|
||||
};
|
||||
|
||||
const request = http.request(query, function(response) {
|
||||
var json = '';
|
||||
@ -31,15 +32,12 @@ var connect = function(uuid, callback) {
|
||||
response.on('end', () => callback(json.result));
|
||||
});
|
||||
|
||||
request.on('error', function(error) {
|
||||
console.error('Error connecting to the server!\n', error.message);
|
||||
});
|
||||
request.on('error', (error) => Error(error.message));
|
||||
|
||||
request.end();
|
||||
}
|
||||
|
||||
exports.connect = connect;
|
||||
|
||||
exports.send = send;
|
||||
/**
|
||||
* Send a message to the server and return a response.
|
||||
* @param {Object} raw - The data to send.
|
||||
@ -47,7 +45,7 @@ exports.connect = connect;
|
||||
* @param {String} raw.text - Message text.
|
||||
* @param {requestCallback} callback - The callback that handles the response.
|
||||
*/
|
||||
var send = function(raw, callback) {
|
||||
function send(raw, callback) {
|
||||
raw = raw || {};
|
||||
|
||||
const query = {
|
||||
@ -55,7 +53,7 @@ var send = function(raw, callback) {
|
||||
hostname: 'iii.ru',
|
||||
path: '/api/2.0/json/Chat.request',
|
||||
method: 'POST',
|
||||
}
|
||||
};
|
||||
|
||||
const data = _createPackage(raw);
|
||||
|
||||
@ -65,22 +63,19 @@ var send = function(raw, callback) {
|
||||
response.on('end', () => callback(json));
|
||||
});
|
||||
|
||||
request.on('error', function(error) {
|
||||
console.error('Error sending the package!\n', error.message);
|
||||
});
|
||||
request.on('error', (error) => Error(error));
|
||||
|
||||
request.write(data);
|
||||
request.end();
|
||||
}
|
||||
|
||||
exports.send = send;
|
||||
|
||||
exports._encrypt = _encrypt;
|
||||
/**
|
||||
* Encrypts the incoming data.
|
||||
* @param {String} raw - Decrypted data.
|
||||
* @returns {String} - Encrypted string.
|
||||
*/
|
||||
var _encrypt = function(raw) {
|
||||
function _encrypt(raw) {
|
||||
raw = raw || '';
|
||||
|
||||
var base64 = Buffer.from(raw).toString('base64');
|
||||
@ -88,14 +83,13 @@ var _encrypt = function(raw) {
|
||||
return _merger(string).toString('base64');
|
||||
}
|
||||
|
||||
exports._encrypt = _encrypt;
|
||||
|
||||
exports._decrypt = _decrypt;
|
||||
/**
|
||||
* Decrypts the incoming data.
|
||||
* @param {String} raw - Encrypted data.
|
||||
* @returns {String} - Decrypted string.
|
||||
*/
|
||||
var _decrypt = function(raw) {
|
||||
function _decrypt(raw) {
|
||||
raw = raw || '';
|
||||
|
||||
var string = Buffer.from(raw, 'base64');
|
||||
@ -103,14 +97,13 @@ var _decrypt = function(raw) {
|
||||
return Buffer.from(decrypted, 'base64');
|
||||
}
|
||||
|
||||
exports._decrypt = _decrypt;
|
||||
|
||||
exports._decryptJSON = _decryptJSON;
|
||||
/**
|
||||
* Decrypts an encrypted JSON object.
|
||||
* @param {String} raw - Encrypted data.
|
||||
* @returns {Object} - Decrypted JSON.
|
||||
*/
|
||||
var _decryptJSON = function(raw) {
|
||||
function _decryptJSON(raw) {
|
||||
raw = raw || '';
|
||||
|
||||
var string = raw.toString('ascii');
|
||||
@ -118,14 +111,13 @@ var _decryptJSON = function(raw) {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
exports._decryptJSON = _decryptJSON;
|
||||
|
||||
exports._merger = _merger;
|
||||
/**
|
||||
* Merge and convert a string.
|
||||
* @param {String} raw - The string to convert.
|
||||
* @returns {String} - The converted string.
|
||||
*/
|
||||
var _merger = function(data) {
|
||||
function _merger(data) {
|
||||
data = data || '';
|
||||
|
||||
const salt = Buffer.from('some very-very long string without any non-latin characters due to different string representations inside of variable programming languages');
|
||||
@ -137,8 +129,7 @@ var _merger = function(data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
exports._merger = _merger;
|
||||
|
||||
exports._createPackage = _createPackage;
|
||||
/**
|
||||
* Creates an encrypted package to send.
|
||||
* @param {Object} raw - The data to send.
|
||||
@ -146,7 +137,7 @@ exports._merger = _merger;
|
||||
* @param {String} raw.text - Message text.
|
||||
* @returns {String} - Encrypted string.
|
||||
*/
|
||||
var _createPackage = function(raw) {
|
||||
function _createPackage(raw) {
|
||||
raw = raw || {};
|
||||
|
||||
if (!raw.text) {
|
||||
@ -165,17 +156,14 @@ var _createPackage = function(raw) {
|
||||
return _encrypt(json);
|
||||
}
|
||||
|
||||
exports._createPackage = _createPackage;
|
||||
|
||||
exports._verification = _verification;
|
||||
/**
|
||||
* Validation UUID format string.
|
||||
* @param {String} data - The string to check.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
var _verification = function(data) {
|
||||
function _verification(data) {
|
||||
data = data || '';
|
||||
const regexp = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', 'i');
|
||||
return regexp.test(data);
|
||||
}
|
||||
|
||||
exports._verification = _verification;
|
||||
|
Loading…
x
Reference in New Issue
Block a user