Class: RPC::Clients::NetHttp
- Inherits:
-
Object
- Object
- RPC::Clients::NetHttp
- Defined in:
- lib/rpc/lib/rpc/clients/net-http.rb
Instance Method Summary (collapse)
- - (Boolean) async?
- - (Object) connect
- - (Object) disconnect
-
- (NetHttp) initialize(uri)
constructor
A new instance of NetHttp.
- - (Object) run(&block)
- - (Object) send(data)
Constructor Details
- (NetHttp) initialize(uri)
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
- (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 |