Download the PHP package emilianozublena/sheetsu-php without Composer
On this page you can find all versions of the php package emilianozublena/sheetsu-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emilianozublena/sheetsu-php
More information about emilianozublena/sheetsu-php
Files in emilianozublena/sheetsu-php
Package sheetsu-php
Short Description PHP 5.6 Library for the Sheetsu API http://sheetsu.com
License
Informations about the package sheetsu-php
sheetsu-php
Installation
The Sheetsu PHP Library is available through Composer.
You can edit your composer.json file or just hit this command in your terminal
Usage
Instantianting the Sheetsu Client
You need to instantiate the main Sheetsu object and give the SheetID You can find this URL on Sheetsu Dashboard. Remember to use composer's autoload.
If you have HTTP Basic Authentication turned on for your API, you should pass key
and secret
here, like:
Initialize library
If you need, you can reinitialize (or initialize) the library after creation
Collection-Model
The Sheetsu PHP Library comes with a small implementation of a Collection abstract data type.
Models are units of Collections (in this case, each Model represents a Row of the given sheet).
Instead of giving arrays to the Sheetsu Client (for CRUD operations), you can do something like this:
Collections and Models are the 2 objects that you are going to get every time you call the api too.
Create
To add data to Google Spreadsheets, send an array, an array of arrays, or more simply, work with Models or Collections ;)
After call is made, returns a Response object.
Read
Read the whole sheet
Read function allows 2 parameters
limit
- limit number of resultsoffset
- start from N first record
search
To get rows that match search criteria, pass an array with criteria
Update
To update row(s), pass column name and its value which is used to find row(s) and an array or model with the data to update.
By default, PATCH request is sent, which is updating only values which are in the collection passed to the method. To send PUT request, pass 4th argument being true
. Read more about the difference between PUT and PATCH in sheetsu docs.
Delete
To delete row(s), pass column name and its value which is used to find row(s).
Change Active Sheet
If you need to change the sheet you're working on, you can do it by using the sheet function and passing the new sheetsu id
You can also chain this function with others, like so:
Go back to using the whole spreadsheet again
If you need to use the whole spreadsheet is easy:
You can also chain this function with others, like so:
Response, Connection & Error Handling
The Sheetsu PHP Library handles the connection through the Connection class. This class uses cURL for making connections and uses the Response class as returns. The Response object is the one responsible for giving the collections, models or errors (or any other response from the last call) Error handling is also made through the Response object (Response uses the ErrorHandler class to abstract the try/catch block and is tightly coupled to the ErrorException php class)
Unit Testing with PHPUnit
This library has above 97% of code coverage. Some of the test are not using mock objects, this is in our to-do list and hope we'll be doing it so. The tests are prepared to be used with PHPUnit and the test suite is configured via XML, so you'll only need to execute PHPUnit in your forked version of this repo like so:
TODO
- [x] Define and implement ErrorHandler to leverage the final user from handling http status code's
- [x] Make this repository work as package with Composer
- [x] Create Unit Test with at least 80% coverage (currently in 91%)
- [x] Add ignore_case to search
- [x] Add a way to manage the active sheet used
- [ ] Create mock objects for tests
- [ ] Make class agnostic in such a way that Collection & Model classes are replaceable for others (or maybe for a ORM like Eloquent)