Skip to content

Instantly share code, notes, and snippets.

@albanpeignier
Created September 11, 2014 13:09
Show Gist options
  • Save albanpeignier/fb1165bf8148a2225800 to your computer and use it in GitHub Desktop.
Save albanpeignier/fb1165bf8148a2225800 to your computer and use it in GitHub Desktop.
Client Metalive - exemple
# 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
@albanpeignier
Copy link
Author

Pour récupérer le "title" de la description :

event["description"]["title"]

Pour l'utiliser dans un test :

if event["description"]["title"] == "start"
  system 'rmlsend PM\ 3\!'
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment