class KyotoTycoon::Tsvrpc::Skinny
Public Class Methods
new(host, port)
click to toggle source
# File lib/kyototycoon/tsvrpc/skinny.rb, line 6 def initialize(host, port) @host = host @port = port @tpl = "" @tpl << "POST %s HTTP/1.1\r\n" @tpl << "Content-Length: %d\r\n" @tpl << "Content-Type: text/tab-separated-values; colenc=%s\r\n" @tpl << "\r\n%s" at_exit { finish } end
Public Instance Methods
finish()
click to toggle source
# File lib/kyototycoon/tsvrpc/skinny.rb, line 52 def finish @sock.close if @sock && !@sock.closed? end
request(path, params, colenc)
click to toggle source
# File lib/kyototycoon/tsvrpc/skinny.rb, line 17 def request(path, params, colenc) start query = KyotoTycoon::Tsvrpc.build_query(params, colenc) request = @tpl % [path, query.bytesize, colenc, query] @sock.write(request) first_line = @sock.gets status = first_line[9, 3] bodylen = 0 body = "" colenc = nil loop do line = @sock.gets if line['Content-Type'] && line['colenc='] colenc = line.match(/colenc=([A-Z])/).to_a[1] next end if line['Content-Length'] bodylen = line.match(/[0-9]+/)[0].to_i next end if line == "\r\n" break end end body = @sock.read(bodylen) [status.to_i, body, colenc] end
start()
click to toggle source
# File lib/kyototycoon/tsvrpc/skinny.rb, line 47 def start @sock = nil if @sock && @sock.closed? @sock ||= ::TCPSocket.new(@host, @port) end