Class: RPC::Clients::NetHttp

Inherits:
Object
  • Object
show all
Defined in:
lib/rpc/lib/rpc/clients/net-http.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ NetHttp

Returns a new instance of NetHttp



20
21
22
23
24
# File 'lib/rpc/lib/rpc/clients/net-http.rb', line 20

def initialize(uri)
  @uri = URI.parse(uri)
  klass = Net.const_get(@uri.scheme.upcase)
  @client = klass.new(@uri.host, @uri.port)
end

Instance Method Details

#async?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rpc/lib/rpc/clients/net-http.rb', line 50

def async?
  false
end

#connectObject



26
27
28
# File 'lib/rpc/lib/rpc/clients/net-http.rb', line 26

def connect
  @client.start
end

#disconnectObject



30
31
32
# File 'lib/rpc/lib/rpc/clients/net-http.rb', line 30

def disconnect
  @client.finish
end

#run(&block) ⇒ Object



34
35
36
37
38
# File 'lib/rpc/lib/rpc/clients/net-http.rb', line 34

def run(&block)
  self.connect
  block.call
  self.disconnect
end

#send(data) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/rpc/lib/rpc/clients/net-http.rb', line 40

def send(data)
  path = @uri.path.empty? ? "/" : @uri.path

  begin
    @client.post(path, data, HEADERS).body
  rescue EOFError
    retry
  end
end