pikitgb
6/15/2015 - 8:34 PM

client_mqtt.rb

require 'mqtt'

topic_name = ARGV[0]
host_address = "localhost"

MQTT::Client.connect(host_address) do |c|
  # If you pass a block to the get method, then it will loop
  c.get(topic_name) do |topic,message|
    puts "#{topic}: #{message}"
  end
end

# Run
# ruby client_mqtt.rb "topic_name"

# ruby client_mqtt.rb "https://twitter.com/pikitgb"

# Produce:
https://twitter.com/pikitgb: {"_id":{"$oid":"557f365b4a7561f004050000"},"created_at":"2012-11-07T18:49:12.000Z","creator_id":null,"description":"Make it real
! Make it!!","favourites_count":16,"followers_count":41,"friends_count":177,"friends_extra_data":null,"geo_enabled":false,"id_str":"932696336","lang":"en","l
isted_count":0,"location":"Miami, Florida","modifier_id":null,"name":"J Ricardo","profile_background_color":"000000","profile_background_image_url":"http://a
bs.twimg.com/images/themes/theme14/bg.gif","profile_banner_url":"http://pbs.twimg.com/profile_banners/932696336/1428224512/web","profile_image_url":"http://p
bs.twimg.com/profile_images/584641645599006720/D70k-fXK_normal.png","profile_link_color":"3B94D9","profile_sidebar_border_color":"000000","profile_sidebar_fi
ll_color":"000000","profile_text_color":"000000","profile_uniquee_id":"557f36564a756169c60d0000","profile_url":"https://twitter.com/pikitgb","protected":fal$
e,"screen_name":"pikitgb","statuses_count":118,"updater_id":null,"verified":false,"version":1}