2017 © Pedro Peláez
 

library chartbeat-php

PHP library for Chartbeat

image

chartbeat/chartbeat-php

PHP library for Chartbeat

  • Thursday, June 27, 2013
  • by eeroniemi
  • Repository
  • 3 Watchers
  • 6 Stars
  • 3,828 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 3 % Grown

The README.md

chartbeat-php

PHP library to interact with Chartbeat API., (*1)

See great API docs and API explorer from Chartbeat website for more info., (*2)

This library requires PHP >5.3 and cURL extension for PHP to work. Tested with PHP 5.3.15 and 5.4.6, (*3)

Please give feedback, report bugs, fork and contribute., (*4)

Installation

Add chartbeat-php to your composer.json:, (*5)

{
    "require" : {
        "chartbeat/chartbeat-php" : "1.*"
    }
}

Simple test script:, (*6)

require_once ('vendor/autoload.php'); // composer autoloader
$apiKey = '<your api key>';
$host = '<your host>';
$cb = new Chartbeat\Chartbeat($host, $apiKey);

// get monthly max people on site
echo 'Monthly max people on the site: ' . $cb->getMonthlyMaxPeople(); 

You can also do any kind of API query using get() method. First parameter is data endpoint (eg. 'historical/traffic/series'), seconds one contains parameters., (*7)

In here, we get top referer of page which has most visitors right now:, (*8)

$cbData = $cb->get('live/toppages/v3/', array('limit' => 1)); // get all top pages, we want only 1
$topPage = current($cbData->pages); // get first page of the result
var_dump(current($topPage->stats->toprefs)); // output first top referer of page

// outputs:
object(stdClass)#9 (2) {
  ["visitors"]=>
  int(10)
  ["domain"]=>
  string(10) "google.com"
}

Error handling

Every error throws exception Chartbeat\Exception., (*9)

try {
    // set invalid key and try to get data
    $cb->setApiKey('invalidapikey');
    $cb->getMonthlyMaxPeople(); 
} catch (Chartbeat\Exception $ex)
{
    echo "Caught exception: " . $ex->getMessage();
    // will output "Caught exception: Chartbeat API error. Message: No Access, Code: 403"
}

Testing

You can test this library by running example.php with:, (*10)

./example.php <your host> <your API key> 

This will output monthly max people your site, (*11)

The Versions

27/06 2013

dev-master

9999999-dev http://github.com/eeroniemi/chartbeat-php

PHP library for Chartbeat

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Eero Niemi

chartbeat

27/06 2013

1.0.0

1.0.0.0 http://github.com/eeroniemi/chartbeat-php

PHP library for Chartbeat

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Eero Niemi

chartbeat