Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# include the datasift library
require 'datasift'
# configuration options
config = {:username => 'YOUR_USERNAME', :api_key => 'YOUR_API_KEY', :enable_ssl => true}
# create a client
@datasift = DataSift::Client.new(config)
# Declare a filter in CSDL, looking for content mentioning music
csdl = 'interaction.content contains "music"'
# Compile the filter
filter = @datasift.compile csdl
# Handler: Message (i.e. a new Tweet) is received
on_message = lambda { |message, stream, hash| puts "Received interaction: #{message}" }
# Handler: Message deleted by user
on_delete = lambda { |stream, m| puts 'You must delete this to be compliant with T&Cs ==> ' + m }
# Handler: An error occurred
on_error = lambda { |stream, e| puts "An error has occurred: #{e.message}" }
# Handler: Connected to DataSift
on_connect = lambda do |stream|
puts 'Connected to DataSift'
stream.subscribe(filter[:data][:hash], on_message)
end
# Create stream object, and start streaming data
conn = DataSift::new_stream(config, on_delete, on_error, on_connect)
conn.stream.read_thread.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.