Created
November 12, 2009 00:43
-
-
Save raggi/232478 to your computer and use it in GitHub Desktop.
A quick hack to post messages to talker chat rooms
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
#!/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