Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options visibility & projection #25

Merged
merged 1 commit into from
Mar 28, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@ var GOOGLE_FEED_URL = "https://spreadsheets.google.com/feeds/";

// NOTE: worksheet IDs start at 1

module.exports = function( ss_key, auth_id ){
module.exports = function( ss_key, auth_id, options ){
var self = this;
var google_auth;

var google_auth = null;
var visibility = "public";
var projection = "values";

this.setAuthAndDependencies = function( auth ) {
google_auth = auth;
if ( options!=null && "visibility" in options ) {
visibility = options.visibility;
}
else {
visibility = google_auth ? 'private' : 'public';
}
if ( options!=null && "projection" in options ) {
projection = options.projection;
}
else {
projection = google_auth ? 'full' : 'values';
}
}

var xml_parser = new xml2js.Parser({
// options carried over from older version of xml2js -- might want to update how the code works, but for now this is fine
explicitArray: false,
Expand All @@ -22,9 +40,13 @@ module.exports = function( ss_key, auth_id ){
throw new Error("Spreadsheet key not provided.");
}
if ( auth_id ){
google_auth = auth_id;
self.setAuthAndDependencies(auth_id)
}

this.setAuthId = function(auth_id) {
self.setAuthAndDependencies(auth_id);
}

this.setAuth = function( username, password, cb ){
var new_auth = new GoogleClientLogin({
email: username,
Expand All @@ -33,7 +55,7 @@ module.exports = function( ss_key, auth_id ){
accountType: GoogleClientLogin.accountTypes.google
})
new_auth.on(GoogleClientLogin.events.login, function(){
google_auth = new_auth.getAuthId();
self.setAuthAndDependencies(new_auth.getAuthId());
cb( null, new_auth );
})
new_auth.on(GoogleClientLogin.events.error, function(err){
Expand Down Expand Up @@ -142,8 +164,6 @@ module.exports = function( ss_key, auth_id ){
url = url_params;
} else if ( Array.isArray( url_params )){
//used for get and post requets
var visibility = google_auth ? 'private' : 'public';
var projection = google_auth ? 'full' : 'values';
url_params.push( visibility, projection );
url = GOOGLE_FEED_URL + url_params.join("/");
}
Expand Down