arthurnumen / fastly
Provides a PHP client for the Fastly API
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0@dev
Requires (Dev)
- phpspec/phpspec: ~2.0
This package is not auto-updated.
Last update: 2024-12-11 21:03:42 UTC
README
Installation via Composer
The recommended method to install Fastly-PHP is through Composer.
-
Add
fastly/fastly
as a dependency in your project'scomposer.json
:{ "require": { "fastly/fastly": "~0.2" } }
-
Download and install Composer:
curl -s http://getcomposer.org/installer | php
-
Install your dependencies:
php composer.phar install --no-dev
-
Require Composer's autoloader
Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process:
<?php require 'vendor/autoload.php'; $adapter = new GuzzleAdapter('api_key'); $client = new Fastly($adapter);
You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at getcomposer.org.
You'll notice that the installation command specified --no-dev
. This prevents Composer from installing the various testing and development dependencies. For average users, there is no need to install the test suite. If you wish to contribute to development, just omit the --no-dev
flag to be able to run tests.
Example
$adapter = new GuzzleAdapter('api_key'); $fastly = new Fastly($adapter); $result = $fastly->send('GET', 'stats?from=1+day+ago'); $result = $fastly->purgeAll('some_service_id');
$result
is an instance of Psr\Http\Message\ResponseInterface
Adapters
This packages uses Guzzle as the default http client.
To use a different http client an adapter class that implements implementing Fastly\Adapter\AdapterInterface
should be provided.
Testing
There is a class provided in order to fake Fastly so it can be used for testing:
$fastly = new FastlyFake(); $result = $fastly->send('GET', 'stats?from=1+day+ago'); $result = $fastly->purgeAll('some_service_id'); $fastly->getCall(0); // Will return array('send', 'GET', 'stats?from=1+day+ago', array()) $fastly->getCall(1); // Will return array('purgeAll', 'some_service_id', array());
Tests
Run tests with bin/phpspec run
TODO
docs consistantly formatted docs
License
This package uses the MIT License (MIT). Please see LICENSE
for more information.