Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gdata-js

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gdata-js - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

62

gdata.js
var querystring = require('querystring');
var request = require('request');
var https = require('https');
var EventEmitter = require('events').EventEmitter;
var URL = require('url');
var oauthBase = 'https://accounts.google.com/o/oauth2';

@@ -50,5 +51,20 @@

var reqUrl = url + '?' + querystring.stringify(params);
request.get({uri:reqUrl}, function(err, resp, body) {
if(resp.statusCode === 401) {
console.error('401 baby!!');
doRequest(url, params, function(err, body) {
callback(err, body);
});
};
function doRequest(url, params, callback) {
var path = URL.parse(url).pathname + '?' + querystring.stringify(params);
var options = {
host: 'www.google.com',
port: 443,
path: path,
method: 'GET'
};
var httpsReq = https.request(options, function(httpsRes) {
if(httpsRes.statusCode === 401) {
console.error('401, baaaaby!');
refreshToken(function(err, result) {

@@ -61,14 +77,20 @@ if(!err && result && !result.error && result.access_token) {

});
} else if(!err && body) {
try {
body = JSON.parse(body);
} catch(e) {
callback(e, body);
return;
}
callback(null, body);
} else {
callback(err, body);
var data = '';
httpsRes.on('data', function(moreData) {
data += moreData;
});
httpsRes.on('close', function() {
try {
callback(null, JSON.parse(data.toString()));
} catch(err) {
callback(err, null);
}
})
}
});
httpsReq.on('error', function(e) {
callback(e, null);
});
httpsReq.end();
}

@@ -95,2 +117,3 @@

function doPost(body, callback) {

@@ -105,5 +128,12 @@ var options = {

var httpsReq = https.request(options, function(httpsRes) {
httpsRes.on('data', function(data) {
callback(null, JSON.parse(data));
});
if(httpsRes.statusCode === 200) {
httpsRes.on('data', function(data) {
callback(null, JSON.parse(data.toString()));
});
} else {
httpsRes.on('data', function(data) {
console.error("refreshing token -- statusCode !== 200, yoikes! data:", data.toString());
callback(data.toString());
});
}
});

@@ -110,0 +140,0 @@ httpsReq.write(querystring.stringify(body));

{
"name": "gdata-js",
"description": "Simple OAuth 2.0 GData API client",
"version": "0.0.5",
"version": "0.0.6",
"author": "Simon Murtha-Smith <simon@murtha-smith.com>",

@@ -10,3 +10,3 @@ "keywords": ["google", "gdata"],

"repository" : {"type": "git" , "url": "http://github.com/smurthas/gdata-js.git" },
"engines": { "node": ">=0.4.6 <=0.4.11" }
"engines": { "node": ">=0.4.6 <0.5.0" }
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc