PHP library for the Spark.io API
PHP library for the Spark.io API.
Makes it incredibly easy to get up and running using the default Tinker firmware or any custom function/variable that is exposed by your core firmware. You can also use the library to access/generate tokens and flash firmware to your core.
More detailed examples will follow shortly but basic operations may be found in the examples directory.
$core = SparkCore::make($accessToken); $core->setPin('D7'); $core->setValue('HIGH'); $core->digitalWrite(); //Will turn on the inbuilt LED
The recommended way to install the library is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php # Add Spark as a dependency php composer.phar require wensleydale/spark:dev-master
After installing, you need to require Composer's autoloader:
You may list all your tokens, generate a token or delete a token
$tokenInstance = SparkCore::token(); $tokenInstance->setUsername('your_spark_username'); $tokenInstance->setPassword('your_spark_password'); $listTokens = $tokenInstance->listTokens();
If there are any issues during the API request a SparkException or SparkTokenException will be thrown which can be caught and managed according to your application needs.
This library uses PHPUnit for unit testing. In order to run the unit tests, you'll first need
to install the dependencies of the project using Composer:
php composer.phar install --dev.
You can then run the tests using
vendor/bin/phpunit. The library comes with a set of mocked responses
from the Spark API