Skip to content

Commit

Permalink
Interface all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Aug 27, 2015
1 parent cdce071 commit 86862e5
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* PHP Client for the Marvel API.
*/
class Client
class Client implements ClientInterface
{
/**
* The public api key issued by Marvel.
Expand Down Expand Up @@ -72,7 +72,7 @@ final public function __construct(
* @param string $resource The API resource to search for.
* @param array $filters Array of search criteria to use in request.
*
* @return Response
* @return ResponseInterface
*
* @throws \InvalidArgumentException Thrown if $resource is empty or not a string.
*/
Expand All @@ -97,7 +97,7 @@ final public function search($resource, array $filters = [])
* @param string $resource The API resource to search for.
* @param integer $id The id of the API resource.
*
* @return Response
* @return ResponseInterface
*/
final public function get($resource, $id)
{
Expand All @@ -118,11 +118,11 @@ final public function get($resource, $id)
/**
* Send the given API Request.
*
* @param Request $request The request to send.
* @param RequestInterface $request The request to send.
*
* @return Response
* @return ResponseInterface
*/
final private function send(Request $request)
final private function send(RequestInterface $request)
{
$response = $this->getFromCache($request);
if ($response !== null) {
Expand All @@ -141,11 +141,11 @@ final private function send(Request $request)
/**
* Retrieve the Response for the given Request from cache.
*
* @param Request $request The request to send.
* @param RequestInterface $request The request to send.
*
* @return Response|null Returns the cached Response or null if it does not exist.
* @return ResponseInterface|null Returns the cached Response or null if it does not exist.
*/
final private function getFromCache(Request $request)
final private function getFromCache(RequestInterface $request)
{
if ($this->cache === null) {
return null;
Expand Down
31 changes: 31 additions & 0 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Chadicus\Marvel\Api;

/**
* PHP Client for the Marvel API.
*/
interface ClientInterface
{
/**
* Execute a search request against the Marvel API.
*
* @param string $resource The API resource to search for.
* @param array $filters Array of search criteria to use in request.
*
* @return ResponseInterface
*
* @throws \InvalidArgumentException Thrown if $resource is empty or not a string.
*/
public function search($resource, array $filters = []);

/**
* Execute a GET request against the Marvel API for a single resource.
*
* @param string $resource The API resource to search for.
* @param integer $id The id of the API resource.
*
* @return ResponseInterface
*/
public function get($resource, $id);
}
2 changes: 1 addition & 1 deletion src/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DominionEnterprises\Util;

class DataContainer
class DataContainer implements DataContainerInterface
{
/**
* The requested offset (number of skipped results) of the call.
Expand Down
42 changes: 42 additions & 0 deletions src/DataContainerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Chadicus\Marvel\Api;

interface DataContainerInterface
{

/**
* Returns The requested offset (number of skipped results) of the call.
*
* @return integer
*/
public function getOffset();

/**
* Returns The requested result limit.
*
* @return integer
*/
public function getLimit();

/**
* Returns The total number of resources available given the current filter set.
*
* @return integer
*/
public function getTotal();

/**
* Returns The total number of results returned by this call.
*
* @return integer
*/
public function getCount();

/**
* Returns The list of creators returned by the call.
*
* @return EntityInterface[]
*/
public function getResults();
}
2 changes: 1 addition & 1 deletion src/DataWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DominionEnterprises\Util;

class DataWrapper
class DataWrapper implements DataWrapperInterface
{
/**
* The HTTP status code of the returned result.
Expand Down
55 changes: 55 additions & 0 deletions src/DataWrapperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Chadicus\Marvel\Api;

interface DataWrapperInterface
{
/**
* Returns the HTTP status code of the returned result.
*
* @return integer
*/
public function getCode();

/**
* Returns A string description of the call status.
*
* @return string
*/
public function getStatus();

/**
* Returns the copyright notice for the returned result.
*
* @return string
*/
public function getCopyright();

/**
* Returns the attribution notice for this result
*
* @return string
*/
public function getAttributionText();

/**
* Returns an HTML representation of the attribution notice for this result.
*
* @return string
*/
public function getAttributionHTML();

/**
* Returns a digest value of the content returned by the call.
*
* @return string
*/
public function getEtag();

/**
* Returns the results returned by the call.
*
* @return DataContainerInterface
*/
public function getData();
}
4 changes: 2 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Represents a request to the Marvel API.
*/
class Request
class Request implements RequestInterface
{
/**
* The url for this request.
Expand Down Expand Up @@ -80,7 +80,7 @@ final public function getMethod()
/**
* Get the body of this request.
*
* @return string
* @return array
*/
final public function getBody()
{
Expand Down
37 changes: 37 additions & 0 deletions src/RequestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Chadicus\Marvel\Api;

/**
* Represents a request to the Marvel API.
*/
interface RequestInterface
{
/**
* Get the url of this request.
*
* @return string
*/
public function getUrl();

/**
* Get the method of this request.
*
* @return string
*/
public function getMethod();

/**
* Get the body of this request.
*
* @return array
*/
public function getBody();

/**
* Get the headers of this request.
*
* @return array
*/
public function getHeaders();
}
4 changes: 2 additions & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Represents a response from the Marvel API.
*/
class Response
class Response implements ResponseInterface
{
/**
* The http status of the response.
Expand Down Expand Up @@ -88,7 +88,7 @@ final public function getHeaders()
/**
* Returns the parsed API response.
*
* @return DataWrapper
* @return DataWrapperInterface
*/
final public function getDataWrapper()
{
Expand Down
37 changes: 37 additions & 0 deletions src/ResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Chadicus\Marvel\Api;

/**
* Represents a response from the Marvel API.
*/
interface ResponseInterface
{
/**
* Returns the HTTP status code of the response.
*
* @return integer
*/
public function getHttpCode();

/**
* Returns the response body.
*
* @return array
*/
public function getBody();

/**
* Returns response headers.
*
* @return array
*/
public function getHeaders();

/**
* Returns the parsed API response.
*
* @return DataWrapperInterface
*/
public function getDataWrapper();
}

0 comments on commit 86862e5

Please # to comment.