wensleydale / spark
PHP library for the Spark.io API
Requires
- guzzle/guzzle: ~3.7
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-11-09 15:46:25 UTC
README
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.
Turning on a LED using default tinker firmware
$core = SparkCore::make($accessToken);
$core->setPin('D7');
$core->setValue('HIGH');
$core->digitalWrite(); //Will turn on the inbuilt LED
Installing via Composer
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:
require 'vendor/autoload.php';
Managing Tokens
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();
Exceptions
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.
Unit Tests
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