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" } | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7777
164
1