Class: Freedb::FetchCGI
- Inherits:
-
Object
- Object
- Freedb::FetchCGI
- Defined in:
- lib/freedb.rb
Overview
:nodoc:
Instance Method Summary collapse
- #close ⇒ Object
- #gets ⇒ Object
-
#initialize(server, port, proxy, proxy_port, path) ⇒ FetchCGI
constructor
A new instance of FetchCGI.
- #send_cmd(cmd, args) ⇒ Object
Constructor Details
#initialize(server, port, proxy, proxy_port, path) ⇒ FetchCGI
Returns a new instance of FetchCGI.
449 450 451 452 453 454 455 |
# File 'lib/freedb.rb', line 449 def initialize(server, port, proxy, proxy_port, path) require "net/http" @session = Net::HTTP.new(server, port, proxy, proxy_port) @path = path @proto_level = 1 @res = [] end |
Instance Method Details
#close ⇒ Object
477 |
# File 'lib/freedb.rb', line 477 def close; end |
#gets ⇒ Object
472 473 474 475 |
# File 'lib/freedb.rb', line 472 def gets #(@res.nil? ? "" : @res.shift) @res.shift end |
#send_cmd(cmd, args) ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/freedb.rb', line 457 def send_cmd(cmd, args) if cmd == "hello" @hello_str = "hello=" + cgi_escape(args) @res << "201" #necessary for the next call to gets elsif cmd == "proto" @proto_level = args @res << "200" #necessary for the next call to gets else request = "?cmd=cddb+#{cmd}+#{cgi_escape(args)}&#{@hello_str}&proto=#{@proto_level}" resp, data = @session.get(@path + request) raise(FreedbError, "Bad HTTP response: #{resp.code} #{resp.} while querying server") unless resp.code == "200" @res.concat( data.split("\n") ) end end |