Created
February 6, 2013 12:53
-
-
Save eminetto/4722347 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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