Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

53 lines (44 sloc) 1.517 kb
# This example consumes 1% of tweets, displaying a . for each interaction
# received, and an X for each delete notification.
# NB: Most of the error handling (exception catching) has been removed for
# the sake of simplicity. Nearly everything in this library may throw
# exceptions, and production code should catch them. See the documentation
# for full details.
# Include the DataSift library
require File.dirname(__FILE__) + '/../lib/datasift'
# Include the configuration - put your username and API key in this file
require 'yaml'
config = YAML::load(, '..', 'config.yml')))
# Authenticate
puts 'Creating user...'
user =['username'], config['api_key'])
# Create the definition
csdl = 'interaction.type == "twitter" AND interaction.sample < 1.0'
puts 'Creating definition...'
puts ' ' + csdl
definition = user.createDefinition(csdl)
# Create the consumer
puts 'Getting the consumer...'
consumer = definition.getConsumer(DataSift::StreamConsumer::TYPE_HTTP)
# Set up the delete event handler. Refer to the documentation for details of
# what the interaction variable will contain:
consumer.onDeleted do |interaction|
print 'X'
# And start consuming
puts 'Consuming...'
puts '--'
consumer.consume(true) do |interaction|
if interaction
print '.'
# This example will not stop unless it gets disconnected
puts 'Consumer stopped'
Jump to Line
Something went wrong with that request. Please try again.