Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Services;
- use Illuminate\Config\Repository;
- use Illuminate\Http\Client\PendingRequest;
- use Illuminate\Http\Client\Response;
- use Illuminate\Support\Arr;
- class YandexService
- {
- protected PendingRequest $client;
- protected array $params;
- protected Repository $repository;
- public function __construct()
- {
- $this->setRepository();
- $this->setParams();
- $this->setClient($this->getRepository());
- }
- protected function setRepository(): void
- {
- $repository = new Repository();
- $repository->set('token', config('yandex.token'));
- $repository->set('url', config('yandex.url'));
- $this->repository = $repository;
- }
- public function getRepository(): Repository
- {
- return $this->repository;
- }
- protected function setClient(Repository $repository): void
- {
- $this->client = PendingRequest::withHeaders([
- 'Authorization' => "OAuth {$repository->get('token')}",
- ])->baseUrl($repository->get('url'));
- }
- public function changeClient(Repository $repository): void
- {
- $this->setClient($repository);
- }
- public function getClient(): PendingRequest
- {
- return $this->client;
- }
- protected function setParams(): void
- {
- $this->params = [
- 'lang' => 'ru',
- 'level' => 'video_an_site',
- ];
- }
- public function getParams(): array
- {
- return $this->params;
- }
- public function getStatistics(): Response
- {
- return $this->getClient()->get('statistics/get.json?' . Arr::query($this->getParams()));
- }
- }
Add Comment
Please, Sign In to add comment