Setting up the bundle
Download the library
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require hans-peter-ording/sleeper-api-client
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Use the client
To make use of the sleeper api client, you only need to install some bundles of your choice for:
PSR-18 compatible HTTP client (e.g. Symfony HTTP client)
PSR-7 compatible library (e.g. Nyholm PSR 7 implementation)
If these prerequisites are met, you can simply use the SleeperApiClientFactory to get a fully qualified instance of SleeperApiClient:
1<?php
2// MyCustomClientUsage.php
3
4use HansPeterOrding\SleeperApiClient\ApiClient\SleeperApiClient;
5use HansPeterOrding\SleeperApiClient\ApiClient\SleeperApiClientFactory;
6use HansPeterOrding\SleeperApiClient\ApiClient\SleeperApiClientInterface;
7
8class SleeperApiClientUsage
9{
10 public function initSleeperApiClient(): SleeperApiClientInterface
11 {
12 $sleeperApiClient = (new SleeperApiClientFactory())->getSleeperApiClient();
13
14 return $sleeperApiClient;
15 }
16}
You can now use the SleeperApiClient to request resources from the sleeper api:
1<?php
2// MyCustomClientUsage.php
3
4use HansPeterOrding\SleeperApiClient\ApiClient\SleeperApiClient;
5use HansPeterOrding\SleeperApiClient\ApiClient\SleeperApiClientFactory;
6use HansPeterOrding\SleeperApiClient\ApiClient\SleeperApiClientInterface;
7use HansPeterOrding\SleeperApiClient\Dto\SleeperDraft;
8
9class SleeperApiClientUsage
10{
11 public function initSleeperApiClient(): SleeperApiClientInterface
12 {
13 $sleeperApiClient = (new SleeperApiClientFactory())->getSleeperApiClient();
14
15 return $sleeperApiClient;
16 }
17
18 public function getMyDrafts(): array
19 {
20 $client = $this->initSleeperApiClient();
21
22 return $client->user()->listDrafts('my-sleeper-user-id', 2022);
23 }
24}