Skip to content

Commit

Permalink
Add returnType to Management class
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Aug 7, 2018
1 parent 2f3bcf6 commit a3d04f9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/API/Helpers/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public static function disableInfoHeaders()

protected $guzzleOptions;

protected $returnType;

public function __construct($config)
{
$this->basePath = $config['basePath'];
$this->domain = $config['domain'];
$this->returnType = isset( $config['returnType'] ) ? $config['returnType'] : null;
$this->headers = isset($config['headers']) ? $config['headers'] : [];
$this->guzzleOptions = isset($config['guzzleOptions']) ? $config['guzzleOptions'] : [];

Expand All @@ -76,7 +79,8 @@ public function __call($name, $arguments)
'domain' => $this->domain,
'basePath' => $this->basePath,
'method' => $name,
'guzzleOptions' => $this->guzzleOptions
'guzzleOptions' => $this->guzzleOptions,
'returnType' => $this->returnType,
]);

return $builder->withHeaders($this->headers);
Expand All @@ -97,7 +101,8 @@ public function method($method)
'domain' => $this->domain,
'basePath' => $this->basePath,
'method' => $method,
'guzzleOptions' => $this->guzzleOptions
'guzzleOptions' => $this->guzzleOptions,
'returnType' => $this->returnType,
]);
$builder->withHeaders($this->headers);

Expand Down
20 changes: 14 additions & 6 deletions src/API/Helpers/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ public function __construct(array $config)
}

/**
* Magic method to overload method calls to paths.
*
* @param string $name Method invoked.
* @param array $arguments Arguments to add to the path.
*
* @param string $name
* @param array $arguments
* @return RequestBuilder
*/
public function __call($name, $arguments)
public function __call($name, array $arguments)
{
$argument = null;

Expand All @@ -144,9 +146,11 @@ public function __call($name, $arguments)
}

/**
* Add a path and an optional argument to this request.
*
* @param string $name Path to add.
* @param string|null $argument Optional argument to add.
*
* @param string $name
* @param string|null $argument
* @return RequestBuilder
*/
public function addPath($name, $argument = null)
Expand All @@ -160,8 +164,10 @@ public function addPath($name, $argument = null)
}

/**
* Add a path variable.
*
* @param string $variable Path variable to add.
*
* @param string $variable
* @return RequestBuilder
*/
public function addPathVariable($variable)
Expand All @@ -171,6 +177,7 @@ public function addPathVariable($variable)
}

/**
* Get the path and URL parameters of this request.
*
* @return string
*/
Expand All @@ -180,6 +187,7 @@ public function getUrl()
}

/**
* Output a URL
*
* @return string
*/
Expand Down
11 changes: 10 additions & 1 deletion src/API/Management.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class Management
*/
private $guzzleOptions;

/**
*
* @var string
*/
private $returnType;

/**
*
* @var Blacklists
Expand Down Expand Up @@ -157,12 +163,14 @@ class Management
* @param string $token
* @param string $domain
* @param array $guzzleOptions
* @param string $returnType
*/
public function __construct($token, $domain, $guzzleOptions = [])
public function __construct($token, $domain, $guzzleOptions = [], $returnType = 'body')
{
$this->token = $token;
$this->domain = $domain;
$this->guzzleOptions = $guzzleOptions;
$this->returnType = $returnType;

$this->setApiClient();

Expand Down Expand Up @@ -193,6 +201,7 @@ protected function setApiClient()
'domain' => $apiDomain,
'basePath' => '/api/v2/',
'guzzleOptions' => $this->guzzleOptions,
'returnType' => $this->returnType,
'headers' => [
new AuthorizationBearer($this->token)
]
Expand Down
5 changes: 5 additions & 0 deletions tests/API/Management/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public function testExceptions()
} catch (CoreException $e) {
$caught_get_no_id_exception = $this->errorHasString($e, 'Invalid "id" parameter');
}

$this->assertTrue($caught_get_no_id_exception);

// Test that the delete method throws an exception if the $id parameter is empty.
Expand All @@ -179,6 +180,7 @@ public function testExceptions()
} catch (CoreException $e) {
$caught_delete_no_id_exception = $this->errorHasString($e, 'Invalid "id" parameter');
}

$this->assertTrue($caught_delete_no_id_exception);

// Test that the create method throws an exception if no "name" field is passed.
Expand All @@ -188,6 +190,7 @@ public function testExceptions()
} catch (CoreException $e) {
$caught_create_no_name_exception = $this->errorHasString($e, 'Missing required "name" field');
}

$this->assertTrue($caught_create_no_name_exception);

// Test that the create method throws an exception if no "script" field is passed.
Expand All @@ -197,6 +200,7 @@ public function testExceptions()
} catch (CoreException $e) {
$caught_create_no_script_exception = $this->errorHasString($e, 'Missing required "script" field');
}

$this->assertTrue($caught_create_no_script_exception);

// Test that the update method throws an exception if the $id parameter is empty.
Expand All @@ -206,6 +210,7 @@ public function testExceptions()
} catch (CoreException $e) {
$caught_update_no_id_exception = $this->errorHasString($e, 'Invalid "id" parameter');
}

$this->assertTrue($caught_update_no_id_exception);
}
}

0 comments on commit a3d04f9

Please sign in to comment.