Skip to content

Commit

Permalink
reworked some code to prepare for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurits van der Schee committed Jan 22, 2013
1 parent de49621 commit e29f8d9
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 369 deletions.
157 changes: 0 additions & 157 deletions Call/ApiCall.php

This file was deleted.

20 changes: 7 additions & 13 deletions Call/ApiCallInterface.php
Expand Up @@ -53,26 +53,20 @@ public function getResponseObjectRepresentation();
/**
* Get the HTTP status of the API call
*/
public function getStatus();

/**
* Generate the request parameter data
*/
public function generateRequestData();
public function getStatusCode();

/**
* Parse the request response data
* Get the HTTP status of the API call
*/
public function parseResponseData();
public function getStatus();

/**
* Method that makes the actual cURL request
* Execute the call
*
* @param resource $curlHandle cURL handle
* @param array $options cURL options array
* @param array $options Array of options
*
* @see \Lsw\ApiCallerBundle\Call\ApiCall::makeRequest()
* @return mixed Response
*/
public function makeRequest($curlHandle, $options);
public function execute($options);

}
14 changes: 8 additions & 6 deletions Call/HttpDeleteJson.php
@@ -1,12 +1,14 @@
<?php
namespace Lsw\ApiCallerBundle\Call;

use Lsw\ApiCallerBundle\Helper\Curl;

/**
* cURL based API call with request data send as GET parameters
*
* @author Maurits van der Schee <m.vanderschee@leaseweb.com>
*/
class HttpDeleteJson extends ApiCall implements ApiCallInterface
class HttpDeleteJson extends CurlCall implements ApiCallInterface
{
/**
* {@inheritdoc}
Expand All @@ -27,11 +29,11 @@ public function parseResponseData()
/**
* {@inheritdoc}
*/
public function makeRequest($curlHandle, $options)
public function makeRequest($curl, $options)
{
curl_setopt($curlHandle, CURLOPT_URL, $this->url.'?'.$this->requestData);
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt_array($curlHandle, $options);
$this->responseData = curl_exec($curlHandle);
$curl->setopt(CURLOPT_URL, $this->url.'?'.$this->requestData);
$curl->setopt(CURLOPT_CUSTOMREQUEST, 'DELETE');
$curl->setoptArray($options);
$this->responseData = $curl->exec();
}
}
14 changes: 8 additions & 6 deletions Call/HttpGetHtml.php
@@ -1,12 +1,14 @@
<?php
namespace Lsw\ApiCallerBundle\Call;

use Lsw\ApiCallerBundle\Helper\Curl;

/**
* cURL based API call with request data send as GET parameters
*
* @author Maurits van der Schee <m.vanderschee@leaseweb.com>
*/
class HttpGetHtml extends ApiCall implements ApiCallInterface
class HttpGetHtml extends CurlCall implements ApiCallInterface
{
/**
* ApiCall class constructor
Expand Down Expand Up @@ -43,16 +45,16 @@ public function parseResponseData()
/**
* {@inheritdoc}
*/
public function makeRequest($curlHandle, $options)
public function makeRequest($curl, $options)
{
$url = $this->url;
if ($this->requestData) {
$url.= $this->requestData;
}
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_COOKIE, $this->cookie);
curl_setopt_array($curlHandle, $options);
$this->responseData = curl_exec($curlHandle);
$curl->setopt(CURLOPT_URL, $url);
$curl->setopt(CURLOPT_COOKIE, $this->cookie);
$curl->setoptArray($options);
$this->responseData = $curl->exec();
}

}
12 changes: 7 additions & 5 deletions Call/HttpGetJson.php
@@ -1,12 +1,14 @@
<?php
namespace Lsw\ApiCallerBundle\Call;

use Lsw\ApiCallerBundle\Helper\Curl;

/**
* cURL based API call with request data send as GET parameters
*
* @author Maurits van der Schee <m.vanderschee@leaseweb.com>
*/
class HttpGetJson extends ApiCall implements ApiCallInterface
class HttpGetJson extends CurlCall implements ApiCallInterface
{
/**
* {@inheritdoc}
Expand All @@ -27,11 +29,11 @@ public function parseResponseData()
/**
* {@inheritdoc}
*/
public function makeRequest($curlHandle, $options)
public function makeRequest($curl, $options)
{
curl_setopt($curlHandle, CURLOPT_URL, $this->url.'?'.$this->requestData);
curl_setopt_array($curlHandle, $options);
$this->responseData = curl_exec($curlHandle);
$curl->setopt(CURLOPT_URL, $this->url.'?'.$this->requestData);
$curl->setoptArray($options);
$this->responseData = $curl->exec();
}

}
16 changes: 9 additions & 7 deletions Call/HttpPostJson.php
@@ -1,12 +1,14 @@
<?php
namespace Lsw\ApiCallerBundle\Call;

use Lsw\ApiCallerBundle\Helper\Curl;

/**
* cURL based API call with request data send as GET parameters
*
* @author Maurits van der Schee <m.vanderschee@leaseweb.com>
*/
class HttpPostJson extends ApiCall implements ApiCallInterface
class HttpPostJson extends CurlCall implements ApiCallInterface
{
/**
* {@inheritdoc}
Expand All @@ -27,13 +29,13 @@ public function parseResponseData()
/**
* {@inheritdoc}
*/
public function makeRequest($curlHandle, $options)
public function makeRequest($curl, $options)
{
curl_setopt($curlHandle, CURLOPT_URL, $this->url);
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $this->requestData);
curl_setopt_array($curlHandle, $options);
$this->responseData = curl_exec($curlHandle);
$curl->setopt(CURLOPT_URL, $this->url);
$curl->setopt(CURLOPT_POST, 1);
$curl->setopt(CURLOPT_POSTFIELDS, $this->requestData);
$curl->setoptArray($options);
$this->responseData = $curl->exec();
}

}
18 changes: 10 additions & 8 deletions Call/HttpPutJson.php
@@ -1,12 +1,14 @@
<?php
namespace Lsw\ApiCallerBundle\Call;

use Lsw\ApiCallerBundle\Helper\Curl;

/**
* cURL based API call with request data send as GET parameters
*
* @author Maurits van der Schee <m.vanderschee@leaseweb.com>
*/
class HttpPutJson extends ApiCall implements ApiCallInterface
class HttpPutJson extends CurlCall implements ApiCallInterface
{
/**
* {@inheritdoc}
Expand All @@ -27,14 +29,14 @@ public function parseResponseData()
/**
* {@inheritdoc}
*/
public function makeRequest($curlHandle, $options)
public function makeRequest($curl, $options)
{
curl_setopt($curlHandle, CURLOPT_URL, $this->url);
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $this->requestData);
curl_setopt($curlHandle, CURLOPT_PUT, 1);
curl_setopt_array($curlHandle, $options);
$this->responseData = curl_exec($curlHandle);
$curl->setopt(CURLOPT_URL, $this->url);
$curl->setopt(CURLOPT_POST, 1);
$curl->setopt(CURLOPT_POSTFIELDS, $this->requestData);
$curl->setopt(CURLOPT_PUT, 1);
$curl->setoptArray($options);
$this->responseData = $curl->exec();
}

}
2 changes: 2 additions & 0 deletions Caller/ApiCallerInterface.php
Expand Up @@ -22,6 +22,8 @@ public function call(ApiCallInterface $call);

/**
* Method returns last status
*
* @return string Last status
*/
public function getLastStatus();

Expand Down

0 comments on commit e29f8d9

Please sign in to comment.