X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/d2570fcd9d41934299fdd07e7c714fa5b97a5cbd..613d09d06d7bab3c6d91fd1b5b231e54c7304480:/src/shpub/Request.php diff --git a/src/shpub/Request.php b/src/shpub/Request.php index 32e25de..e7c3b77 100644 --- a/src/shpub/Request.php +++ b/src/shpub/Request.php @@ -56,7 +56,7 @@ class Request $data['url'] = $this->url; } if ($this->type !== null) { - $data['type'] = 'h-' . $this->type; + $data['type'] = array('h-' . $this->type); } if (count($this->properties)) { $data['properties'] = $this->properties; @@ -93,6 +93,17 @@ class Request $cp = new CurlPrinter(); $cp->show($this->req, $this->uploadsInfo, $this->dedicatedBody); } + + if ($this->cfg->dryRun && $this->req->getMethod() != 'GET') { + //do not run any modifying queries + //fake a successful response + $res = new \HTTP_Request2_Response('HTTP/1.1 200 OK', false); + $res->parseHeaderLine('Content-type: text/plain'); + $res->parseHeaderLine('Location: http://example.org/fake-response'); + $res->appendBody('Fake --dry-run response'); + return $res; + } + $res = $this->req->send(); if (intval($res->getStatus() / 100) != 2) { @@ -108,7 +119,7 @@ class Request ); $shown = false; - if ($res->getHeader('content-type') == 'application/json') { + if (Util::getMimeType($res) == 'application/json') { $errData = json_decode($res->getBody()); if (!isset($errData->error)) { Log::err('Error response does not contain "error" property'); @@ -143,11 +154,21 @@ class Request } /** + * Add file upload + * * @param string $fieldName name of file-upload field * @param array $fileNames list of local file paths + * + * @return void */ public function addUpload($fieldName, $fileNames) { + if ($this->directUpload && $this->sendAsJson) { + throw new \Exception( + 'Cannot do direct upload with JSON requests' + ); + } + if ($this->host->endpoints->media === null || $this->directUpload ) { @@ -174,6 +195,10 @@ class Request } /** + * Execute the file upload + * + * @param string $fileName File path + * * @return string URL at media endpoint */ public function uploadToMediaEndpoint($fileName) @@ -211,7 +236,7 @@ class Request { if ($isHtml) { $this->addProperty( - 'content', ['html' => $text] + 'content', [['html' => $text]] ); } else { $this->addProperty('content', $text); @@ -224,6 +249,8 @@ class Request * * @param string $key Parameter name * @param string|array $values One or multiple values + * + * @return void */ public function addProperty($key, $values) {