-
Notifications
You must be signed in to change notification settings - Fork 2
/
Api.php
43 lines (36 loc) · 974 Bytes
/
Api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php declare(strict_types=1);
/**
* Copyright (C) Apis Networks, Inc - All Rights Reserved.
*
* MIT License
*
* Written by Matt Saladna <matt@apisnetworks.com>, August 2018
*/
namespace Opcenter\Dns\Providers\Cloudflare;
use Cloudflare\API\Auth\APIKey;
use Cloudflare\API\Endpoints\API as CFAPI;
use Opcenter\Dns\Providers\Cloudflare\Extensions\APIToken;
use Opcenter\Dns\Providers\Cloudflare\Extensions\GuzzleAdapter;
class Api
{
/**
* Create a Cloudflare API instance
*
* @param string|null $email
* @param string $key
* @param string $abstract
* @return CFAPI
*/
public static function api(?string $email, string $key, string $abstract): CFAPI
{
if ($email && ctype_xdigit($key)) {
// Master key
$authHandler = new APIKey($email, $key);
} else {
// Scoped API token
$authHandler = new APIToken($key);
}
$adapter = new GuzzleAdapter($authHandler);
return new $abstract($adapter);
}
}