Skip to content

Commit

Permalink
Merge pull request #7 from m4tthumphrey/master
Browse files Browse the repository at this point in the history
Set OAuth::remote() to use \Request::forge() with cURL.
  • Loading branch information
Phil Sturgeon committed Apr 23, 2012
2 parents 763e704 + 5c9e03e commit 5b5b660
Showing 1 changed file with 5 additions and 35 deletions.
40 changes: 5 additions & 35 deletions classes/oauth.php
Expand Up @@ -41,43 +41,13 @@ abstract class OAuth {
*/
public static function remote($url, array $options = NULL)
{
// The transfer must always be returned
$options[CURLOPT_RETURNTRANSFER] = TRUE;
$request = \Request::forge($url, array('driver' => 'curl'))
->set_options($options)
->execute();

// Open a new remote connection
$remote = curl_init($url);

// Set connection options
if ( ! curl_setopt_array($remote, $options))
{
throw new Exception('Failed to set CURL options, check CURL documentation: http://php.net/curl_setopt_array');
}

// Get the response
$response = curl_exec($remote);

// Get the response information
$code = curl_getinfo($remote, CURLINFO_HTTP_CODE);

if ($code AND ($code < 200 OR $code > 299))
{
$error = $response;
}
elseif ($response === FALSE)
{
$error = curl_error($remote);
}

// Close the connection
curl_close($remote);

if (isset($error))
{
throw new Exception(sprintf('Error fetching remote %s [ status %s ] %s', $url, $code, $error));
}

return $response;
return $request->response();
}

/**
* RFC3986 compatible version of urlencode. Passing an array will encode
* all of the values in the array. Array keys will not be encoded.
Expand Down

0 comments on commit 5b5b660

Please sign in to comment.