Skip to content

Commit

Permalink
Fix for inserting new rows with 0 values
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo Ephraim committed Jul 12, 2013
1 parent 4e0bf42 commit 2bf2eba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions examples/example_usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ testsheet.getInfo( function(err, ss_info){


// if auth is set, you can edit. you read the rows while authenticated in order to get the edit feed URLs from google
testsheet.setAuth( 'youremail@gmail.com', 'YOURPASSWORD', function(err){
testsheet.setAuth( 'youremail@gmail.com', '*PASSWORD*', function(err){
if (err) console.log(err);

console.log(' GOOGLE AUTH SUCCESS!' );

// you can also add and read rows by just indicating the worksheet id (starts at 1)
testsheet.addRow( 1, {
testdate: (new Date()).toString('yyyy-MM-dd')
testdate: ( new Date() ).toString('yyyy-MM-dd'),
testnum: 0
})

testsheet.getRows( 2, function(err, rows){
if (err) console.log( err );

// to edit row data, just edit the data and call save()
rows[0].testcount++;
rows[0].testnum++;
rows[0].save();

// you can also delete rows by calling .del()
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module.exports = function( ss_key, auth_id ){
}
});
data_xml += '</entry>';
console.log( data_xml );
self.makeFeedRequest( ["list", ss_key, worksheet_id], 'POST', data_xml, cb );
}

Expand Down Expand Up @@ -215,7 +216,7 @@ var SpreadsheetRow = function( spreadsheet, data, xml ){
data_xml = data_xml.replace('<entry>', "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>");
Object.keys( self ).forEach( function(key) {
if (key.substr(0,1) != '_' && typeof( self[key] == 'string') ){
data_xml = data_xml.replace( new RegExp('<gsx:'+xmlSafeColumnName(key)+'>(.*?)</gsx:'+xmlSafeColumnName(key)+'>'), '<gsx:'+xmlSafeColumnName(key+)'>'+ xmlSafeValue(self[key]) +'</gsx:'+xmlSafeColumnName(key)+'>');
data_xml = data_xml.replace( new RegExp('<gsx:'+xmlSafeColumnName(key)+'>(.*?)</gsx:'+xmlSafeColumnName(key)+'>'), '<gsx:'+xmlSafeColumnName(key)+'>'+ xmlSafeValue(self[key]) +'</gsx:'+xmlSafeColumnName(key)+'>');
}
});
spreadsheet.makeFeedRequest( self['_links']['edit'], 'PUT', data_xml, cb );
Expand All @@ -232,7 +233,7 @@ var forceArray = function(val) {
return [ val ];
}
var xmlSafeValue = function(val){
if (!val) return '';
if ( val == null ) return '';
return String(val).replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Theo Ephraim <theozero@gmail.com> (http://theoephraim.com)",
"name": "google-spreadsheet",
"description": "Google Spreadsheet Data API for Node.js",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/theoephraim/node-google-spreadsheets",
"repository": {
"type": "git",
Expand Down

0 comments on commit 2bf2eba

Please sign in to comment.