Created
April 26, 2011 06:19
-
-
Save iaindooley/941868 to your computer and use it in GitHub Desktop.
Example Decal API request to build a list of Decal plan costs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('curl_request.class.php'); | |
//update this to point to your install | |
$url = 'http://www.decalcms.com/index.php?h=DecalApi'; | |
$api_key = '597990c64261faa854805f6366f9dcc4f505ed0e'; | |
//formulate the post fields for the request | |
//we'll look at the options in detail below | |
$fields = array('api_key' => $api_key, | |
't' => 'Home', | |
'numitems' => '10', //we only want one page per list | |
); | |
//send off the request using the CurlRequest class | |
$xml = simplexml_load_string(CurlRequest::toUrl($url) | |
->method(CurlRequest::POST) | |
->postFields($fields) | |
->execute()); | |
//The Decal home page has 2 types of component: | |
// | |
// - Plan Stack | |
// - Plan Stack Feature | |
// | |
// The structure of each of these is fixed in the Decal template | |
// so we can reliably work with it without exposing ourselves to | |
// the normal brittleness of screen scraping | |
foreach($xml->page[0]->xpath('.//component[contains(@name,"Plan stack")]') as $price) | |
{ | |
$dollars = $price->xpath('.//h3'); | |
$title = $price->xpath('.//h4'); | |
echo $title[0].' costs: '.$dollars[0]->a.'<br />'.PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment