forked from basiclines/GooglePlay-JSAPI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.js
53 lines (50 loc) · 1.33 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var request = require('request');
module.exports = {
/**
* Retrieves information with a given appID
*
* @param Object config
* @prop String appID
* @param Function callback
* @param Object data
*/
getApp: function (config, callback) {
var basePath = "https://play.google.com/store/apps/details?id=";
request(basePath+config.appID, function (error, res, chunk) {
if (!error && res.statusCode == 200) {
var scraper = require('./scrapers/app');
var data = scraper.parse(chunk);
if (typeof callback == 'function') {
callback(JSON.stringify(data));
}
} else {
// call callback anyway
callback(JSON.stringify({
error: res.statusCode
}));
}
});
},
/**
* Retrieves search details for a given name
*
* @param Object config
* @prop String queryStr
* @prop String lang
* @param Function callback
* @param Object data
*/
getSearch: function (config, callback) {
var basePath = "https://play.google.com/store/search?&c=apps&q=" + config.queryStr + "&hl=" + config.lang;
console.log('Fetching url ' + basePath);
request(basePath, function (error, res, chunk) {
if (!error && res.statusCode == 200) {
var scraper = require('./scrapers/search');
var data = scraper.parse(chunk);
if (typeof callback == 'function') {
callback(JSON.stringify(data));
}
}
});
}
};