Skip to content

Instantly share code, notes, and snippets.

@chriscalip
Created July 29, 2015 00:50
Show Gist options
  • Save chriscalip/cea464425b4d391e4fb9 to your computer and use it in GitHub Desktop.
Save chriscalip/cea464425b4d391e4fb9 to your computer and use it in GitHub Desktop.
<?php
class checkGR
{
public $prop = array();
function __construct($title) {
$ret = $this->callGR($title);
$xml = new SimpleXMLElement($ret);
$this->prop = $this->parseXML($xml);
}
public function parseXML(SimpleXMLElement $xml) {
$json = json_encode( (array)$xml->search );
return json_decode($json);
}
public function callGR($newval)
{
$ch = curl_init();
$ret = curl_setopt($ch, CURLOPT_URL, "https://www.goodreads.com/search.xml");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'key=XXXXXX=' . urlencode($newval));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($ch);
return $ret;
}
}
$title = 'Dune';
$obj = new checkGR($title);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment