From f52f864984543bdb594efdee1ae6454b733e9724 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Mon, 5 Apr 2021 18:00:26 +0300 Subject: [PATCH 1/5] add file method --- src/TwitterOAuth.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/TwitterOAuth.php b/src/TwitterOAuth.php index db361a9b..35a066e2 100644 --- a/src/TwitterOAuth.php +++ b/src/TwitterOAuth.php @@ -464,7 +464,24 @@ 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; + } + + /** + * Get media file attached to direct message. + * + * @param string $url + * @param array $parameters + * @return string + */ + function file(string $url, array $parameters) + { + return $this->makeRequests($url, 'GET', $parameters, false); } /** @@ -477,7 +494,7 @@ private function http( * @param array $parameters * @param bool $json * - * @return array|object + * @return string */ private function makeRequests( string $url, @@ -488,13 +505,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; } /** From 97410704c0748b03c9315d348ed797d65a22d67c Mon Sep 17 00:00:00 2001 From: Valeriy Date: Tue, 6 Apr 2021 09:30:23 +0300 Subject: [PATCH 2/5] rename file to getFile --- src/TwitterOAuth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TwitterOAuth.php b/src/TwitterOAuth.php index 35a066e2..bcf73304 100644 --- a/src/TwitterOAuth.php +++ b/src/TwitterOAuth.php @@ -479,7 +479,7 @@ private function http( * @param array $parameters * @return string */ - function file(string $url, array $parameters) + function getFile(string $url, array $parameters) { return $this->makeRequests($url, 'GET', $parameters, false); } From 05076f4fa1e7ec750d9878e476f6aa46d73e35f8 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Tue, 6 Apr 2021 11:40:27 +0300 Subject: [PATCH 3/5] make getFile parameters optional --- src/TwitterOAuth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TwitterOAuth.php b/src/TwitterOAuth.php index bcf73304..fe15174e 100644 --- a/src/TwitterOAuth.php +++ b/src/TwitterOAuth.php @@ -479,7 +479,7 @@ private function http( * @param array $parameters * @return string */ - function getFile(string $url, array $parameters) + function getFile(string $url, array $parameters = []) { return $this->makeRequests($url, 'GET', $parameters, false); } From 2188c499f20ea0d253336346a00c6d96e18d4dc2 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Tue, 6 Apr 2021 12:46:52 +0300 Subject: [PATCH 4/5] move getFile to other public methods --- src/TwitterOAuth.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/TwitterOAuth.php b/src/TwitterOAuth.php index fe15174e..67e41cf6 100644 --- a/src/TwitterOAuth.php +++ b/src/TwitterOAuth.php @@ -317,6 +317,18 @@ 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. * @@ -472,18 +484,6 @@ private function http( return $response; } - /** - * Get media file attached to direct message. - * - * @param string $url - * @param array $parameters - * @return string - */ - function getFile(string $url, array $parameters = []) - { - return $this->makeRequests($url, 'GET', $parameters, false); - } - /** * * Make requests and retry them (if enabled) in case of Twitter's problems. From 1fa3d7b819117253b4cdb107f0838a412b5ebba0 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Tue, 6 Apr 2021 12:47:40 +0300 Subject: [PATCH 5/5] reformat PHPDoc --- src/TwitterOAuth.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TwitterOAuth.php b/src/TwitterOAuth.php index 67e41cf6..2e1f43a3 100644 --- a/src/TwitterOAuth.php +++ b/src/TwitterOAuth.php @@ -321,7 +321,8 @@ public function mediaStatus(string $media_id) * Get media file attached to direct message. * * @param string $url - * @param array $parameters + * @param array $parameters + * * @return string */ public function getFile(string $url, array $parameters = [])