Skip to content

Instantly share code, notes, and snippets.

@datapolitical
Forked from esseguin/gist:3310332
Created September 13, 2012 22:50
Show Gist options
  • Save datapolitical/3718319 to your computer and use it in GitHub Desktop.
Save datapolitical/3718319 to your computer and use it in GitHub Desktop.
Sample summary gist for PHP on Mashape
<?php
//Step 1 - Requre the client library
require_once("Bitly.php");
//Step 2 - Instantiate a new client object
$bitly = new Bitly("MY_PUBLIC_KEY", "MY_PRIVATE_KEY", "MY_API_KEY", "MY_LOGIN");
//Step 3 - Return a MashapeResponse object by calling a method
$response = $bitly->getShortenedUrl("http://mashape.com/docs/consume/php");
//Step 4- Consume the data in a MashapeResponse object
echo $response->statusCode; // should be "200"
echo $response->headers; // A string showing the headers of the response
//Parsed response data is is inside of a property called body
echo $response->body->shortenedUrl;
if ($response->statusCode == "200") {
// $response->body will be a stdClass representing the parsed response
echo "Shortened URL: " . $response->body->shortenedUrl;
} else {
// $response->rawBody will be a string representing the unparsed response
echo "Problem with request. Response: " . $response->rawBody;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment