Last active
January 27, 2017 08:33
-
-
Save hasangilak/d4349d3a97ddcdfc846b98228383e6fb to your computer and use it in GitHub Desktop.
a php cloudflare client for adding subdomain. depends on guzzle >= v6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services\CloudFlare; | |
use GuzzleHttp\Client; | |
class CloudFlareClient | |
{ | |
private $email; | |
private $key; | |
private $zone; | |
public function __construct($email, $key, $zone) | |
{ | |
$this->email = $email; | |
$this->key = $key; | |
$this->zone = $zone; | |
} | |
public function listAllZones() | |
{ | |
$client = new Client(); | |
$url = 'https://api.cloudflare.com/client/v4/zones'; | |
$parameters = [ | |
'headers' => [ | |
'X-Auth-Email' => $this->email, | |
'X-Auth-Key' => $this->key, | |
'Content-Type' => 'application/json' | |
] | |
]; | |
return $client->get($url, $parameters); | |
} | |
public function addSubDomain($name, $ip) | |
{ | |
$client = new Client(); | |
$response = $client->request('POST', | |
'https://api.cloudflare.com/client/v4/zones/' . $this->zone . '/dns_records', [ | |
'json' => [ | |
'name' => $name, | |
'type' => 'A', | |
'content' => $ip, | |
'proxied' => true | |
], | |
'headers' => [ | |
'X-Auth-Email' => $this->email, | |
'X-Auth-Key' => $this->key, | |
'Content-Type' => 'application/json' | |
] | |
]); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment