Class: Groonga::Client::Protocol::HTTP::Coolio

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/client/protocol/http/coolio.rb

Defined Under Namespace

Classes: GroongaHTTPClient, Request

Instance Method Summary collapse

Constructor Details

#initialize(host, port, options) ⇒ Coolio

Returns a new instance of Coolio.



69
70
71
72
73
74
# File 'lib/groonga/client/protocol/http/coolio.rb', line 69

def initialize(host, port, options)
  @host = host
  @port = port
  @options = options
  @loop = @options[:loop] || ::Coolio::Loop.default
end

Instance Method Details

#close(&block) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/groonga/client/protocol/http/coolio.rb', line 104

def close(&block)
  sync = !block_given?
  if sync
    false
  else
    yield
    EmptyRequest.new
  end
end

#connected?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/groonga/client/protocol/http/coolio.rb', line 100

def connected?
  false
end

#send(command, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/groonga/client/protocol/http/coolio.rb', line 76

def send(command, &block)
  client = GroongaHTTPClient.connect(@host, @port, block)
  client.attach(@loop)
  url = URI("http://#{@host}:#{@port}")
  if command.is_a?(Groonga::Command::Load)
    raw_values = command[:values]
    command[:values] = nil
    path = resolve_path(url, command.to_uri_format)
    command[:values] = raw_values
    options = {
      :head => {
        "content-type" => "application/json",
        "user-agent"   => @options[:user_agent],
      },
      :body => raw_values,
    }
    client.request("POST", path, options)
  else
    path = resolve_path(url, command.to_uri_format)
    client.request("GET", path)
  end
  Request.new(client, @loop)
end