Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created February 6, 2013 12:53
Show Gist options
  • Save eminetto/4722347 to your computer and use it in GitHub Desktop.
Save eminetto/4722347 to your computer and use it in GitHub Desktop.
<?php
class Coderockr_Service extends Zend_Service_Abstract
{
private $apiKey;
private $httpClient;
public function __construct($apiKey)
{
$this->apiKey = $apiKey;
$this->httpClient = $this->getHttpClient();
$this->httpClient->setHeaders('Authorization', $this->apiKey);
}
public function execute($uri, $parameters)
{
//@todo filtrar os parametros para evitar problemas de segurança
$this->httpClient->setUri($uri);
$this->httpClient->setMethod(Zend_Http_Client::POST);
$this->httpClient->setParameterPost($parameters);
$response = $this->httpClient->request();
return array(
'status' => $response->getStatus(),
'data' => $response->getBody()
);
}
public function get($uri)
{
$this->httpClient->setUri($uri);
$this->httpClient->setMethod(Zend_Http_Client::GET);
$response = $this->httpClient->request();
return array(
'status' => $response->getStatus(),
'data' => $response->getBody()
);
}
public function post($uri, $fields)
{
//@todo filtrar os parametros para evitar problemas de segurança
$this->httpClient->setUri($uri);
$this->httpClient->setMethod(Zend_Http_Client::POST);
$this->httpClient->setParameterPost($fields);
$response = $this->httpClient->request();
return array(
'status' => $response->getStatus(),
'data' => $response->getBody()
);
}
public function put($uri, $fields)
{
//@todo filtrar os parametros para evitar problemas de segurança
$this->httpClient->setUri($uri);
$this->httpClient->setMethod(Zend_Http_Client::PUT);
$this->httpClient->setParameterPost($fields);
$response = $this->httpClient->request();
return array(
'status' => $response->getStatus(),
'data' => $response->getBody()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment