public function testExplodeAssocWithCustomGlueArgumentsReturnsCorrectArrayValue() { $string = 'some_key:dummyvalue;another_key:anothervalue'; $expectedArray = ['some_key' => 'dummyvalue', 'another_key' => 'anothervalue']; $explodedValue = explode_assoc($string, ':', ';'); assertThat($explodedValue, is(equalTo($expectedArray))); }
private function sendRequest($uri, $httpMethod, $postData = null, $extraHeaders = null, $isDownload = false, $returnHeaders = false, $isContentXML = true, $returnHTTPCode = false) { $uri = trim($uri); // create an associative array from each key/value url query param pair. $params = array(); $pieces = explode('?', $uri); if (isset($pieces[1])) { $params = explode_assoc('=', '&', $pieces[1]); } // urlencode each url parameter key/value pair $tempStr = $pieces[0]; foreach ($params as $key => $value) { $tempStr .= '&' . urlencode($key) . '=' . urlencode($value); } $uri = preg_replace('/&/', '?', $tempStr, 1); $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->oauth_token, $httpMethod, $uri, $params); $request->sign_request($this->sig_method, $this->consumer, $this->oauth_token); $auth_header = $request->to_header(); $headers = array($auth_header, 'GData-Version: 3.0'); if ($isContentXML) { $headers = array_merge($headers, array('Content-Type: application/atom+xml')); } if (is_array($extraHeaders)) { $headers = array_merge($headers, $extraHeaders); } $curl = curl_init($uri); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); switch ($httpMethod) { case 'GET': curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); break; case 'POST': curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); break; case 'PUT': $headers[] = 'If-Match: *'; curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpMethod); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); break; case 'DELETE': $headers[] = 'If-Match: *'; curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpMethod); break; default: curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); } if ($isDownload) { $tmpFile = OC_Helper::tmpFile(); $handle = fopen($tmpFile, 'w'); curl_setopt($curl, CURLOPT_FILE, $handle); } if ($returnHeaders) { curl_setopt($curl, CURLOPT_HEADER, true); } $result = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($result) { // TODO https://developers.google.com/google-apps/documents-list/#handling_api_errors // TODO Log error messages if ($httpCode <= 308) { if ($isDownload) { return $tmpFile; } else { if ($returnHTTPCode) { return array('result' => $result, 'code' => $httpCode); } else { return $result; } } } } return false; }
/** * Modify credentials attribute before access it from outside the model. * * @param string $value * @return array */ public function getCredentialsAttribute($value) { return explode_assoc($value, '=', ';'); }
preg_match('/oauth_token=(.*)&oauth_token_secret=(.*)/', $response, $matches); $_SESSION['access_token'] = urldecode(@$matches[1]); $_SESSION['token_secret'] = urldecode(@$matches[2]); echo json_encode(array('html_link' => $req->to_url(), 'base_string' => $req->get_signature_base_string(), 'response' => $response, 'authorization_header' => $req->to_header())); exit; // ajax request, just stop exec break; // Fetch data. User has valid access token. // Fetch data. User has valid access token. case 'execute': $feedUri = trim($feedUri); // create an associative array from each key/value url query param pair. $params = array(); $pieces = explode('?', $feedUri); if (isset($pieces[1])) { $params = explode_assoc('=', '&', $pieces[1]); } // urlencode each url parameter key/value pair $tempStr = $pieces[0]; foreach ($params as $key => $value) { $tempStr .= '&' . urlencode($key) . '=' . urlencode($value); } $feedUri = preg_replace('/&/', '?', $tempStr, 1); $req = OAuthRequest::from_consumer_and_token($consumer, $oauth_token, $http_method, $feedUri, $params); $req->sign_request($sig_method, $consumer, $oauth_token, $privKey); $auth_header = $req->to_header(); // decide where to put the oauth_* params (Authorization header or in URL) if ($_REQUEST['oauth_params_loc'] == 'query') { $feedUri = $req->to_url(); $auth_header = null; }