Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
Readded Traits
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmaron committed Jan 15, 2018
1 parent fabbda0 commit e722207
Show file tree
Hide file tree
Showing 6 changed files with 920 additions and 672 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

## 1.6.0 - 2018-01-14

* Split `ReportingCloud\ReportingCloud` into multiple Traits.
* Added `PHP_CodeSniffer` to ensure consistency in code formatting.
* Added Composer script `composer test` to run unit tests.
* Added Composer script `composer phpcs` to run `PHP_CodeSniffer`.
Expand Down
112 changes: 112 additions & 0 deletions src/DeleteTrait.php
@@ -0,0 +1,112 @@
<?php

/**
* ReportingCloud PHP Wrapper
*
* PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
*
* @link http://www.reporting.cloud to learn more about ReportingCloud
* @link https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
* @license https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
* @copyright © 2018 Text Control GmbH
*/

namespace TxTextControl\ReportingCloud;

use GuzzleHttp\Psr7\Response;
use GuzzleHttp\RequestOptions;
use TxTextControl\ReportingCloud\Exception\InvalidArgumentException;
use TxTextControl\ReportingCloud\Validator\StaticValidator;

trait DeleteTrait
{
/**
* Abstract Methods
* -----------------------------------------------------------------------------------------------------------------
*/

/**
* Construct URI with version number
*
* @param string $uri URI
*
* @return string
*/
abstract protected function uri($uri);

/**
* Request the URI with options
*
* @param string $method HTTP method
* @param string $uri URI
* @param array $options Options
*
* @return mixed|null|\Psr\Http\Message\ResponseInterface
*
* @throws RuntimeException
*/
abstract protected function request($method, $uri, $options);

/**
* DELETE Methods
* -----------------------------------------------------------------------------------------------------------------
*/

/**
* Delete an API key
*
* @param string $key API key
*
* @return bool
*/
public function deleteApiKey($key)
{
$ret = false;

StaticValidator::execute($key, 'ApiKey');

$options = [
RequestOptions::QUERY => [
'key' => $key,
],
];

$response = $this->request('DELETE', $this->uri('/account/apikey'), $options);

if ($response instanceof Response && 200 === $response->getStatusCode()) {
$ret = true;
}

return $ret;
}

/**
* Delete a template in template storage
*
* @param string $templateName Template name
*
* @throws InvalidArgumentException
*
* @return bool
*/
public function deleteTemplate($templateName)
{
$ret = false;

StaticValidator::execute($templateName, 'TemplateName');

$options = [
RequestOptions::QUERY => [
'templateName' => $templateName,
],
];

$response = $this->request('DELETE', $this->uri('/templates/delete'), $options);

if ($response instanceof Response && 204 === $response->getStatusCode()) {
$ret = true;
}

return $ret;
}
}

0 comments on commit e722207

Please sign in to comment.