Created
September 11, 2014 13:09
-
-
Save albanpeignier/fb1165bf8148a2225800 to your computer and use it in GitHub Desktop.
Client Metalive - exemple
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
# Prerequires | |
# | |
# $ gem install eventmachine em-websocket-client json | |
# Building native extensions. This could take a while... | |
# Successfully installed eventmachine-1.0.3 | |
# Fetching: em-websocket-client-0.1.2.gem (100%) | |
# Successfully installed em-websocket-client-0.1.2 | |
# Building native extensions. This could take a while... | |
# Successfully installed json-1.8.1 | |
# 3 gems installed | |
# | |
# Run | |
# | |
# $ ruby metalive_client.rb | |
# {"description"=>{"title"=>"Test"}, "occurred_at"=>"2014-09-11T13:01:04.590205021Z", "uuid"=>"4223e28d-0e4d-4c13-ae34-6c04093dbd4f"} | |
# {"description"=>{"album"=>"Afro-Colombian Sound Modernizers", "artist"=>"Son Palenque", "group"=>"MUSIC", "title"=>"Cumbia Africana", "year"=>"YYYY"}, "occurred_at"=>"2014-09-11T13:05:06.071020001Z", "uuid"=>"a514fb08-dfdc-4a64-8fdb-bd323c988367"} | |
# ... | |
require 'eventmachine' | |
require 'em-websocket-client' | |
require 'json' | |
EM.run do | |
conn = EventMachine::WebSocketClient.connect("ws://metalive.tryphon.eu:8080/api/streams/test/events.ws") | |
conn.errback do |e| | |
puts "Got error: #{e}" | |
end | |
conn.disconnect do | |
puts "gone" | |
EM::stop_event_loop | |
end | |
conn.stream do |msg| | |
event = JSON.parse(msg.data) | |
puts event.inspect | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pour récupérer le "title" de la description :
Pour l'utiliser dans un test :