Exemple #1
0
<?php

require_once "../main.php";
try {
    $Client = new REST_CLIENT();
    $Client->setMethod(REST_CLIENT::METHOD_POST);
    $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, '[your api key]');
    $Client->setData('<?xml version="1.0" encoding="utf-8"?>  
<request method="invoice.list">  
</request>');
    $result = $Client->request('https://[username].freshbooks.com/api/2.1/xml-in', REST_CLIENT::CONTENT_XML);
    echo '<ul>';
    foreach ($result->invoices->invoice as $invoice) {
        echo '<li>' . $invoice->invoice_id . ': ' . $invoice->organization . ' (' . $invoice->status . ')</li>';
    }
    echo '</ul>';
} catch (Exception $e) {
    echo 'Problems with freshbooks.';
}
Exemple #2
0
try {
    // Create api client instance
    $Client = new REST_CLIENT();
    // Get token to authenticate our requests
    $Client->setMethod(REST_CLIENT::METHOD_GET);
    // This is not required because the default method is GET
    $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, 'Basic ' . base64_encode('[email]:[password]'));
    $result = $Client->request('https://www.pivotaltracker.com/services/v3/tokens/active', REST_CLIENT::CONTENT_XML);
    $token = trim($result->guid);
    // Get activity log
    $Client->reset();
    $Client->addHeader('X-TrackerToken', $token);
    $result = $Client->request('http://www.pivotaltracker.com/services/v3/projects/232211/activities?limit=20', REST_CLIENT::CONTENT_XML);
    // Show activity log
    echo '<ul>';
    foreach ($result->activity as $activity) {
        echo '<li>' . $activity->description . '</li>';
    }
    echo '</ul>';
    // Create a new project
    // We don't need to set the token again because it is still set from the get activity log above
    $Client->setMethod(REST_CLIENT::METHOD_POST);
    $Client->addHeader(REST_CLIENT::HEADER_CONTENT_TYPE, 'application/xml');
    $Client->setData('<project><name>Test project by Api Client</name><iteration_length type="integer">2</iteration_length></project>');
    $result = $Client->request('http://www.pivotaltracker.com/services/v3/projects', REST_CLIENT::CONTENT_XML);
    if (isset($result->id)) {
        echo 'New project is created an has ID: ' . $result->id;
    }
} catch (Exception $e) {
    echo 'Problem while executing!';
}
Exemple #3
0
<?php

include '../../main.php';
try {
    $Client = new REST_CLIENT();
    $Client->setMethod(REST_CLIENT::METHOD_PUT);
    // $Client->useFopen(); // You can also use fopen for this
    $Client->setData(file_get_contents('source.txt'));
    $result = $Client->request('http://192.168.1.101:8080/Source/Projects/PHP/REST_CLIENT/src/Script/Examples/put/action.php');
} catch (Exception $e) {
    echo 'Problem catched.';
}
Exemple #4
0
<?php

require_once "../main.php";
try {
    $Client = new REST_CLIENT();
    $Client->setMethod(REST_CLIENT::METHOD_POST);
    $Client->useFopen();
    $Client->setData(xmlrpc_encode_request("wp.getPages", array(1, '[username]', '[password]')));
    $result = $Client->request('http://neogenlabs.com/wordpress/xmlrpc.php', REST_CLIENT::CONTENT_XMLRPC);
    explore($result);
    echo '<ul>';
    foreach ($result as $page) {
        echo '<li>' . $page['title'] . '</li>';
    }
    echo '</ul>';
} catch (Exception $e) {
    echo 'Problems with freshbooks.';
}