Skip to content

Instantly share code, notes, and snippets.

@macournoyer
Forked from raggi/quicktalk.rb
Created November 12, 2009 02:12
Show Gist options
  • Save macournoyer/232530 to your computer and use it in GitHub Desktop.
Save macournoyer/232530 to your computer and use it in GitHub Desktop.
#!/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