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

- (NetHttp) initialize(uri)



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

- (Boolean) async?



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

def async?
  false
end

- (Object) connect



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

def connect
  @client.start
end

- (Object) disconnect



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

def disconnect
  @client.finish
end

- (Object) run(&block)



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

- (Object) send(data)



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