Last active
August 29, 2015 14:03
-
-
Save richcaudle/441ef26018ac5428e6b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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