dosomething / stathat
Simple API wrapper for StatHat.
Installs: 5 052
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 14
Forks: 1
Open Issues: 4
Requires
- php: >=5.4.0
Suggests
- laravel/laravel: Allows shared configuration through the Laravel 5 service container.
This package is auto-updated.
Last update: 2024-12-07 15:58:50 UTC
README
This is a simple, modern API wrapper for StatHat. It also includes optional support for usage as a service in Laravel 5.
Installation
Install with Composer:
"require": { "dosomething/stathat": "^2.0.0" }
Usage
In vanilla PHP, require the Client
class and create a new instance with your credentials.
use DoSomething\StatHat\Client as StatHat; $stathat = new StatHat([ 'user_key' => '<your_user_key>', // required for count() and value() 'ez_key' => 'your_ez_key@example.com', // required for ezCount() and ezValue() 'access_token' => 'ABC123abc', // required for AlertsAPI 'prefix' => 'appname - ', // optional! will be prepended to EZ stat names 'debug' => false, // optional! will prevent sending stats if true. ]); // And go! $stathat->ezCount('<stat_name>', 1); $stathat->ezValue('<stat_name>', 15); $stathat->count('<stat_key>', 1); $stathat->value('<stat_key>', 9);
Laravel Usage
Laravel support is built-in. Simply add a service provider & facade alias to your config/app.php
:
'providers' => [ // ... DoSomething\StatHat\StatHatServiceProvider::class, ], 'aliases' => [ // ... 'StatHat' => DoSomething\StatHat\Facades\StatHat::class ],
Finally, add your keys to the config/services.php
configuration array:
'stathat' => [ 'user_key' => '<your_user_key>', // required for count() and value() 'ez_key' => 'your_ez_key@example.com', // required for ezCount() and ezValue() 'prefix' => 'appname - ', // optional! will be prepended to EZ stat names 'debug' => env('APP_DEBUG'), // optional! will prevent sending stats in debug mode. ],
The StatHat
facade will now be accessible from anywhere in your application:
StatHat::ezCount('<stat_name>', 1); StatHat::ezValue('<stat_name>', 15); StatHat::count('stat_key', 1); StatHat::value('stat_key', 9);
License
©2016 DoSomething.org. StatHat-PHP is free software, and may be redistributed under the terms specified in the LICENSE file. The name and logo for DoSomething.org are trademarks of Do Something, Inc and may not be used without permission.