PHP code example of cwramsey / gnip-rules

1. Go to this page and download the library: Download cwramsey/gnip-rules library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cwramsey / gnip-rules example snippets




use Gnip\GnipRules;

$username = '';
$password = '';
$gnip_account_name = 'your_account_name';
$data_source = 'twitter';
$stream_label = 'stream_name';

$client = new GnipRules($username, $password, $gnip_account_name, $data_source, $stream_label);


$rules = $client->read(); // returns a Gnip\RuleList iterable with your full rule list.

foreach ($rules as $rule) {
	echo $rule->getValue() . " - " . $rule->getTag();
}


$new_rules = [
	[
    	'value' => 'rule1',
        'tag' => '123'
    ],
	[
    	'value' => 'rule2',
        'tag' => '123'
    ],
	[
    	'value' => 'rule3',
        'tag' => '123'
    ],
];

$updated_rules = $client->create($new_rules); // returns a GnipRuleList iterable with updated rules

$rules_to_delete = [
	[
    	'value' => 'rule1',
    ],
	[
    	'value' => 'rule2',
    ],
	[
    	'value' => 'rule3',
    ],
]; // please note that Gnip does not allow you to delete by tag, so you must only