<?php
 
include_once "Sit/Http.php";
 
class Rest_Api extends Sit_Http
 
{
 
    const URL = "https://example.com";
 
    const ACCOUNT_ID = "secretAccount";
 
    const USER = "secretUser";
 
    const PASSWORD = "secretPassword";
 
 
    /**
 
     * Method to get some really awesome information
 
     */
 
    public function getInformation()
 
    {
 
        $url = Rest_Api::URL . "/api/" . Rest_Api::ACCOUNT_ID;
 
        parent::__construct($url);
 
        $this->setAuthentication(Rest_Api::USER, Rest_Api::PASSWORD);
 
        $return = $this->execute();
 
        $this->close();
 
        return $return;
 
    }
 
}
 
 
 
$api = new Rest_Api();
 
$result = $api->getInformation();
 
print_r($result);
 
 
/*
 
This will print something like:
 
 
Array
 
(
 
    [result] => stdClass Object
 
        (
 
            [status] => ok
 
            [contents] => stdClass Object
 
                (
 
                    [information] => true
 
                )
 
 
        )
 
 
    [headers] => Array
 
        (
 
            [url] => https://example.com/api/secretAccount
 
            [content_type] => application/json;charset=UTF-8
 
            [http_code] => 200
 
            [header_size] => 739
 
            [request_size] => 152
 
            [filetime] => -1
 
            [ssl_verify_result] => 0
 
            [redirect_count] => 0
 
            [total_time] => 0.516501
 
            [namelookup_time] => 0.009794
 
            [connect_time] => 0.016837
 
            [pretransfer_time] => 0.054574
 
            [size_upload] => 0
 
            [size_download] => 199
 
            [speed_download] => 385
 
            [speed_upload] => 0
 
            [download_content_length] => 199
 
            [upload_content_length] => 0
 
            [starttransfer_time] => 0.516425
 
            [redirect_time] => 0
 
            [certinfo] => Array
 
                (
 
                )
 
 
            [redirect_url] => 
 
            [request_header] => GET /api/secretAccount HTTP/1.1
 
Authorization: Basic c2VjcmV0VXNlcjpzZWNyZXRQYXNzd29yZA==
 
Host: example.com
 
Accept: */*
 
 
 
        )
 
 
 |