Example #1
0
 /**
  * Upload photo to the Twitter
  *
  * @param string $file
  * @param string|null $status
  *
  * @return Utils\ArrayHash
  *
  * @throws Exceptions\FileNotFoundException
  * @throws Exceptions\InvalidArgumentException
  * @throws OAuth\Exceptions\ApiException|static
  */
 public function uploadMedia($file, $status = NULL)
 {
     if (!is_file($file)) {
         throw new Exceptions\FileNotFoundException("File '{$file}' does not exists. Please provide valid path to file.");
     }
     if ($status !== NULL && !is_string($status)) {
         throw new Exceptions\InvalidArgumentException("Status text '{$status}' have to be a string. Please provide valid status text.");
     }
     if ($status !== NULL) {
         $post = ['media[]' => new \CURLFile($file), 'status' => $status];
         $result = $this->post('statuses/update_with_media.json', [], $post);
         return $result instanceof Utils\ArrayHash ? $result : new Utils\ArrayHash();
     } else {
         // Add file to post params
         $post = ['media' => new \CURLFile($file)];
         $response = $this->httpClient->makeRequest(new Api\Request($this->consumer, $this->config->createUrl('upload', 'media/upload.json'), Api\Request::POST, $post, [], $this->getAccessToken()), 'HMAC-SHA1');
         if ($response->isOk() && $response->isJson() && ($data = Utils\ArrayHash::from($response->toArray()))) {
             return $data;
         } else {
             $ex = $response->toException();
             throw $ex;
         }
     }
 }
Example #2
0
 /**
  * @return string
  */
 public function getUrl()
 {
     return (string) $this->config->createUrl('oauth', 'authenticate', $this->getQueryParams());
 }