Ejemplo n.º 1
0
 /**
  * Builds the web service url
  *
  * @param Feed $feed
  *
  * @return string
  * @throws Exception
  */
 public function buildUrl(Feed $feed)
 {
     if (null == $feed->getApiKey() || null == $feed->getFeedId()) {
         throw new Exception("You must set the feed Id and API key", 500);
     }
     $this->setHeader(array("X-PachubeApiKey: {$feed->getApiKey()}"));
     $url = implode('/', array($this->baseUrl, "feeds", "{$feed->getFeedId()}.{$feed->getFormat()}"));
     // If datastreams set
     if (count($feed->getDatastreams()) > 0) {
         $datastreams = implode(',', $feed->getDatastreams());
         return "{$url}?datastreams={$datastreams}";
     }
     return $url;
 }
Ejemplo n.º 2
0
 /**
  * Reads feed
  *
  * @param string $apiVersion
  * @param string $apiKey
  * @param integer $feedId
  *
  * @return array
  */
 public function readFeed($feedId, $apiKey)
 {
     $feed = new Feed();
     $feed->setFeedId($feedId);
     $feed->setApiKey($apiKey);
     $feed->setDatastreams(array(1));
     $feed->setFormat('json');
     $response = ResponseToArrayTransformer::transform($this->connManager->getRequest($feed), $feed->getFormat());
     echo "<pre>";
     var_dump($response);
     echo "</pre>";
     die;
     //        //if historical query
     //        if ($start != null && $end != null) {
     //            $startDate = new \DateTime($start);
     //            $endDate = new \DateTime($end);
     //
     //            $pachube = new Pachube($apiVersion, $feedId);
     //            $pachube->setStartDate($startDate);
     //            $pachube->setEndDate($endDate);
     //
     //            $url = $pachube->buildUrl();
     //
     //
     //            $response = $this->connManager->_getRequest($url);
     //            return $response;
     //        }
     //        else {
     //            $pachube = new Pachube($apiVersion, $feedId);
     //
     //            //building web service url
     //            $url = $pachube->buildUrl();
     //
     //            //getting data
     //            $data = $this->connManager->_getRequest($url);
     //
     //        }
     //
     //        return $data;
 }