Class: Hypertube::Utils::PluginConnectionData
- Inherits:
-
ConnectionData
- Object
- ConnectionData
- Hypertube::Utils::PluginConnectionData
- Defined in:
- lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb
Constant Summary
Constants inherited from ConnectionData
ConnectionData::THREAD_LOCAL_HEADERS_KEY
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#plugin_config ⇒ Object
readonly
Returns the value of attribute plugin_config.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #connection_type ⇒ Object
- #get_address_bytes ⇒ Object
- #get_config ⇒ Object
- #get_port_bytes ⇒ Object
-
#initialize(hostname, plugin_config) ⇒ PluginConnectionData
constructor
A new instance of PluginConnectionData.
- #serialize_connection_data ⇒ Object
- #to_s ⇒ Object
Methods inherited from ConnectionData
#get_headers, #get_thread_local_headers, #set_headers, #set_thread_local_headers, #to_canonical_key
Constructor Details
#initialize(hostname, plugin_config) ⇒ PluginConnectionData
Returns a new instance of PluginConnectionData.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 9 def initialize(hostname, plugin_config) super() host_only, port = parse_hostname(hostname) @hostname = "#{host_only}:#{port}" @port = port @plugin_config = plugin_config.to_s if host_only == 'localhost' @ip_address = '127.0.0.1' else begin @ip_address = IPSocket.getaddress(host_only) rescue SocketError raise 'Unable to resolve hostname to an IP address.' end end end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
7 8 9 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7 def hostname @hostname end |
#ip_address ⇒ Object (readonly)
Returns the value of attribute ip_address.
7 8 9 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7 def ip_address @ip_address end |
#plugin_config ⇒ Object (readonly)
Returns the value of attribute plugin_config.
7 8 9 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7 def plugin_config @plugin_config end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 7 def port @port end |
Instance Method Details
#connection_type ⇒ Object
26 27 28 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 26 def connection_type ConnectionType::PLUGIN end |
#get_address_bytes ⇒ Object
38 39 40 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 38 def get_address_bytes @ip_address.split('.').map(&:to_i) end |
#get_config ⇒ Object
34 35 36 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 34 def get_config @plugin_config end |
#get_port_bytes ⇒ Object
42 43 44 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 42 def get_port_bytes [@port & 0xFF, @port >> 8] end |
#serialize_connection_data ⇒ Object
46 47 48 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 46 def serialize_connection_data [Hypertube::Utils::ConnectionType::PLUGIN] + get_address_bytes + get_port_bytes end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/hypertube-ruby-sdk/utils/plugin_connection_data.rb', line 30 def to_s "plugin|#{@hostname}" end |