nyc-bookstores/node_modules/feed-tables/package.json

26 lines
7.3 KiB
JSON
Raw Normal View History

2013-05-27 20:45:59 +00:00
{
"name": "feed-tables",
"author": {
"name": "Tomas Vitvar",
"email": "tomas@vitvar.com"
},
"version": "0.1.3",
"description": "A lightweight parser for Google Spreadsheets tables in cells or list feed JSON data formats.",
"keywords": [
"Google Spreadsheets",
"server",
"client",
"Atom feed"
],
"directories": {
"lib": "lib"
},
"main": "lib/feed-tables",
"readme": "# Feed Tables\n\nFeed tables provide lightweight parsers for Google Spreadsheets data available as a table in cells feed or list feed JSON data formats.\nFeed tables work for both Node.js and a client-side JavaScript. Loading the data is out of the scope of this library, the sample code below shows how you can load the data in Node.js \nand in a browser by using JSONP. You can, however, use any other mechanism to access the data including authorization mechanisms. \n\n### Spreadsheet data\n\nYou must have a Google spreadsheet ready. For example, a <a href=\"https://spreadsheets.google.com/spreadsheet/ccc?key=0AoooUkEfVrhldEpRekRVakVYWmJ2U2Z4SFBVZ0M1Nnc\">sample data</a>\ncontains data about people such as for every person in the table there is a name, a street, and a city. \nIn order to use this data, you can access it\nas an atom feed in JSON format either as a <a href=\"https://spreadsheets.google.com/feeds/list/0AoooUkEfVrhldEpRekRVakVYWmJ2U2Z4SFBVZ0M1Nnc/od6/public/basic?alt=json\">list feed</a> or a <a href=\"https://spreadsheets.google.com/feeds/cells/0AoooUkEfVrhldEpRekRVakVYWmJ2U2Z4SFBVZ0M1Nnc/od6/public/basic?alt=json\">cells feed</a>. Note that in order to access a spreadsheet data at such URLs without any authorization, \nyou need to publish your spreadsheet as a Web page (in Google Spreadsheet go to Share -> Publish as a Web Page).\n\n## Usage in Node.js\n\n### Installation\n\n npm install feed-tables\n\n### Loading the data \n\nFirst, you need to load the data from the spreadsheet. In Node.js, you can use\nhttp and url libraries and the following `receive` function:\n\n```js\nvar http = require('http');\nvar url = require('url');\n\nvar receive = function(dataUrl, dataReady) {\n var urlp = url.parse(dataUrl);\n var service = http.createClient(urlp.port ? urlp.port : 80, urlp.hostname);\n var req = service.request('GET', urlp.pathname + urlp.search,\n {'host': urlp.hostname});\n\n var data = null, status = null, finished = false;\n\n req.on('response', function (res) {\n var body = \"\";\n status = res.statusCode;\n\n res.on('data', function (chunk) {\n body += chunk;\n });\n\n res.on('end', function () {\n data = JSON.parse(body);\n if (!finished) {\n finished = true;\n dataReady(data);\n }\n });\n });\n\n req.end();\n\n setTimeout(function() {\n if (!finished) {\n finished = true;\n dataReady(null);\n }\n }, 2000);\n};\n```\n\n### Parsing the data\n\nYou can use either `CellsFeed` or `ListFeed` parser to parse the data. This depends on the format\nof the spreadsheet you want to use. Cells feeds are larger as every spreadsheet cell data \nis in a separated atom feed entry. The `CellsFeed` parser expects that there are names of header fields \nin the first row of the spreadsheet. \n\nThe following code shows how to use the `CellsFeed` parser.\n\n```js\nvar ft = require('feed-tables');\n\nreceive(\"https://spreadsheets.google.com/feeds/cells/0AoooUkEfVrhldEpRekRVakVYWmJ2U2Z4SFBVZ0M1Nnc/od6/public/basic?alt=json\",\n function(data) {\n if (data) {\n var table = new ft.CellsFeed(data); \n for (var r = 0; r < table.length; r++) {\n var row = table.getRow(r);\n console.log(\"name: \" + row.name + \", street: \" + row.street, \" city: \" + row.city + \"\\n\");\n }\n } else\n console.log(\"Timeout while fetching the Google Spreadsheet data.\");\n });\n```\n\nList feeds are much smaller in size as every atom feed entry contains a single row, however, this format\ndoes not contain a row with all the table's header field names, hence you need to provide \nthe header field names expicitly when creating the parser. \n\nTo create the `ListFeed` parser you need to use the List feed url https://spreadsheets.google.com/feeds/list/0AoooUkEfVrhldEpRekRVakVYWmJ2U2Z4SFBVZ0M1Nnc/od6/public/basic?alt=json \nwhen retrieving the spre
"_id": "feed-tables@0.1.3",
"dist": {
"shasum": "ca4d11895af032cf8269f1ea97b7c0d360752f65"
},
"_from": "feed-tables"
}