Class: WsConnectionData

Inherits:
Object
  • Object
show all
Defined in:
lib/hypertube-ruby-sdk/utils/ws_connection_data.rb

Constant Summary collapse

DEFAULT_CONNECT_TIMEOUT_SECONDS =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, connect_timeout = DEFAULT_CONNECT_TIMEOUT_SECONDS) ⇒ WsConnectionData

Returns a new instance of WsConnectionData.



8
9
10
11
12
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 8

def initialize(hostname, connect_timeout = DEFAULT_CONNECT_TIMEOUT_SECONDS)
  @hostname = hostname
  @connect_timeout = connect_timeout
  @headers = {}
end

Instance Attribute Details

#connect_timeoutObject

Returns the value of attribute connect_timeout.



6
7
8
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 6

def connect_timeout
  @connect_timeout
end

#hostnameObject

Returns the value of attribute hostname.



6
7
8
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 6

def hostname
  @hostname
end

Instance Method Details

#add_header(key, value) ⇒ Object



22
23
24
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 22

def add_header(key, value)
  @headers[key.to_s] = value.to_s
end

#add_headers(headers) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 26

def add_headers(headers)
  return if headers.nil?

  headers.each do |key, value|
    add_header(key, value)
  end
end

#connection_typeObject



14
15
16
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 14

def connection_type
  ConnectionType::WEB_SOCKET
end

#headersObject



18
19
20
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 18

def headers
  @headers.dup
end

#serialize_connection_dataObject



34
35
36
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 34

def serialize_connection_data
  [connection_type, 0, 0, 0, 0, 0, 0]
end

#to_canonical_keyObject



42
43
44
45
46
47
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 42

def to_canonical_key
  headers_for_key = serialize_headers_for_key
  return to_s if headers_for_key.empty?

  "#{to_s}|h:#{headers_for_key}"
end

#to_sObject



38
39
40
# File 'lib/hypertube-ruby-sdk/utils/ws_connection_data.rb', line 38

def to_s
  "websocket|#{@hostname}"
end