post() public method

Make a call to a DataSift API endpoint.
public post ( string $endpoint, array $params = [], $headers = [], $ingest = false ) : array
$endpoint string The endpoint of the API call.
$params array The parameters to be passed along with the request.
return array The response from the server.
Ejemplo n.º 1
0
 /**
  * Generates a curl request to the Ingestion Endpoint 
  */
 public function ingest($data_set)
 {
     if (strlen($this->_source_id) == 0) {
         throw new DataSift_Exception_InvalidData('Cannot make request without a source ID');
     }
     if (empty($data_set)) {
         throw new DataSift_Exception_InvalidData('Cannot make request without a valid data set');
     }
     return $this->_user->post($this->getSourceId(), $data_set, array(), true);
 }
Ejemplo n.º 2
0
 /**
  * Returns a list of sample interactions (super-public)
  *
  * @param Datasift_User $user The Datasift user object
  * @param string $id The id of the existing pylon
  * @param string $filter additional CSDL filter
  * @param int $start the start time of the pylon
  * @param int $end the end time of the pylon
  * @param int $count optional value to set the count
  *
  * @throws DataSift_Exception_InvalidData
  *
  * @return array Response from the sample endpoint
  */
 public function sample($filter = false, $start = false, $end = false, $count = false, $id = false)
 {
     if ($id) {
         $this->_id = $id;
     }
     if (strlen($this->_id) == 0) {
         throw new DataSift_Exception_InvalidData('Unable to retrieve pylon sample without an ID');
     }
     $params = array('id' => $this->_id);
     if ($start) {
         $params['start'] = $start;
     }
     if ($end) {
         $params['end'] = $end;
     }
     if ($count) {
         $params['count'] = $count;
     }
     if ($filter) {
         $params['filter'] = $filter;
         return $this->_user->post('pylon/sample', $params);
     } else {
         return $this->_user->get('pylon/sample', $params);
     }
 }
Ejemplo n.º 3
0
 /**
  * List Historics queries.
  *
  * @param DataSift_User $user     The user object.
  * @param int           $page     The start page.
  * @param int           $per_page The start page.
  *
  * @throws DataSift_Exception_InvalidData
  * @throws DataSift_Exception_APIError
  */
 public static function listHistorics($user, $page = 1, $per_page = 20)
 {
     try {
         $res = $user->post('historics/get', array('page' => $page, 'max' => $page));
         $retval = array('count' => $res['count'], 'historics' => array());
         foreach ($res['data'] as $historic) {
             $retval['historics'][] = new self($user, $historic);
         }
         return $retval;
     } catch (DataSift_Exception_APIError $e) {
         switch ($e->getCode()) {
             case 400:
                 // Missing or invalid parameters
                 throw new DataSift_Exception_InvalidData($e->getMessage());
             default:
                 throw new DataSift_Exception_APIError('Unexpected APIError code: ' . $e->getCode() . ' [' . $e->getMessage() . ']');
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Page through recent push subscription log entries, specifying the sort
  * order.
  *
  * @param DataSift_User $user      The user making the request.
  * @param int           $page      Which page to fetch.
  * @param int           $per_page  Based on this page size.
  * @param string        $order_by  Which field to sort by.
  * @param string        $order_dir In asc[ending] or desc[ending] order.
  * @param string        $id        Push subscription ID.
  *
  * @return array Of LogEntry objects.
  * @throws DataSift_Exception_APIError
  * @throws DataSift_Exception_InvalidData
  * @throws DataSift_Exception_AccessDenied
  */
 public static function getLogs($user, $page = 1, $per_page = 20, $order_by = self::ORDERBY_REQUEST_TIME, $order_dir = self::ORDERDIR_ASC, $id = false)
 {
     if ($page < 1) {
         throw new DataSift_Exception_InvalidData('The specified page number is invalid');
     }
     if ($per_page < 1) {
         throw new DataSift_Exception_InvalidData('The specified per_page value is invalid');
     }
     $params = array();
     if ($id !== false && strlen($id) > 0) {
         $params['id'] = $id;
     }
     $params['page'] = $page;
     $params['per_page'] = $per_page;
     $params['order_by'] = $order_by;
     $params['order_dir'] = $order_dir;
     $res = $user->post('push/log', $params);
     $retval = array('count' => $res['count'], 'log_entries' => array());
     foreach ($res['log_entries'] as $log) {
         $retval['log_entries'][] = new DataSift_Push_LogEntry($log);
     }
     return $retval;
 }
Ejemplo n.º 5
0
 /**
  * Gets a single DataSift_Source object by ID
  *
  * @param DataSift_User $user The user making the request.
  * @param string        $id   The id of the Source to fetch
  *
  * @return DataSift_Source
  *
  * @throws DataSift_Exception_APIError
  * @throws DataSift_Exception_AccessDenied
  */
 public static function get(DataSift_User $user, $id)
 {
     $params = array('id' => $id);
     return new self($user, $user->post('source/get', $params));
 }