initial implementation of google play platform

This commit is contained in:
Almir Kadric
2014-08-28 04:21:25 +00:00
parent fbab375820
commit e64281bcf0
11 changed files with 223 additions and 3 deletions

10
lib/https/get.js Normal file
View File

@@ -0,0 +1,10 @@
var https = require('./index');
module.exports = function (url, options, cb) {
options = options || {};
// Set method to GET and call it
options.method = 'GET';
https.request(url, options, null, cb);
};

3
lib/https/index.js Normal file
View File

@@ -0,0 +1,3 @@
exports.request = require('./request');
exports.post = require('./post');
exports.get = require('./get');

26
lib/https/post.js Normal file
View File

@@ -0,0 +1,26 @@
var https = require('./index');
var formUrlencoded = require('form-urlencoded');
module.exports = function (url, options, cb) {
options = options || {};
// Try and extract data and set it's type
var data = null;
try {
if (options.form) {
data = formUrlencoded.encode(options.form);
delete options.form;
options.headers = {
'content-type': 'application/x-www-form-urlencoded',
'content-length': Buffer.byteLength(data)
};
}
} catch (error) {
cb(error);
}
// Set method to POST and call it
options.method = 'POST';
https.request(url, options, data, cb);
};

43
lib/https/request.js Normal file
View File

@@ -0,0 +1,43 @@
var url = require('url');
var https = require('https');
module.exports = function (requestUrl, options, data, cb) {
options = options || {};
var parsedUrl = url.parse(requestUrl);
if (parsedUrl.hostname) {
options.hostname = parsedUrl.hostname;
}
if (parsedUrl.port) {
options.port = parsedUrl.port;
}
if (parsedUrl.path) {
options.path = parsedUrl.path;
}
var req = https.request(options, function (res) {
res.setEncoding('utf8');
var responseData = '';
res.on('data', function (str) {
responseData += str;
});
res.on('end', function () {
if (res.statusCode !== 200) {
return cb(new Error('Received ' + res.statusCode + ' status code with body: ' + responseData));
}
cb(null, responseData);
});
});
req.on('error', cb);
req.end(data);
};