Whoosh Traffic! API v2.0 documentation

API

Contents   ::   API Documentation  »

API

Contents:

A Basic PHP Example

This example is meant to complement the Python based examples, please refer to the PHP cURL Docs and PHP JSON Docs for further explanation of cURL options.

This PHP example will make use of an object oriented cURL wrapper library Parnell wrote for the opensource KohanaPHP framework:

The first thing to keep in mind is that PHP’s cURL implementation will already base64 encode your authorization header value, please use the example below as a reference for your own implementation:

<?php

require 'Curl.php';

# Set your login token and key
$login = "dfjsgIDKsHOskd32dsfw";
$key   = "ksdfjsjf922j2ksdkf.laksdjfkjaj23dskf/fjjsd.dfss/s7O";

# Setup initial cURL options
$options = array
(
    CURLOPT_FAILONERROR      => False,
    CURLOPT_FOLLOWLOCATION   => True,
    CURLOPT_RETURNTRANSFER   => True,
    CURLOPT_FRESH_CONNECT    => True,
    CURLOPT_FORBID_REUSE     => True,
    CURLOPT_POST             => False,
    CURLOPT_URL              => "https://secure.whooshtraffic.com/ranktracker/pairs",
    CURLOPT_HTTPAUTH         => CURLAUTH_BASIC,
    CURLOPT_USERPWD          => $login.":".$key, # cURL base64 encodes it automatically
    CURLOPT_HTTPHEADER       => array("Accept: application/vnd.whoosh.api+json", "Range: offset=0"),
    CURLOPT_SSL_VERIFYHOST   => 2
);

$curl   = new Curl($options);

# Execute the cURL session and ignore cURL errorno "22" so we can branch on HTTP status codes
$result = $curl->execute(array(22));

# Return the status, this defaults to the HTTP status code returned by the session
echo $curl->status() . "<br />";

if ($curl->status() === 200)
{
    echo var_export(json_decode($result));
} else {
    echo $result;
}

Indices and tables

Contents   ::   API Documentation  »