Beispiel #1
0
 /**
  * Performs a OAuth curl request.
  *
  * @param string $url
  * @param array  $params
  * @param string $method
  * @param bool   $multipart
  *
  * @return OAuthResponse
  */
 protected function curlRequest($url, $params = [], $method = 'GET', $multipart = false)
 {
     $curl = curl_init();
     $requestUrl = $url;
     if ($method == 'GET') {
         $requestUrl = $url . '?' . $this->formatQueryString($params);
     } else {
         curl_setopt($curl, CURLOPT_POST, true);
         if ($multipart) {
             $data = $this->buildMultipartContent($params['media_file']);
             $this->setRequestBody($data);
         } else {
             $this->setRequestBody($this->formatQueryString($params));
         }
         curl_setopt($curl, CURLOPT_POSTFIELDS, $this->getRequestBody());
     }
     $this->buildHeaders($method, $url, $params, $multipart);
     curl_setopt_array($curl, [CURLOPT_USERAGENT => $this->userAgent, CURLOPT_CONNECTTIMEOUT => 60, CURLOPT_TIMEOUT => 20, CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $requestUrl, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HEADER => false, CURLINFO_HEADER_OUT => true, CURLOPT_HTTPHEADER => $this->getHeaders()]);
     $response = new OAuthResponse();
     $response->setResponse(curl_exec($curl));
     $response->setCode(curl_getinfo($curl, CURLINFO_HTTP_CODE));
     $response->setInfo(curl_getinfo($curl));
     $response->setError(curl_error($curl));
     $response->setErrno(curl_errno($curl));
     curl_close($curl);
     return $response;
 }
 /**
  * @covers SimplyDO\OAuthResponse::setCode
  * @covers SimplyDO\OAuthResponse::getCode
  */
 public function testShouldGetAndSetCode()
 {
     $this->model->setCode(200);
     $this->assertEquals(200, $this->model->getCode());
 }