Created
April 12, 2011 14:22
-
-
Save gavinr/915578 to your computer and use it in GitHub Desktop.
The Ravelry Yarn Store Search Authentication implemented in PHP
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 | |
// Ravelry API PHP Example | |
// | |
// This example builds the URL and echos the JSON | |
// data from the Ravelry API to the page. | |
// | |
// Implementation of these instructions: | |
// http://www.ravelry.com/groups/ravelry-api/pages/API-Documentation#extra_signing | |
$secret = 'xxxxx'; // your secret key | |
$data = array(); | |
$data['access_key'] = 'xxxxx'; // your access key | |
$data['query'] = 'yarn me'; // the store search query for full text search | |
$data['shop_type_id'] = '1'; // restrict shop type, 1 = Local Yarn Store | |
$data['timestamp'] = date('c'); // gets the current date/time | |
$string = 'http://api.ravelry.com' . '/shops/search.json?' . http_build_query($data); | |
$signature = base64_encode(hash_hmac('sha256', $string, $secret, true)); | |
$data['signature'] = $signature; | |
$final = http_build_query($data); | |
$final = 'http://api.ravelry.com' . '/shops/search.json?' . $final; | |
// Begin CURL section - getting the response from the URL that | |
// was built above. | |
$ch = curl_init(); | |
// set URL and other appropriate options | |
curl_setopt($ch, CURLOPT_URL, $final); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
// grab URL and pass it to the browser | |
curl_exec($ch); | |
// close cURL resource to free up system resources | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment