Http
in package
implements
HttpInterface
uses
HttpTrait
HTTP client for the "Magic: The Gathering Developers" REST API, built the same way DiscordPHP talks to `discord.com` (rate-limit buckets, driver, retry) but pointed at `api.magicthegathering.io`. The API is read-only and unauthenticated, so no token is required.
Tags
Table of Contents
Interfaces
- HttpInterface
Constants
- BASE_URL : string = 'https://api.magicthegathering.io/v' . self::HT...
- MTG API base URL.
- HTTP_API_VERSION : string = 1
- Current MTG HTTP API version.
- VERSION : string = 'v1.0.0'
- MTG Http version.
Properties
- $buckets : array<string|int, Bucket>
- Array of request buckets.
- $driver : DriverInterface
- HTTP driver.
- $logger : LoggerInterface
- Logger for HTTP requests.
- $loop : LoopInterface
- ReactPHP event loop.
- $promiseV3 : mixed
- Whether react/promise v3 is used, if false, using v2.
- $queue : SplQueue
- Request queue to prevent API overload.
- $rateLimit : RateLimit
- The current rate-limit.
- $rateLimitReset : TimerInterface
- Timer that resets the current global rate-limit.
- $unboundQueue : SplQueue
- Request queue to prevent API overload.
- $waiting : int
- Number of requests that are waiting for a response.
- $apiKey : string|null
- Optional `X-Api-Key` for the MTG API. Supplying one raises the per-hour request allowance; without it the API still works at the anonymous limit.
- $token : string
- Authentication token. Empty for the MTG API, which is unauthenticated — kept only so the shared {@see HttpTrait} plumbing has something to read.
Methods
- __construct() : mixed
- Http wrapper constructor.
- getUserAgent() : string
- Identifies this client to the MTG API as DiscordPHP-MTG rather than borrowing the generic DiscordPHP-HTTP agent string.
- queueRequest() : PromiseInterface
- Builds and queues a request.
Constants
BASE_URL
MTG API base URL.
public
string
BASE_URL
= 'https://api.magicthegathering.io/v' . self::HTTP_API_VERSION
HTTP_API_VERSION
Current MTG HTTP API version.
public
string
HTTP_API_VERSION
= 1
VERSION
MTG Http version.
public
string
VERSION
= 'v1.0.0'
Properties
$buckets
Array of request buckets.
protected
array<string|int, Bucket>
$buckets
= []
$driver
HTTP driver.
protected
DriverInterface
$driver
$logger
Logger for HTTP requests.
protected
LoggerInterface
$logger
$loop
ReactPHP event loop.
protected
LoopInterface
$loop
$promiseV3
Whether react/promise v3 is used, if false, using v2.
protected
mixed
$promiseV3
= true
$queue
Request queue to prevent API overload.
protected
SplQueue
$queue
$rateLimit
The current rate-limit.
protected
RateLimit
$rateLimit
$rateLimitReset
Timer that resets the current global rate-limit.
protected
TimerInterface
$rateLimitReset
$unboundQueue
Request queue to prevent API overload.
protected
SplQueue
$unboundQueue
$waiting
Number of requests that are waiting for a response.
protected
int
$waiting
= 0
$apiKey
Optional `X-Api-Key` for the MTG API. Supplying one raises the per-hour request allowance; without it the API still works at the anonymous limit.
private
string|null
$apiKey
$token
Authentication token. Empty for the MTG API, which is unauthenticated — kept only so the shared {@see HttpTrait} plumbing has something to read.
private
string
$token
Methods
__construct()
Http wrapper constructor.
public
__construct(string $token, LoopInterface $loop, LoggerInterface $logger[, DriverInterface|null $driver = null ][, string|null $apiKey = null ]) : mixed
Parameters
- $token : string
-
Unused by the MTG API; pass
''. - $loop : LoopInterface
- $logger : LoggerInterface
- $driver : DriverInterface|null = null
- $apiKey : string|null = null
-
Optional MTG API key (
X-Api-Key) for a higher rate limit.
getUserAgent()
Identifies this client to the MTG API as DiscordPHP-MTG rather than borrowing the generic DiscordPHP-HTTP agent string.
public
getUserAgent() : string
Return values
stringqueueRequest()
Builds and queues a request.
public
queueRequest(string $method, Endpoint $url, mixed $content[, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
- $method : string
- $url : Endpoint
- $content : mixed
- $headers : array<string|int, mixed> = []