Skip to content

Commit

Permalink
Took the request lib out of the provider check, its impossible to get…
Browse files Browse the repository at this point in the history
… a useful exception out of that thing.
  • Loading branch information
Phil Sturgeon committed Nov 29, 2011
1 parent fa200b4 commit f733cd8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions classes/provider.php
Expand Up @@ -169,9 +169,9 @@ public function access($code, $options = array())
$url = $this->url_access_token();

// Get ready to make a request
$request = \Request::forge($url, 'curl');

$request->set_params($params);
// $request = \Request::forge($url, 'curl');
//
// $request->set_params($params);

switch ($this->method)
{
Expand All @@ -187,6 +187,21 @@ public function access($code, $options = array())

case 'POST':

$postdata = http_build_query($params);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$response = file_get_contents($url, false, $context);

$params = get_object_vars(json_decode($response));

/*
Fuck the request class
try
{
$request->set_header('Accept', 'application/json');
Expand All @@ -210,19 +225,20 @@ public function access($code, $options = array())
// Try to get the actual response, its hopefully an array
$body = $response->body();
*/

break;

default:
throw new \OutOfBoundsException("Method '{$this->method}' must be either GET or POST");
}

if (isset($body['error']))
if (isset($params['error']))
{
throw new \Exception($body);
throw new \Exception($params);
}

return Token::forge($body);
return Token::forge($params);
}

}

2 comments on commit f733cd8

@dhrrgn
Copy link

@dhrrgn dhrrgn commented on f733cd8 Jan 23, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stupid and doesn't work right all the time. You should have used cURL requests...not file_get_contents FFS

@philsturgeon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to but the curl driver for request is all messed up and after spending days trying to hack around making it work I got bored and went with the "get it done in 5 minutes and do something that gets me paid" approach of file_get_contents().

It works most of the time for me. What issues are you getting?

Please sign in to comment.