Skip to content
Ruby client for DataSift
Failed to load latest commit information.
examples Resolved minor issues with API v1.3 PYLON examples Mar 8, 2016
lib rename 'auth' parameter into 'auth_ids' for 'source/auth/remove' endp… Jun 3, 2016
test Resolve merge conflicts + update VCR test fixtures Nov 13, 2015
.gitignore Minor updates to docs May 6, 2015
.rubocop_todo.yml Trivial refactoring (mainly comments/whitespace) in examples Nov 13, 2015
.travis.yml Test against ruby-head, but allow failures Sep 24, 2015
.yardopts Documented /analysis endpoints using Yard Docs Feb 23, 2015 Bump to v3.6.2 Jun 3, 2016
Gemfile Loosen some Gem dependancies. Successfully tested against rest-client… Oct 22, 2015
LICENSE Happy New Year! 2015 Jan 5, 2015 Typo Jun 25, 2014 Adds historics_id param for dpu endpoint May 15, 2015
Rakefile Add Bundler build tasks to Rakefile Jul 1, 2014
VERSION Bump to v3.6.2 Jun 3, 2016
datasift.gemspec Loosen some Gem dependancies. Successfully tested against rest-client… Oct 22, 2015


Gem Version Build Status

The official Ruby library for accessing the DataSift API.

Getting Started

Read our Ruby Getting Started Guide to get started with the DataSift platform. The guide will take you through creating a DataSift account, and activating data sources which you will need to do before using the DataSift API.

Many of the examples and API endpoints used in this library require you have enabled certain data sources before you can receive any data (you should do this at Certain API features, such as Historics and Managed Sources will require you have signed up to a monthly subscription before you can access them.

If you are interested in using these features, or would like more information about DataSift, please get in touch!

Install Instructions

sudo gem install datasift


If you're using the source you'll need to install the dependencies.

sudo gem install rest-client multi_json websocket-td

The library will use SSL connections by default. While we recommend using SSL you may disable it if required by passing enable_ssl: false as the third parameter when creating your @config object.

Simple example

This example looks for anything that contains the word "football" in real-time, and simply prints the content to the screen as they come in.

require 'datasift'
@config = { username: 'DATASIFT_USERNAME', api_key: 'DATASIFT_API_KEY' }
@datasift =
csdl = 'interaction.content contains "football"'
filter = @datasift.compile csdl
receivedCount = 0

on_delete = lambda { |stream, m| puts 'We must delete this to be compliant ==> ' + m }
on_error = lambda { |stream, e| puts "A serious error has occurred: #{e.message}" }
on_message = lambda do |message, stream, hash|
  receivedCount += 1
  puts "Received interaction: #{message}"

  if receivedCount >= 5
    puts "Unsubscribing from hash #{hash}"
    stream.unsubscribe hash

on_connect = lambda do |stream|
  stream.subscribe(filter[:data][:hash], on_message)
  puts 'Subscribed to '+ filter[:data][:hash]

on_datasift_message = lambda do |stream, message, hash|
  #not all messages have a hash
  puts "is_success =  #{message[:is_success]}, is_failure =  #{message[:is_failure]}, is_warning =  #{message[:is_warning]}, is_tick =  #{message[:is_tick]}"
  puts "DataSift Message #{hash} ==> #{message}"

conn = DataSift::new_stream(@config, on_delete, on_error, on_connect)
conn.on_datasift_message = on_datasift_message

Supported Operating Environment

This version of the client library has been tested, and is known to work against the following language versions and Operating Systems:

Language Versions

  • Ruby 1.9.3 (Support for Ruby 1.x will be dropped from v4.0 of the library)
  • Ruby 2.0
  • Ruby 2.1
  • Ruby 2.2

Operating Systems

  • Linux
  • Ubuntu
  • OS X
  • Windows 7/8


Contributions are always welcome and appreciated

  1. Fork on GitHub
  2. Create a feature branch (we use Gitflow for branching)
  3. Commit your changes with tests
    • New feature? Send a pull request against the develop branch.
    • Bug fix? Send a pull request against the master branch.
    • Please don't break backwards-compatibility :)


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.

Something went wrong with that request. Please try again.