Skip to content

Commit

Permalink
Class methods reorganisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pol Dellaiera authored and Pol Dellaiera committed Dec 3, 2016
1 parent 17327ed commit e527453
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 84 deletions.
50 changes: 29 additions & 21 deletions src/Http/Client.php
Expand Up @@ -62,9 +62,13 @@ public function __construct(HttpClient $httpClient = NULL, UriFactory $uriFactor
* Set the Random.org endpoint.
*
* @param string $uri
*
* @return self
*/
public function setEndpoint($uri) {
$this->endpoint = $this->getUriFactory()->createUri($uri);

return $this;
}

/**
Expand All @@ -77,20 +81,23 @@ public function getEndpoint() {
}

/**
* Request.
*
* @param MethodPluginInterface $methodPlugin
* @param \Http\Message\UriFactory $uriFactory
*
* @return null|ResponseInterface
* @return self
*/
public function request(MethodPluginInterface $methodPlugin) {
try {
$response = $this->post($this->getEndpoint(), [], json_encode($methodPlugin->getParameters()));
} catch (NetworkException $e) {
return NULL;
}
public function setUriFactory(UriFactory $uriFactory) {
$this->uriFactory = $uriFactory;

return $this->validateResponse($response);
return $this;
}

/**
* Returns the UriFactory.
*
* @return \Http\Message\UriFactory
*/
public function getUriFactory() {
return $this->uriFactory;
}

/**
Expand Down Expand Up @@ -126,19 +133,20 @@ public function validateResponse(ResponseInterface $response) {
}

/**
* Returns the UriFactory.
* Request.
*
* @return \Http\Message\UriFactory
* @param MethodPluginInterface $methodPlugin
*
* @return null|ResponseInterface
*/
public function getUriFactory() {
return $this->uriFactory;
}
public function request(MethodPluginInterface $methodPlugin) {
try {
$response = $this->post($this->getEndpoint(), [], json_encode($methodPlugin->getParameters()));
} catch (NetworkException $e) {
return NULL;
}

/**
* @param \Http\Message\UriFactory $uriFactory
*/
public function setUriFactory(UriFactory $uriFactory) {
$this->uriFactory = $uriFactory;
return $this->validateResponse($response);
}

}
126 changes: 63 additions & 63 deletions src/RandomOrgAPI.php
Expand Up @@ -77,50 +77,75 @@ public function __construct(HttpClient $httpClient = NULL) {
}

/**
* Set the Random.org endpoint template.
* Set the Random.org API Key.
*
* @param string $uri
* The URI.
* @param string $key
* The API Key.
*
* @return self
*/
public function setEndpoint($uri) {
$this->endpoint = $uri;
$this->getHttpClient()->setEndpoint($this->getEndpoint());
public function setApiKey($key) {
$this->apiKey = $key;

return $this;
}

/**
* Get the Random.org endpoint.
* Get the Random.org API Key.
*
* @return string
* The API Key.
*/
public function getEndpoint() {
return sprintf($this->endpoint, $this->getApiVersion());
public function getApiKey() {
return $this->apiKey;
}

/**
* Set the Method plugin manager.
* Set the API version.
*
* @param MethodPluginManager $methodPluginManager
* The method plugin manager.
* @param int
* The API version.
*
* @return self
*/
public function setMethodPluginManager(MethodPluginManager $methodPluginManager) {
$this->methodPluginManager = $methodPluginManager;
public function setApiVersion($version) {
$this->apiVersion = $version;
$this->getHttpClient()->setEndpoint($this->getEndpoint());

return $this;
}

/**
* Return the Method plugin manager.
* Get the API version.
*
* @return \drupol\Yaroc\Plugin\MethodPluginManager
* @return int
*/
public function getMethodPluginManager() {
return $this->methodPluginManager;
public function getApiVersion() {
return $this->apiVersion;
}

/**
* Set the Random.org endpoint template.
*
* @param string $uri
* The URI.
*
* @return self
*/
public function setEndpoint($uri) {
$this->endpoint = $uri;
$this->getHttpClient()->setEndpoint($this->getEndpoint());

return $this;
}

/**
* Get the Random.org endpoint.
*
* @return string
*/
public function getEndpoint() {
return sprintf($this->endpoint, $this->getApiVersion());
}

/**
Expand Down Expand Up @@ -157,74 +182,49 @@ public function getHttpClient() {
}

/**
* Set the Random.org API Key.
* Set the method plugin.
*
* @param string $key
* The API Key.
* @param \drupol\Yaroc\Plugin\MethodPluginInterface|NULL $methodPlugin
*
* @return self
* @return False|self
* Return itself, or FALSE otherwise.
*/
public function setApiKey($key) {
$this->apiKey = $key;
public function setMethodPlugin(MethodPluginInterface $methodPlugin = NULL) {
$this->methodPlugin = $methodPlugin;

return $this;
return $methodPlugin ? $this : FALSE;
}

/**
* Get the Random.org API Key.
* Get the method plugin.
*
* @return string
* The API Key.
* @return \drupol\Yaroc\Plugin\MethodPluginInterface
*/
public function getApiKey() {
return $this->apiKey;
private function getMethodPlugin() {
return $this->methodPlugin;
}

/**
* Set the API version.
* Set the Method plugin manager.
*
* @param int
* The API version.
* @param MethodPluginManager $methodPluginManager
* The method plugin manager.
*
* @return self
*/
public function setApiVersion($version) {
$this->apiVersion = $version;
$this->getHttpClient()->setEndpoint($this->getEndpoint());
public function setMethodPluginManager(MethodPluginManager $methodPluginManager) {
$this->methodPluginManager = $methodPluginManager;

return $this;
}

/**
* Get the API version.
*
* @return int
*/
public function getApiVersion() {
return $this->apiVersion;
}

/**
* Set the method plugin.
*
* @param \drupol\Yaroc\Plugin\MethodPluginInterface|NULL $methodPlugin
*
* @return False|self
* Return itself, or FALSE otherwise.
*/
public function setMethodPlugin(MethodPluginInterface $methodPlugin = NULL) {
$this->methodPlugin = $methodPlugin;

return $methodPlugin ? $this : FALSE;
}

/**
* Get the method plugin.
* Return the Method plugin manager.
*
* @return \drupol\Yaroc\Plugin\MethodPluginInterface
* @return \drupol\Yaroc\Plugin\MethodPluginManager
*/
private function getMethodPlugin() {
return $this->methodPlugin;
public function getMethodPluginManager() {
return $this->methodPluginManager;
}

/**
Expand Down

0 comments on commit e527453

Please sign in to comment.