diff --git a/src/TwitterOAuth.php b/src/TwitterOAuth.php index db361a9b..2e1f43a3 100644 --- a/src/TwitterOAuth.php +++ b/src/TwitterOAuth.php @@ -317,6 +317,19 @@ public function mediaStatus(string $media_id) ); } + /** + * Get media file attached to direct message. + * + * @param string $url + * @param array $parameters + * + * @return string + */ + public function getFile(string $url, array $parameters = []) + { + return $this->makeRequests($url, 'GET', $parameters, false); + } + /** * Private method to upload media (not chunked) to upload.twitter.com. * @@ -464,7 +477,12 @@ private function http( if (!$json) { $parameters = $this->cleanUpParameters($parameters); } - return $this->makeRequests($url, $method, $parameters, $json); + $result = $this->makeRequests($url, $method, $parameters, $json); + + $response = JsonDecoder::decode($result, $this->decodeJsonAsArray); + $this->response->setBody($response); + + return $response; } /** @@ -477,7 +495,7 @@ private function http( * @param array $parameters * @param bool $json * - * @return array|object + * @return string */ private function makeRequests( string $url, @@ -488,13 +506,11 @@ private function makeRequests( do { $this->sleepIfNeeded(); $result = $this->oAuthRequest($url, $method, $parameters, $json); - $response = JsonDecoder::decode($result, $this->decodeJsonAsArray); - $this->response->setBody($response); $this->attempts++; // Retry up to our $maxRetries number if we get errors greater than 500 (over capacity etc) } while ($this->requestsAvailable()); - return $response; + return $result; } /**