sheetsu-node
Installation
npm install sheetsu-node --save
Usage
Generating a Client
You need to create a new sheetsu function, and populate it with your Sheetsu API URL. You can find this URL on Sheetsu Dashboard.
var sheetsu = ; // create a config filevar config = address: '020b2c0f'; // Create new clientvar client = ;
for ES6
; // create a config filevar config = address: '020b2c0f'; // Create new clientvar client = ;
If you have HTTP Basic Authentication turned on for your API, you should pass api_key
and api_secret
here, like:
// create a config filevar config = address: '020b2c0f' api_key: 'YOUR_API_KEY' api_secret: 'YOUR_API_SECRET'; // Create new clientvar client = ;
CRUD
Sheetsu gives you the ability to use full CRUD on your Google Spreadsheet. Remember to populate the first row of every sheet with column names. You can look at example spreadsheet.
Create
To add data to Google Spreadsheets, send a hash or an array of hashes.
// Adds single rowclient; /// Adds bunch of rowsrows = id: 7 name: "Glenn" score: "69" id: 8 name: "Brian" score: "77" id: 9 name: "Joe" score: "45" client;
By default, all writes are performed on the first sheet (worksheet). Pass name of a sheet as a 2nd param to add data to other worksheet.
// Adds single row to worksheet named "Sheet3"client;
On success returns a hash or an array of hashes with created values.
Read
Read the whole sheet
client;
You can pass hash with options
limit
- limit number of resultsoffset
- start from N first recordsearch
- hash with search params (more below)sheet
- get data from named worksheet
// Get first two rows from worksheet named "Sheet2"client; // Get 5th and 6th record from worksheet named "Sheet3"client;
search
To get rows that match search criteria, pass a hash with search params
// Get all rows where column 'id' is 'foo' and column 'value' is 'bar'client; // Get all rows where column 'First name' is 'Peter' and column 'Score' is '42'client; // Get first two row where column 'First name' is 'Peter',// column 'Score' is '42' from sheet named "Sheet3"client;
On success returns an array of hashes.
Update
To update row(s), pass column name and its value which is used to find row(s).
client;
// Update all columns where 'name' is 'Peter' to have 'score' = 99 and 'last name' = 'Griffin'client;
By default, PATCH request is sent, which is updating only values which are in the hash passed to the method. To send PUT request, pass 4th argument being true
. Read more about the difference between PUT and PATCH in our docs.
// Update all columns where 'name' is 'Peter' to have 'score' = 99 and 'last name' = 'Griffin'// Empty all cells which matching, which are not 'score' or 'last name'client;
To perform #update
on different than the first sheet, pass sheet name as a 5th argument.
// Update all columns where 'name' is 'Peter' to have 'score' = 99 and 'last name' = 'Griffin'// In sheet named 'Sheet3'// Empty all cells which matching, which are not 'score' or 'last name'client;
On success returns an array of hashes with updated values.
Delete
To delete row(s), pass column name and its value which is used to find row(s).
// Delete all rows where 'name' equals 'Peter'client;
You can pass sheet name as a 3rd argument. All operations are performed on the first sheet, by default.
// Delete all rows where 'foo' equals 'bar' in sheet 'Sheet3'client;
If success returns :ok
symbol.
Development
Run all tests:
npm test
Run a nyan version test:
npm run nyan-test
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/sheetsu/sheetsu-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Pull Requests
-
Add tests! Your patch won't be accepted if it doesn't have tests.
-
Create topic branches. Please, always create a branch with meaningful name. Don't ask us to pull from your master branch.
-
One pull request per feature. If you want to do more than one thing, please send multiple pull requests.
-
Send coherent history. Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before sending them to us.
Docs
Sheetsu documentation sits on GitHub. We would love your contributions! We want to make these docs accessible and easy to understand for everyone. Please send us Pull Requests or open issues on GitHub.