public function getDetails($isbn = null)
 {
     if ($isbn != null && apiUtils::isValidISBN($isbn)) {
         $url = MessageFormatter::formatMessage("nl_NL", BookloveApi::baseUrl . BookloveApi::editionInfoEndpoint, array($this->apikey, $isbn));
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($ch);
         curl_close($ch);
         if ($response !== false) {
             return $response;
         }
         return null;
     }
 }
Exemple #2
0
        $app->response->headers->set('Content-Type', 'application/json');
        $app->response->setBody($details);
    } else {
        $response = $bookLoveApi->findBooksByTitle($q);
        if ($response != null) {
            $responseArray = json_decode($response, true);
            if ($responseArray['resultcode'] == 'SUCCESS') {
                $app->response->setBody($response);
            }
        } else {
            $app->response->setStatus(404);
        }
    }
});
$app->get('/v1/book/:query', function ($q) use($app, $bookLoveApi) {
    if (apiUtils::isValidISBN($q)) {
        $nurCode = NurApi::getByISBN($q);
        $details = $bookLoveApi->getDetails($q);
        if ($details != null) {
            $arrDetails = json_decode($details, true);
            if ($arrDetails['resultcode'] == "SUCCESS" && $nurCode != null) {
                $description = NurApi::getDescription($nurCode);
                $arrDetails['nur'] = array('code' => intval($nurCode), 'description' => $description);
            }
            $details = json_encode($arrDetails);
        }
        $app->response->headers->set('Content-Type', 'application/json');
        $app->response->setBody($details);
    } else {
        $app->response->setStatus(400);
    }