Difference between revisions of "Ruby"

From Open Rail Data Wiki
Jump to navigation Jump to search
m (Redirected to new Ruby examples page)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
+
#REDIRECT [[Ruby_Examples]]
 
 
== Simple Ruby script ==
 
Here is a very simple Ruby script to get you subscribing to messages, they simply get output to the console.
 
You'll obviously need Ruby installed (I'm using 1.9.3 via RVM) and the stomp ruby gem installed <code>gem install stomp</code>
 
 
 
You will of course, also need to have signed up to the Network Rail datafeed programme and have your login credentials.
 
Then set up environment variables with DATAFEEDS_USER as your username and DATAFEEDS_PASSWORD as your password.
 
 
 
<code>
 
require 'stomp'
 
 
begin
 
  # Credentials set here as environment variables
 
  @user = ENV["DATAFEEDS_USER"];
 
  @password = ENV["DATAFEEDS_PASSWORD"]
 
  @host = "datafeeds.networkrail.co.uk"
 
  @port = 61618
 
 
  # Example destination add yours here
 
  @destination = "/topic/TD_ALL_SIG_AREA"
 
 
  puts "Connecting to datafeeds as #{@user} using stomp protocol stomp://#{@host}:#{@port}\n"
 
  @connection = Stomp::Connection.open @user, @password, @host, @port, true
 
  @connection.subscribe @destination
 
 
  while true
 
    @msg = @connection.receive
 
    puts @msg
 
  end
 
  @connection.disconnect
 
rescue
 
end
 
</code>
 

Latest revision as of 17:55, 9 July 2013

Redirect to: