views:

57

answers:

0

Hi,

I am trying to make a GET request to gowalla spots by Zend_Http_Client (cURL adapter) here is my class:

    class Application_Model_Gowalla
{
    private $_config;
    private $options;
    private $array;
    private $json;

    public function  __construct() {

         $conf = Zend_Registry::get('config');
         $this->_config = $conf->gowalla->toArray();
         $this->options = array(
            'adapter'   => 'Zend_Http_Client_Adapter_Curl',
            'useragent' => 'Zend_Http_Client',
            'curloptions' => array(
                                CURLOPT_VERBOSE => 1,
                                CURLOPT_NOBODY => 0,
                                CURLOPT_RETURNTRANSFER => true,
                                CURLOPT_FOLLOWLOCATION => true,
                                CURLOPT_HTTPHEADER => array('X-Gowalla-API-Key: '.$this->_config['api_key'],'Accept: application/json')

                                )
        );
    }

   public function getLocation($lon, $lat, $radius) {

       $query = '/spots?lat='.$lon.'&lng='.$lat.'&radius='.$radius;
       $client = new Zend_Http_Client($this->_config['site'].$query, $this->options);
       //var_dump($client);
       $final = $client->request("GET");
       if ($final) {
         $result = json_decode($final);
         return $result;
       }
   }

But is not working, even the response code being 200 the date is in gzip not json as requested.

When I make a plain cURL request using libcurl as in:

/*
    *  This is a alternative version
    */
   public function plainCurl($lon, $lat, $radius) {

                $curl = new CURL();
                $curl->retry = 2;
                $url = '/spots?lat='.$lon.'&lng='.$lat.'&radius='.$radius;
                $opts = array( CURLOPT_RETURNTRANSFER => true,
                               CURLOPT_FOLLOWLOCATION => true,  CURLOPT_HTTPHEADER =>       array('X-Gowalla-API-Key: '.$this->_config['api_key'],'Content-Type: application/json','Accept: application/json'));
                $curl->addSession($this->_config['site'].$url, $opts);
                $this->json = $curl->exec();
                if ($this->json) {
                        $this->array = json_decode($this->json);
                        return $this->array;
                }
                $curl->clear();


   }

It works perfectly, but I would rather to keep myself inside zend framework.

What am I doing wrong?