Skip to content

Instantly share code, notes, and snippets.

@raggi
Created November 12, 2009 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raggi/232478 to your computer and use it in GitHub Desktop.
Save raggi/232478 to your computer and use it in GitHub Desktop.
A quick hack to post messages to talker chat rooms
#!/usr/bin/env ruby
domain, room, *message = ARGV
token = File.read(ENV['HOME'] + '/.talker').strip
abort <<-TEXT unless domain && room && token
Usage: #{File.basename($0)} domain room_id [message]
Reads from stdin if no message supplied
Expects a user token in $HOME/.talker
TEXT
require 'uri'
base_uri = URI("https://#{domain}.talkerapp.com/rooms/#{room}/messages")
message = message.join(' ')
message = $stdin.read if message.empty?
require 'net/https'
http = Net::HTTP.new base_uri.host, base_uri.port
http.use_ssl = base_uri.scheme == 'https'
http.start
req = Net::HTTP::Post.new(base_uri.path)
req.set_form_data({'message' => message})
req['Accept'] = 'application/json'
req['Content-Type'] = 'application/x-www-form-urlencoded'
req['X-Talker-Token'] = token
puts http.request(req).body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment