<?php require_once "../../main.php"; define("GOOGLE_API", "AIzaSyDEqBO9D1tLqSdX3QOtqy6-ZfotMZ5e-6A"); $client = new REST_CLIENT(); $client->setMethod(REST_CLIENT::METHOD_POST); $client->addParam("longUrl", "http://www.amitinside.com/"); $client->addParam("key", GOOGLE_API); $result = $client->request("https://www.googleapis.com/urlshortener/v1/url", REST_CLIENT::CONTENT_JSON); explode($result);
<?php require_once "../main.php"; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); // This is not required because the default method is GET $result = $Client->request('http://marketplace.envato.com/api/v2/popular:codecanyon.json', REST_CLIENT::CONTENT_JSON); explore($result); // Show results /*foreach($result->popular->authors_last_month as $user) { echo '<a href="' . $user->url . '"><img src="' . $user->image . '" alt="' . $user->item . '" /></a>'; }*/ } catch (Exception $e) { echo 'Envato seems to be offline!'; }
<?php include '../../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); $Client->useCertificate(str_replace('\\', '/', getcwd()) . '/cacert.pem'); $result = $Client->request('https://mobilevikings.com/api/1.0/doc/'); echo $result; } catch (Exception $e) { print_r($Client->getErrors()); echo 'Problems with service.'; }
<?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.'; }
<?php ini_set("max_execution_time", 18000); require_once "../../main.php"; define("BING_API", "B91795CF2EB537EC1694547C3B1A4CCE00790E52"); $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); $Client->setTimeout = 18000; $no = range(5717, 5938); $files = array(); foreach ($no as $v) { array_push($files, "C:\\xampp\\htdocs\\REST_SOCKET_CLIENT\\examples\\gtranslate\\file\\" . "AMIT" . "_" . $v . ".log"); } //explore($files); foreach ($files as $file) { $data = file_get_contents($file); $params = array("Sources" => "Translation", "Translation.SourceLanguage" => "Es", "Translation.TargetLanguage" => "en", "Query" => $data); foreach ($params as $key => $value) { $Client->addParam($key, $value); } $result = $Client->request('http://api.bing.net/json.aspx?AppId=' . BING_API, REST_CLIENT::CONTENT_JSON); //explore($result); $reply = $result->SearchResponse->Translation->Results[0]->TranslatedTerm; $reply .= "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n"; $fp = fopen("final_translated.txt", "a+"); $fp1 = fopen("log.txt", "a+"); fwrite($fp, $reply); $file_parse = explode("\\", $file); fwrite($fp1, end($file_parse)); }
<?php include '../../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); //$Client->useFopen(); // Also works with Fopen //$Client->addHeader(REST_CLIENT::HEADER_COOKIE, 'Variable1=Value1; Variable2=Value2;'); // String method $Client->addHeader(REST_CLIENT::HEADER_COOKIE, array('Variable1' => 'Value1', 'Variable2' => 'Value2')); // Array method $result = $Client->request('http://localhost/REST_SOCKET_CLIENT/examples/cookies/endpoint.php'); echo $result; } catch (Exception $e) { echo 'Service seems to be offline!'; }
<?php include '../../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); $Client->useFopen(); // Also works with Fopen $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, 'Basic ' . base64_encode('admin:tester')); $result = $Client->request('http://localhost/REST/Examples/basicauth/secured/index.html'); echo $result; } catch (Exception $e) { echo 'Your username/password combination seems to be wrong!'; }
<?php require_once "../main.php"; $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); $Client->addParam('q', 'microsoft'); $result = $Client->request('http://ajax.googleapis.com/ajax/services/search/web?v=1.0', REST_CLIENT::CONTENT_JSON); explore($result);
<?php include '../main.php'; try { $Client = new REST_CLIENT(); $Client->useFopen(); $Client->setMethod(REST_CLIENT::METHOD_GET); $result = $Client->request('http://404.php.net'); } catch (Exception $e) { // Get more information about the problem //print_r($Client->getErrors()); // Get response headers //print_r($Client->getHeaders()); // Show the user that the service is offline echo 'Service seems to be offline!'; }
<?php include '../../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); $Client->setTimeout(1); $result = $Client->request('[url to sleep script here]sleep.php'); } catch (Exception $e) { echo 'Request timeout'; }
<?php include '../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); // This is not required because the default method is GET //$Client->useFopen(); // Also works with Fopen $Client->addHeader(REST_CLIENT::HEADER_CUSTOMREQUEST, 'GET /CMD_API_SHOW_USERS? HTTP/1.0'); $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, 'Basic ' . base64_encode('[username]:[password]')); $result = $Client->request('[direct admin url]:2222', REST_CLIENT::CONTENT_QUERYSTRING); print_r($result); } catch (Exception $e) { echo 'Can\'t connect to DirectAdmin!'; }
<?php require_once "../../main.php"; $client = new REST_CLIENT(); $client->setMethod(REST_CLIENT::METHOD_GET); $headers = array("CURLOPT_USERAGENT" => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5", "CURLOPT_HTTPHEADER" => array("Content-Type: application/x-www-form-urlencoded", "Accept: */*"), "CURLOPT_POST" => TRUE, "CURLOPT_FOLLOWLOCATION" => TRUE, "CURLOPT_RETURNTRANSFER" => TRUE, "CURLOPT_AUTOREFERER" => true, "CURLOPT_SSL_VERIFYPEER" => false, "CURLOPT_MAXREDIRS" => 0); foreach ($headers as $k => $v) { $client->addHeader($k, $v); } $url = "http://wwwa.way2sms.com/jsp/logout.jsp"; $result = $client->request($url, REST_CLIENT::CONTENT_PLAIN); print_r($result);
<?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.'; }
<?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.'; }
<?php include '../main.php'; 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; }
<?php require_once "../main.php"; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); // This is not required because the default method is GET $Client->setParams(array('vq' => 'codecanyon', 'orderby' => 'viewCount')); $result = $Client->request('http://gdata.youtube.com/feeds/api/videos', REST_CLIENT::CONTENT_XML); // Show results echo '<ul>'; foreach ($result->entry as $item) { echo '<li><a href="' . $item->link[0]['href'] . '">' . trim($item->title) . '</a></li>'; } echo '</ul>'; } catch (Exception $e) { echo 'YouTube seems to be offline!'; }
<?php include '../../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_POST); $Client->addParam('file', "@" . dirname(__FILE__) . "/test.txt"); $result = $Client->request('[the url to the action file here]action.php'); print_r($result); } catch (Exception $e) { echo 'Problem catched.'; }