Skip to content

Commit

Permalink
New HttpGetXML handles XML requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
comstar committed May 2, 2014
1 parent 2f890d8 commit a334361
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Call/HttpGetXML.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
namespace Lsw\ApiCallerBundle\Call;

use Lsw\ApiCallerBundle\Helper\Curl;

/**
* cURL based API call with request data send as GET parameters
*
* @author J. Cary Howell <[email protected]>
*/
class HttpGetXML extends CurlCall implements ApiCallInterface
{
/**
* ApiCall class constructor
*
* @param string $url API url
* @param object $cookie Cookie
* @param object $requestObject Request
* @param boolean $asAssociativeArray
*/
public function __construct($url,$cookie,$asAssociativeArray=false,$requestObject=null)
{
$this->url = $url;
$this->cookie = $cookie;
$this->requestObject = $requestObject;
$this->asAssociativeArray = $asAssociativeArray;
$this->generateRequestData();
}

/**
* {@inheritdoc}
*/
public function generateRequestData()
{
if ($this->requestObject) {
$this->requestData = '?'.http_build_query($this->requestObject);
}
}

/**
* {@inheritdoc}
*/
public function parseResponseData()
{
if($this->asAssociativeArray) {
$xml = simplexml_load_string($this->responseData);
$json = json_encode($xml);
$this->responseObject = json_decode( $json, TRUE );
} else {
$this->responseObject = $this->responseData;
}
}

/**
* {@inheritdoc}
*/
public function makeRequest($curl, $options)
{
$url = $this->url;
if ($this->requestData) {
$url.= $this->requestData;
}
$curl->setopt(CURLOPT_URL, $url);
$curl->setopt(CURLOPT_COOKIE, $this->cookie);
$curl->setopt(CURLOPT_HTTPGET, TRUE);
$curl->setoptArray($options);
$this->curlExec($curl);
}

}

0 comments on commit a334361

Please sign in to comment.