PHP implementation for the lookup methof of iTunes API

<?php /** * iTunes API to search apps */ class ITunesApi { var $api = "https://itunes.apple.com/"; /** * Lookup an app on the iTunes store by the given id * * @param type $id The app id to lookup * @return boolean False if it fails, the result otherwise */ public function lookup($id) { $endpoint = $this->api."lookup?id=".$id; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $endpoint); curl_setopt($cURL, CURLOPT_HTTPGET, true); curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($cURL, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' )); $result = json_decode(curl_exec($cURL)); curl_close($cURL); if ($result->resultCount > 0) { return $result->result; } else { return false; } } }

1 Response

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.