This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
forked from hhhonzik/GooglePlay-JSAPI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.js
51 lines (48 loc) · 1.36 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
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, config.appID);
if (typeof callback == 'function') {
return callback(error, JSON.stringify(data));
}
}
if (typeof callback == 'function') {
return callback(error);
}
});
},
/**
* 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));
}
}
});
}
};