Fetch new google spreadsheet published page as parsed data
(For older spreadsheet, see Ghostsheet)
Example:
name | age:integer | active:bool | |
---|---|---|---|
John | 23 | john@example.com | true |
Tom | 18 | tom@example.com | false |
Then publish the spreadhseet as web page.
Note your spreadsheet's key (like: 00X_xxxXX_0xXxxXx00XXXxx-xxXXxX0-XxXxXx0XxxX)
Available types:
- string (default)
- integer, int
- boolean, bool
- float, double
- json
require "the/path/to/ghostsheet/phplib/Ghostsheet.php";
$gs = new Ghostsheet();
$data = $gs->load("00X_xxxXX_0xXxxXx00XXXxx-xxXXxX0-XxXxXx0XxxX");
if(! $data){
die("Failed");
}
var_dump($data);
Configure options
Get data by specified mode (load|fetch|cache|update)
- If cache file is alive, get the content of cache file.
- If cache file doesn't exist or lifetime expires, fetch new data from remote, save it as cache file.
- Forcely fetch data from remote.
- This doesn't save it as cache.
- This ignores cache lifetime
- Forcely get data from cache.
- If cache file doesn't exists, returns null.
- This ignores cache lifetime
- Forcely fetch data from remote and save it as cache
- This ignores cache lifetime
- Interface for Ajax request
$vars
acceptsmode
andkey
- cache_suffix :String ... Extention of cache file
- cache_dir :String ... Directory to save cache file
- cache_lifetime :Integer ... Cache file lifetime
- url :String ... Spreadsheet publish URL
- timeout :Integer ... Timeout setting for CURL
Though interfaces of the class are almost the same as PHP's one,
methods return not object, but deferred-like object.
Returned object has methods like done()
, fail()
and then()
.
var gs = new (require("ghostsheet"));
gs.load("00X_xxxXX_0xXxxXx00XXXxx-xxXXxX0-XxXxXx0XxxX")
.then(function(data){
console.log(data);
}, function(){
console.error("Failed");
});
This just fetch file and save data as JSON file.
grunt.initConfig({
ghostsheet: {
dev: {
files: {
"./data/mydata.json": "00X_xxxXX_0xXxxXx00XXXxx-xxXXxX0-XxXxXx0XxxX"
}
}
}
});
grunt.loadNpmTasks("ghostsheet");