Http
in package
implements
HttpInterface
uses
HttpTrait
HTTP client for the MTGJSON v5 API, built the same way DiscordPHP talks to `discord.com` (buckets, driver, retry) but pointed at `mtgjson.com/api/v5`. The API is read-only and unauthenticated, so no token is required. Responses are MTGJSON's `{"meta": {...}, "data": ...}` wrapper, decoded.
Requests are buffered (16 MiB by default in react/http), which covers every small file; the bulk files are streamed separately by Database.
Tags
Table of Contents
Interfaces
- HttpInterface
Constants
- BASE_URL : string = 'https://mtgjson.com/api/v' . self::HTTP_API_VE...
- MTGJSON API base URL.
- HTTP_API_VERSION : string = 5
- Current MTGJSON 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.
- $token : string
- Authentication token. Empty for MTGJSON, 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 MTGJSON as DiscordPHP-MTG rather than borrowing the generic DiscordPHP-HTTP agent string.
- queueRequest() : PromiseInterface
- Builds and queues a request.
Constants
BASE_URL
MTGJSON API base URL.
public
string
BASE_URL
= 'https://mtgjson.com/api/v' . self::HTTP_API_VERSION
HTTP_API_VERSION
Current MTGJSON API version.
public
string
HTTP_API_VERSION
= 5
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
$token
Authentication token. Empty for MTGJSON, 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 ]) : mixed
Parameters
- $token : string
-
Unused by MTGJSON; pass
''. - $loop : LoopInterface
- $logger : LoggerInterface
- $driver : DriverInterface|null = null
getUserAgent()
Identifies this client to MTGJSON 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> = []