Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andimiller committed Mar 2, 2016
2 parents fba7221 + 087e57c commit 8ad9ac8
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 65 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
Changelog
=========================

##v.2.6.0 (2016-03-02)
### Added
* DataSift_Pylon::update added for hotswapping filters

### Changed
* Pylon endpoints now take and return a recording ID, rather than a hash
* Moved to v1.3 API

##v.2.5.1
###Fixed
* Fixed an issue with ```DataSift_Pylon::getStart```.
Expand Down
55 changes: 55 additions & 0 deletions examples/pylon/analysis-with-offset.php
@@ -0,0 +1,55 @@
<?php
/**
* This simple example demonstrates how get a PYLON recording by it's ID,
* then run a simple analysis query on that recording with a timezone offset
*
* @category DataSift
* @package PHP-client
* @author Jason Dugdale <jason.dugdale@datasift.com>
* @copyright 2105 MediaSift Ltd.
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://www.mediasift.com
*/

// Include the DataSift library
require dirname(__FILE__) . '/../../lib/datasift.php';

// Include the configuration - put your username and API key in this file
require dirname(__FILE__) . '/../../config.php';

if (function_exists('date_default_timezone_set')) {
date_default_timezone_set('UTC');
}

// Authenticate
echo "Creating user...\n";
$user = new DataSift_User(USERNAME, API_KEY, false);

//Set your Analysis Query values
$hash = '<YOUR_RECORDING_HASH>'; // This must be the hash of an active recording
// This filter will likely get redacted; change to something related to your recording, or exclude
$filter = 'fb.content contains "some content"';
$start = mktime(0, 0, 0, date('n'), date('j') - 7); // 7 days ago
$end = mktime(0, 0, 0, date('n'), date('j')); // This morning

// Get the PYLON recording by hash
$pylon = DataSift_Pylon::fromHash($user, $hash);

//Set your Analysis Query parameters
$parameters = array(
'analysis_type' => 'timeSeries',
'parameters' => array(
'interval' => 'day',
'offset' => -5
)
);

try {
//Analyze the recording
$analyze = $pylon->analyze($parameters, false, $start, $end, false);
} catch (Exception $e) {
echo "Caught exception during analysis:\n";
print_r($e);
}

echo json_encode($analyze, true);
12 changes: 10 additions & 2 deletions examples/pylon/pylon.php
Expand Up @@ -21,7 +21,7 @@
echo "Creating user...\n";
$user = new DataSift_User(USERNAME, API_KEY, false);

$csdl = '(fb.content any "coffee" OR fb.hashtags in "tea") AND fb.language in "en"';
$csdl = '(fb.content any "coffee, tea" OR fb.hashtags in "tea") AND fb.language in "en"';

//Validate the CSDL
$validate = DataSift_Pylon::validate($user, $csdl);
Expand All @@ -45,6 +45,14 @@

//Stop after 10 seconds
sleep(10);

//Compile some new CSDL
$pylon->setCsdl('(fb.content any "coffee, tea, flour" OR fb.hashtags in "tea") AND fb.language in "en"');
$pylon->compile();

//Update the recording with the new definition
$pylon->update();

$pylon->stop();

//Set the analyze parameters
Expand Down Expand Up @@ -80,4 +88,4 @@

echo "There were a total of {$analyze['interactions']} interactions that matched this filter\n";

$reloaded_pylon = DataSift_Pylon::fromHash($user, $pylon->getHash());
$reloaded_pylon = DataSift_Pylon::fromId($user, $pylon->getId());
21 changes: 21 additions & 0 deletions lib/DataSift/Account.php
Expand Up @@ -48,6 +48,27 @@ public function __construct(DataSift_User $user)
{
$this->_user = $user;
}

/**
* Returns the user agent this library should use for all API calls.
*
* @return string
*/
public function usage($start = false, $end = false)
{
$params = array();

if ($start)
{
$params['start'] = $start;
}
if ($end)
{
$params['end'] = $end;
}

return $this->_user->get('account/usage', $params);
}

/**
* Returns the user agent this library should use for all API calls.
Expand Down

0 comments on commit 8ad9ac8

Please sign in to comment.