From 8dcb58039396d897d6d935f80a53f8737a3544f8 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Thu, 22 Jun 2023 11:03:15 +0300 Subject: [PATCH] Add the authenticated API fetcher and sender. --- app/DotsAPI/Fetcher/v2/AuthApiFetcher.php | 42 ++++++++++++++++++++++ app/DotsAPI/Fetcher/v2/AuthApiSender.php | 44 +++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 app/DotsAPI/Fetcher/v2/AuthApiFetcher.php create mode 100644 app/DotsAPI/Fetcher/v2/AuthApiSender.php diff --git a/app/DotsAPI/Fetcher/v2/AuthApiFetcher.php b/app/DotsAPI/Fetcher/v2/AuthApiFetcher.php new file mode 100644 index 0000000..e2f035d --- /dev/null +++ b/app/DotsAPI/Fetcher/v2/AuthApiFetcher.php @@ -0,0 +1,42 @@ +get( + $apiUrl, + [ + 'headers' => [ + 'Api-Auth-Token' => $apiAuthToken, + 'Api-Token' => $apiToken, + 'Api-Account-Token' => $apiAccountToken, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + 'query' => [ + 'v'=> '2.0.0', + ], + ] + ); + + $data = json_decode($response->getBody()->getContents(), true); + + if($field == '') + return $data; + + return $data[$field]; + } +} diff --git a/app/DotsAPI/Fetcher/v2/AuthApiSender.php b/app/DotsAPI/Fetcher/v2/AuthApiSender.php new file mode 100644 index 0000000..aff9cdd --- /dev/null +++ b/app/DotsAPI/Fetcher/v2/AuthApiSender.php @@ -0,0 +1,44 @@ +post( + $apiUrl, + [ + GuzzleHttp\RequestOptions::JSON => $json, + 'headers' => [ + 'Api-Auth-Token' => $apiAuthToken, + 'Api-Token' => $apiToken, + 'Api-Account-Token' => $apiAccountToken, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + 'query' => [ + 'v'=> '2.0.0', + ], + ] + ); + + $data = json_decode($response->getBody()->getContents(), true); + + if($field == '') + return $data; + + return $data[$field]; + } +}