put() public method

Put
public put ( $url, $data = [] ) : string
$url
$data
return string
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $fileName = 'main';
     $config = new Configuration($this->getConfigPaths(), $fileName);
     $columnId = $input->getArgument('columnId');
     $taskId = $input->getArgument('taskId');
     $domain = $config->getValue('domain');
     $boardId = $config->getValue('boardId');
     $apiToken = $config->getValue('apiToken');
     $url = $this->getUrl($domain, $boardId, $apiToken, $taskId);
     $curl = new Curl();
     $curl->put($url, array('workflow_stage_id' => $columnId));
 }
Beispiel #2
0
 public function put($url = false, $params = false)
 {
     if ($url) {
         if ($params === false) {
             $params = array();
         }
         $curl = new Curl();
         $curl->put($url, $params);
         if ($curl->error) {
             return $curl->errorCode . ': ' . $curl->errorMessage;
         } else {
             return $curl->response;
         }
     }
     return false;
 }
Beispiel #3
0
 /**
  * Make API-call
  */
 private function call($method, $uri, $getParams = array(), $postParams = array(), $authMethod = 'basic')
 {
     $uri = $this->apiEndpoint . $uri;
     $getParams = array_merge($this->apiGetParams, $getParams);
     // Filter empty params
     $getParams = array_filter($getParams, function ($var) {
         return !empty($var);
     });
     // CURL Stuff
     $this->applyCurlOptions($authMethod);
     // Do Request
     switch ($method) {
         case 'get':
             $this->curl->get($uri, $getParams);
             break;
         case 'post':
             $this->curl->post($uri . '?' . http_build_query($getParams), $postParams);
             break;
         case 'delete':
             $this->curl->delete($uri, $getParams);
             break;
         case 'put':
             $this->curl->put($uri . '?' . http_build_query($getParams), $postParams);
             break;
         default:
             throw new \Exception('Requested method behaviour is not defined yet');
     }
     if ($this->curl->curl_error_code == 28) {
         throw new \Exception('Connection timeout', 28);
     }
     $error = $this->curl->error;
     if ($error) {
         throw new \Exception($error . ' (HTTP CODE ' . $this->curl->http_status_code . ')');
     }
     // If JSONP is activated, return instantly
     if (isset($extraParams['callback'])) {
         return $this->curl->response;
     }
     // Otherwise decode and return
     $result = json_decode($this->curl->response);
     return $result;
 }
 public function testSetUrl()
 {
     $data = array('key' => 'value');
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'get');
     $curl->setUrl(Test::TEST_URL);
     $curl->delete($data);
     $this->assertEquals(Test::TEST_URL, $curl->base_url);
     $this->assertEquals('key=value', $curl->response);
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'get');
     $curl->setUrl(Test::TEST_URL);
     $curl->get($data);
     $this->assertEquals(Test::TEST_URL, $curl->base_url);
     $this->assertEquals('key=value', $curl->response);
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'get');
     $curl->setUrl(Test::TEST_URL);
     $curl->head($data);
     $this->assertEquals(Test::TEST_URL, $curl->base_url);
     $this->assertEquals('HEAD /?key=value HTTP/1.1', $curl->request_headers['Request-Line']);
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'get');
     $curl->setUrl(Test::TEST_URL);
     $curl->options($data);
     $this->assertEquals(Test::TEST_URL, $curl->base_url);
     $this->assertEquals('key=value', $curl->response);
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'request_method');
     $curl->setUrl(Test::TEST_URL);
     $curl->patch($data);
     $this->assertEquals(Test::TEST_URL, $curl->base_url);
     $this->assertEquals('PATCH', $curl->response);
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'post');
     $curl->setUrl(Test::TEST_URL);
     $curl->post($data);
     $this->assertEquals(Test::TEST_URL, $curl->base_url);
     $this->assertEquals('key=value', $curl->response);
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'put');
     $curl->setUrl(Test::TEST_URL);
     $curl->put($data);
     $this->assertEquals(Test::TEST_URL, $curl->base_url);
     $this->assertEquals('key=value', $curl->response);
 }
