From dcd3f22c453258be18a300b96781c9c70f2c970d Mon Sep 17 00:00:00 2001 From: Morgan Newcomb Date: Mon, 23 Sep 2024 11:39:17 -0400 Subject: [PATCH] refactor request arg retrieval for api requests --- src/api/class-jw-player-api.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api/class-jw-player-api.php b/src/api/class-jw-player-api.php index c782f3e..c1e2319 100644 --- a/src/api/class-jw-player-api.php +++ b/src/api/class-jw-player-api.php @@ -79,17 +79,13 @@ public function request_url( string $last_modified_date, int $batch_size ): stri * @return array */ public function request_args( string $type = '' ): array { - $default_args = [ + return [ 'user-agent' => $this->user_agent(), 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_secret, 'Content-Type' => 'application/json', ], ]; - - return 'vip' === $type - ? $default_args - : array_merge( $default_args, [ 'timeout' => 3 ] ); } /** @@ -147,12 +143,17 @@ public function request_latest_videos( string $updated_after, int $batch_size ): 3, 5, 3, - $this->request_args( 'vip' ) + $this->request_args() ); } else { $api_request = wp_remote_get( $request_url, - $this->request_args() + wp_parse_args( + $this->request_args(), + [ + 'timeout' => 3, + ] + ) ); }