Example #1
0
 /**
  * @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;
     }
 }
Example #2
0
 /**
  * @covers MemePuush\Output\AbstractOutput::addHashInput
  * @covers MemePuush\Output\AbstractOutput::getFilename
  * @covers MemePuush\Output\AbstractOutput::getHash
  * @covers MemePuush\Output\File::getDirectory
  * @covers MemePuush\Output\File::getOutputPath
  */
 public function testGetOutputPathWithHash()
 {
     $this->object->addHashInput('testing123');
     $this->object->addHashInput('testing456');
     $this->assertEquals(File::PATH . '50640732.jpg', $this->object->getOutputPath());
 }