Created
January 5, 2012 18:21
-
-
Save syropian/1566487 to your computer and use it in GitHub Desktop.
Function for obtaining a response from a digest-based API in Laravel. The session must contain a username and password, and you must have MCrypt installed for the Crypter class to work.
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 | |
class API { | |
public static function call($url) { | |
$user = Session::get('username'); | |
$password = Session::get('password'); | |
$process = curl_init($url); | |
curl_setopt($process, CURLOPT_USERPWD, $user.':'.Crypter::decrypt($password)); | |
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); | |
curl_setopt($process, CURLOPT_TIMEOUT, 30); | |
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE); | |
$response = curl_exec($process); | |
$status = curl_getinfo($process); | |
curl_close($process); | |
if ($status['http_code'] != '200'){ | |
return "Authentication Failed"; | |
} | |
else { | |
return $response; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment