yandex-predictor
Advanced tools
Comparing version 0.0.5 to 0.2.1
@@ -1,53 +0,50 @@ | ||
const request = require('request'); | ||
const request = require("request"); | ||
module.exports = class Client { | ||
constructor(key) { | ||
this.apikey = key; | ||
} | ||
constructor(key) { | ||
this.apikey = key; | ||
this.header = { | ||
"User-Agent": "Super Agent/0.0.1", | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}; | ||
this.method = 'GET' | ||
} | ||
getLangs(callback, type = 'json') { | ||
if (type == 'xml') { | ||
this.urlQuery = 'https://predictor.yandex.net/api/v1/predict/getLangs?key=' + this.apikey; | ||
} else { | ||
this.urlQuery = 'https://predictor.yandex.net/api/v1/predict.json/getLangs?key=' + this.apikey; | ||
} | ||
var options = { | ||
url: this.urlQuery, | ||
method: 'GET', | ||
headers: { | ||
'User-Agent': 'Super Agent/0.0.1', | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
} | ||
request(options, function (error, response, body) { | ||
async getLangs(callback) { | ||
this.urlQuery = | ||
"https://predictor.yandex.net/api/v1/predict.json/getLangs?key=" + | ||
this.apikey; | ||
request({ | ||
url: this.urlQuery, | ||
method: this.method, | ||
headers: this.header | ||
}, (error, response, body) => { | ||
if (!error && response.statusCode == 200) { | ||
callback(body); | ||
} | ||
else | ||
console.log(error); | ||
}) | ||
} | ||
let langObj = JSON.parse(body); | ||
callback(langObj); | ||
} else console.log(error); | ||
}); | ||
} | ||
complete(callback, q, lang = 'en', type = 'json', limit = 1) { | ||
if (type == 'xml') { | ||
this.urlQuery = 'https://predictor.yandex.net/api/v1/predict/complete?key=' + this.apikey + '&q=' + q + '&lang=' + lang + '&type=' + type + '&limit=' + limit; | ||
} else { | ||
this.urlQuery = 'https://predictor.yandex.net/api/v1/predict.json/complete?key=' + this.apikey + '&q=' + q + '&lang=' + lang + '&type=' + type + '&limit=' + limit; | ||
} | ||
var options = { | ||
url: this.urlQuery, | ||
method: 'GET', | ||
headers: { | ||
'User-Agent': 'Super Agent/0.0.1', | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
} | ||
request(options, function (error, response, body) { | ||
async complete(q, callback, lang = "en", limit = 5) { | ||
request({ | ||
url: "https://predictor.yandex.net/api/v1/predict.json/complete?key=" + | ||
this.apikey + | ||
"&q=" + | ||
encodeURI(q) + | ||
"&lang=" + | ||
lang + | ||
"&type=json" + | ||
"&limit=" + | ||
limit, | ||
method: this.method, | ||
headers: this.header | ||
}, (error, response, body) => { | ||
if (!error && response.statusCode == 200) { | ||
callback(body); | ||
} | ||
else | ||
console.log(error); | ||
}) | ||
} | ||
} | ||
let resObj = JSON.parse(body) | ||
callback(resObj); | ||
} else console.log(error); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "yandex-predictor", | ||
"version": "0.0.5", | ||
"description": "Client API for Yandex Predictor", | ||
"version": "0.2.1", | ||
"description": "The API Client for Yandex Predictor", | ||
"main": "client.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
# Yandex Predictor | ||
Yandex.Prediсtor is an application that prompts the most likely continuation of words or phrases typed by the user. It simplifies text entry, especially on mobile devices. In this case, the predictor takes into account possible typos. You can use it with this NPM package. | ||
> Yandex.Prediсtor is an application that prompts the most likely continuation of words or phrases typed by the user. It simplifies text entry, especially on mobile devices. In this case, the predictor takes into account possible typos. You can use it with this NPM package. | ||
@@ -20,27 +20,24 @@ Follow this list | ||
// example of using getLangs method | ||
ya.getLangs((res) => { | ||
console.log(res); // Callback func with response | ||
}, 'json' ); | ||
ya.getLangs((langsObj) => { // callback with the Object of all languages in ISO | ||
console.log(langsObj); | ||
}); | ||
``` | ||
| Param | Type | Default | | ||
| ------------- |:-------------:| -----:| | ||
| callback | func(res) | - | | ||
| type | string ('json', 'xml')| 'json' | | ||
| Param | Type | Default | | ||
| ------------- |:---------------------:| --------:| | ||
| callback | func(obj) | - | | ||
## complete | ||
Get the complete of phrase | ||
```javascript | ||
// example of using getLangs method | ||
ya.complete((res) => { | ||
console.log(res); // Callback func with response | ||
}, 'hello w', 'json' ); | ||
// example of using complete method | ||
ya.complete('Кахаю ц', (obj) => { | ||
console.log(obj); // | ||
}, 'be', 10); | ||
``` | ||
| Param | Type | Default | | ||
| ------------- |:-------------:| -----:| | ||
| callback | func(res) | - | | ||
| q | string | -| | ||
| lang | string | 'en'| | ||
| type | string ('json', 'xml')| 'json' | | ||
| limit | int| 1| | ||
| Param | Type | Default | | ||
| ------------- |:---------------------:| --------:| | ||
| q | string | - | | ||
| callback | func(obj) | - | | ||
| lang | string | 'en' | | ||
| limit | int | 5 | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4651
48
43