/** * @param Imagick $image * * @throws \Exception * @return string */ public function upload(Imagick $image) { //finally output the image if it doesn't exist yet if (!$this->exists()) { if (!file_exists(parent::getDirectory())) { mkdir(parent::getDirectory()); } $image->writeImage(parent::getOutputPath()); } $fields = array('k' => urlencode($this->getApiKey()), 'z' => urlencode('poop'), 'f' => '@' . parent::getOutputPath()); //set POST variables $request = $this->getHttpClient()->post(null, array(), $fields, array('exceptions' => false)); $response = $request->send(); switch ($response->getStatusCode()) { case 200: //split the response $output = explode(',', $response->getBody(true)); //Response (upload, success): 0,{url},{id},{size} //Response (failure): -1 //if the response was successful, return the url $this->outputPath = $output[0] == 0 ? $output[1] : ''; break; default: throw new \Exception('Could not upload meme to puu.sh. Response code returned: ' . $response->getStatusCode()); break; } }
/** * @covers MemePuush\Output\File::upload */ public function testUpload() { $imagick = $this->getMock('Imagick', array('writeImage')); $this->object->upload($imagick); }