Beispiel #5
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Curl\Curl;
// curl -X PUT -d "id=1&first_name=Zach&last_name=Borboa" "https://httpbin.org/put"
$curl = new Curl();
$curl->put('https://httpbin.org/put', array('id' => 1, 'first_name' => 'Zach', 'last_name' => 'Borboa'));
echo 'Data server received via PUT:' . "\n";
var_dump($curl->response->form);
const CLIENT_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXX';
const REDIRECT_URI = 'https://www.example.com/oauth2callback';
if (php_sapi_name() !== 'cli') {
    throw new Exception('This application must be run on the command line.');
}
// Request authorization from the user.
$auth_url = OAUTH2_AUTH_URL . '?' . http_build_query(array('access_type' => 'offline', 'approval_prompt' => 'force', 'client_id' => CLIENT_ID, 'redirect_uri' => REDIRECT_URI, 'response_type' => 'code', 'scope' => 'https://www.googleapis.com/auth/spreadsheets'));
echo 'Open the following link in your browser:' . "\n";
echo $auth_url . "\n";
echo 'Enter verification code: ';
$code = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$curl = new Curl();
$curl->post(OAUTH2_TOKEN_URI, array('client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'code' => $code, 'grant_type' => 'authorization_code', 'redirect_uri' => REDIRECT_URI));
$access_token = $curl->response;
// Update spreadsheet.
$spreadsheet_id = '1Z2cXhdG-K44KgSzHTcGhx1dY-xY31yuYGwX21F4GeUp';
$range = 'Sheet1!A1';
$url = 'https://sheets.googleapis.com/v4/spreadsheets/' . $spreadsheet_id . '/values/' . $range;
$url .= '?' . http_build_query(array('valueInputOption' => 'USER_ENTERED'));
$data = array('values' => array(array('This is cell A1', 'B1', 'C1', 'and D1')));
$curl = new Curl();
$curl->setHeader('Content-Type', 'application/json');
$curl->setHeader('Authorization', 'Bearer ' . $access_token->access_token);
$curl->put($url, $data);
if ($curl->error) {
    echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage . "\n";
    var_dump($curl);
} else {
    var_dump($curl->response);
}
 public function testSetUrl()
 {
     $data = array('key' => 'value');
     $curl = new Curl();
     $curl->setUrl(Test::TEST_URL);
     $curl->delete($data);
     $this->assertEquals('DELETE /?key=value HTTP/1.1', $curl->requestHeaders['Request-Line']);
     $this->assertEquals(Test::TEST_URL . '?key=value', $curl->effectiveUrl);
     $curl = new Curl();
     $curl->setUrl(Test::TEST_URL);
     $curl->get($data);
     $this->assertEquals('GET /?key=value HTTP/1.1', $curl->requestHeaders['Request-Line']);
     $this->assertEquals(Test::TEST_URL . '?key=value', $curl->effectiveUrl);
     $curl = new Curl();
     $curl->setUrl(Test::TEST_URL);
     $curl->head($data);
     $this->assertEquals('HEAD /?key=value HTTP/1.1', $curl->requestHeaders['Request-Line']);
     $this->assertEquals(Test::TEST_URL . '?key=value', $curl->effectiveUrl);
     $curl = new Curl();
     $curl->setUrl(Test::TEST_URL);
     $curl->options($data);
     $this->assertEquals('OPTIONS /?key=value HTTP/1.1', $curl->requestHeaders['Request-Line']);
     $this->assertEquals(Test::TEST_URL . '?key=value', $curl->effectiveUrl);
     $curl = new Curl();
     $curl->setUrl(Test::TEST_URL);
     $curl->patch($data);
     $this->assertEquals('PATCH / HTTP/1.1', $curl->requestHeaders['Request-Line']);
     $this->assertEquals(Test::TEST_URL, $curl->effectiveUrl);
     $curl = new Curl();
     $curl->setUrl(Test::TEST_URL);
     $curl->post($data);
     $this->assertEquals('POST / HTTP/1.1', $curl->requestHeaders['Request-Line']);
     $this->assertEquals(Test::TEST_URL, $curl->effectiveUrl);
     $curl = new Curl();
     $curl->setUrl(Test::TEST_URL);
     $curl->put($data);
     $this->assertEquals('PUT / HTTP/1.1', $curl->requestHeaders['Request-Line']);
     $this->assertEquals(Test::TEST_URL, $curl->effectiveUrl);
 }
<?php

// PUT a file using chunked data.
// See also "examples/receive_large_file_chunked.php".
require __DIR__ . '/vendor/autoload.php';
use Curl\Curl;
function read_file($ch, $fd, $length)
{
    $data = fread($fd, $length);
    return $data;
}
$filename = 'large_image.png';
$fp = fopen($filename, 'rb');
$curl = new Curl();
$curl->setHeader('Transfer-Encoding', 'chunked');
$curl->setOpt(CURLOPT_UPLOAD, true);
$curl->setOpt(CURLOPT_INFILE, $fp);
$curl->setOpt(CURLOPT_INFILESIZE, filesize($filename));
$curl->setOpt(CURLOPT_READFUNCTION, 'read_file');
$curl->put('http://127.0.0.1:8000/');
fclose($fp);
if ($curl->error) {
    echo 'Error: ' . $curl->errorMessage . "\n";
} else {
    echo 'Success' . "\n";
}