Skip to content

Commit

Permalink
Merge pull request #92 from exportsmedia/feature-crypto-endpoints
Browse files Browse the repository at this point in the history
Add Crypto endpoints to crypto.php, update TLS.php
  • Loading branch information
IcyApril authored Jun 7, 2019
2 parents d913aa8 + 7a7e6dc commit b558622
Show file tree
Hide file tree
Showing 19 changed files with 684 additions and 66 deletions.
95 changes: 95 additions & 0 deletions src/Endpoints/Crypto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Cloudflare\API\Endpoints;

use Cloudflare\API\Adapter\Adapter;

class Crypto implements API
{
private $adapter;

public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}

/**
* Get the Opportunistic Encryption feature for a zone.
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getOpportunisticEncryptionSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/opportunistic_encryption'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}

/**
* Get the Onion Routing feature for a zone.
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getOnionRoutingSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/opportunistic_onion'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}

/**
* Update the Oppurtunistic Encryption setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateOpportunisticEncryptionSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/opportunistic_encryption',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}

/**
* Update the Onion Routing setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateOnionRoutingSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/opportunistic_onion',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}
153 changes: 153 additions & 0 deletions src/Endpoints/SSL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

namespace Cloudflare\API\Endpoints;

use Cloudflare\API\Adapter\Adapter;

class SSL implements API
{
private $adapter;

public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}

/**
* Get the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getSSLSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/ssl'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}

/**
* Get SSL Verification Info for a Zone
*
* @param string $zoneID The ID of the zone
* @return array|false
*/
public function getSSLVerificationStatus(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/ssl/verification'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body;
}
return false;
}

/**
* Get the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRedirectSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/always_use_https'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}

/**
* Get the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRewritesSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/automatic_https_rewrites'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}

/**
* Update the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateSSLSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/ssl',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}

/**
* Update the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRedirectSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/always_use_https',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}

/**
* Update the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRewritesSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/automatic_https_rewrites',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}
Loading

0 comments on commit b558622

Please sign in to comment.