Class: NetHttp2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/net-http2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
# File 'lib/net-http2/client.rb', line 11

def initialize(uri, options={})
  @uri         = URI.parse(uri)
  @ssl_context = options[:ssl_context] || OpenSSL::SSL::SSLContext.new

  @is_ssl = (@uri.scheme == 'https')

  @pipe_r, @pipe_w = Socket.pair(:UNIX, :STREAM, 0)
  @socket_thread   = nil
  @mutex           = Mutex.new
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/net-http2/client.rb', line 9

def uri
  @uri
end

Instance Method Details

#async_delete(path, headers = {}, options = {}, &block) ⇒ Object



57
58
59
60
# File 'lib/net-http2/client.rb', line 57

def async_delete(path, headers={}, options={}, &block)
  request = NetHttp2::Request::Delete.new(@uri, path, headers, options)
  async_call_with request, &block
end

#async_get(path, headers = {}, options = {}, &block) ⇒ Object



42
43
44
45
# File 'lib/net-http2/client.rb', line 42

def async_get(path, headers={}, options={}, &block)
  request = NetHttp2::Request::Get.new(@uri, path, headers, options)
  async_call_with request, &block
end

#async_post(path, body, headers = {}, options = {}, &block) ⇒ Object



47
48
49
50
# File 'lib/net-http2/client.rb', line 47

def async_post(path, body, headers={}, options={}, &block)
  request = NetHttp2::Request::Post.new(@uri, path, body, headers, options)
  async_call_with request, &block
end

#async_put(path, body, headers = {}, options = {}, &block) ⇒ Object



52
53
54
55
# File 'lib/net-http2/client.rb', line 52

def async_put(path, body, headers={}, options={}, &block)
  request = NetHttp2::Request::Put.new(@uri, path, body, headers, options)
  async_call_with request, &block
end

#closeObject



66
67
68
69
70
71
72
73
# File 'lib/net-http2/client.rb', line 66

def close
  exit_thread(@socket_thread)

  @h2            = nil
  @pipe_r        = nil
  @pipe_w        = nil
  @socket_thread = nil
end

#delete(path, headers = {}, options = {}) ⇒ Object



37
38
39
40
# File 'lib/net-http2/client.rb', line 37

def delete(path, headers={}, options={})
  request = NetHttp2::Request::Delete.new(@uri, path, headers, options)
  call_with request
end

#get(path, headers = {}, options = {}) ⇒ Object



22
23
24
25
# File 'lib/net-http2/client.rb', line 22

def get(path, headers={}, options={})
  request = NetHttp2::Request::Get.new(@uri, path, headers, options)
  call_with request
end

#post(path, body, headers = {}, options = {}) ⇒ Object



27
28
29
30
# File 'lib/net-http2/client.rb', line 27

def post(path, body, headers={}, options={})
  request = NetHttp2::Request::Post.new(@uri, path, body, headers, options)
  call_with request
end

#put(path, body, headers = {}, options = {}) ⇒ Object



32
33
34
35
# File 'lib/net-http2/client.rb', line 32

def put(path, body, headers={}, options={})
  request = NetHttp2::Request::Put.new(@uri, path, body, headers, options)
  call_with request
end

#ssl?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/net-http2/client.rb', line 62

def ssl?
  @is_ssl
end