PHP client to interface with DataSift
PHP Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
tests
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
composer.json
config.php

README.md

DataSift PHP Client Library

Build Status

This is the official PHP library for accessing Datasift. See the examples folder for some simple example usage.

Getting Started

To get started choose one of our quick start guides:

Simple example

This example looks for anything that contains the word "datasift" and simply prints the content to the screen as they come in.

<?php
  // Load the library (If you're using this library standalone)
  require 'lib/datasift.php';
  // Load the library via Composer
  //require '/path/to/vendor/autoload.php';

  // An object of this type will receive events
  class EventHandler implements DataSift_IStreamConsumerEventHandler
  {
    public function onInteraction($consumer, $interaction, $hash)
    {
      echo $interaction['interaction']['content']."\n";
    }

    // Ignore the other events for the purposes of this example.
    public function onConnect($consumer)                      { }
    public function onDeleted($consumer, $interaction, $hash) { }
    public function onStatus($consumer, $type, $info)         { }
    public function onWarning($consumer, $message)            { }
    public function onError($consumer, $message)              { }
    public function onDisconnect($consumer)                   { }
    public function onStopped($consumer, $reason)             { }
  }
  // Create the user
  $user = new DataSift_User('your username', 'your api_key');
  // Create a definition looking for the word "datasift"
  $def = $user->createDefinition('interaction.content contains "datasift"');
  // Get an HTTP stream consumer for that definition
  $consumer = $def->getConsumer(DataSift_StreamConsumer::TYPE_HTTP, new EventHandler());
  // Consume it - this will not return unless the stream gets disconnected
  $consumer->consume();
?>

See the DataSift documentation for full details of the data contained within each interaction. See this page on our developer site for an example interaction: http://dev.datasift.com/docs/targets/interaction/mapping

Contributing

Please feel free to contribute to this repository using pull requests.

The unit tests should be run with phpunit.

Note that we use git flow to manage development.

Requirements

The library will use SSL connections by default. While we recommend using SSL you may disable it if required by passing false as the third parameter when creating a user, or by calling $user->enableSSL(false) on the user object.

License

All code contained in this repository is Copyright 2011-2015 MediaSift Ltd.

This code is released under the BSD license. Please see the LICENSE file for more details.