Skip to content

Commit

Permalink
Removed unnecessary dependency on OAuth common if no authentication i…
Browse files Browse the repository at this point in the history
…s used. And a method for getting the last curl error
  • Loading branch information
Simon Ljungberg committed Jan 20, 2010
1 parent 8a7a515 commit 390e378
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions includes/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class RestClient {
private $authentication = NULL;
private $request_alter = NULL;
private $formatter = NULL;
private $lastError = FALSE;
public $rawResponse;
public $lastResponse;

Expand Down Expand Up @@ -128,6 +129,7 @@ public function execute($ch, $unserialize = TRUE) {
$this->rawResponse = curl_exec($ch);
$res = $this->interpretResponse($this->rawResponse);
$this->lastResponse = $res;
$this->lastError = curl_error($ch);
curl_close($ch);

if ($res->responseCode==200) {
Expand Down Expand Up @@ -162,6 +164,35 @@ private function interpretResponse($res) {

return $obj;
}

/**
* Stolen from OAuth_common
*/
public static function urlencode_rfc3986($input) {
if (is_array($input)) {
return array_map(array('RestClient', 'urlencode_rfc3986'), $input);
} else if (is_scalar($input)) {
return str_replace(
'+',
' ',
str_replace('%7E', '~', rawurlencode($input))
);
} else {
return '';
}
}

/**
* Check for curl error
* Returns FALSE if no error occured
*/
public function getCurlError() {
if (empty($this->lastError)) {
$this->lastError = FALSE;
}
return $this->lastError;
}

}

class RestClientBaseFormatter implements RestClientFormatter {
Expand Down
4 changes: 2 additions & 2 deletions includes/RestClientRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public function toUrl() {
foreach ($this->parameters as $k => $v) {
if (is_array($v)) {
foreach ($v as $va) {
$total[] = OAuthUtil::urlencode_rfc3986($k) . "[]=" . OAuthUtil::urlencode_rfc3986($va);
$total[] = RestClient::urlencode_rfc3986($k) . "[]=" . RestClient::urlencode_rfc3986($va);
}
} else {
$total[] = OAuthUtil::urlencode_rfc3986($k) . "=" . OAuthUtil::urlencode_rfc3986($v);
$total[] = RestClient::urlencode_rfc3986($k) . "=" . RestClient::urlencode_rfc3986($v);
}
}
$out = implode("&", $total);
Expand Down

0 comments on commit 390e378

Please sign in to comment.