Class: Caldecott::Client::Tunnel

Inherits:
Object
  • Object
show all
Defined in:
lib/caldecott-client/tunnel/tunnel.rb

Direct Known Subclasses

HttpTunnel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options) ⇒ Tunnel

Returns a new instance of Tunnel.



22
23
24
25
26
27
28
29
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 22

def initialize(url, options)
  @url = url
  @dst_host = options[:dst_host]
  @dst_port = options[:dst_port]
  @token = options[:token]
  @logger = Caldecott.logger
  @closed = false
end

Instance Attribute Details

#dst_hostObject (readonly)

Returns the value of attribute dst_host.



20
21
22
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 20

def dst_host
  @dst_host
end

#dst_portObject (readonly)

Returns the value of attribute dst_port.



20
21
22
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 20

def dst_port
  @dst_port
end

#loggerObject (readonly)

Returns the value of attribute logger.



20
21
22
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 20

def logger
  @logger
end

#tokenObject (readonly)

Returns the value of attribute token.



20
21
22
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 20

def token
  @token
end

#urlObject (readonly)

Returns the value of attribute url.



20
21
22
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 20

def url
  @url
end

Class Method Details

.for_url(url, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 7

def self.for_url(url, options)
  case url
    when /^https?/
      HttpTunnel.new(url, options)
    when /^ws/
      # TODO: implement
      raise NotImplemented, "Web Sockets support coming soon"
    else
      raise InvalidTunnelUrl,
            "Invalid tunnel url: #{url}, only HTTP and WS schemas supported"
  end
end

Instance Method Details

#closeObject



31
32
33
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 31

def close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 35

def closed?
  @closed
end

#readObject

Raises:



47
48
49
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 47

def read
  raise NotImplemented, "#read not implemented for #{self.class.name}"
end

#startObject

Raises:



39
40
41
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 39

def start
  raise NotImplemented, "#start not implemented for #{self.class.name}"
end

#stopObject

Raises:



51
52
53
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 51

def stop
  raise NotImplemented, "#stop not implemented for #{self.class.name}"
end

#write(data) ⇒ Object

Raises:



43
44
45
# File 'lib/caldecott-client/tunnel/tunnel.rb', line 43

def write(data)
  raise NotImplemented, "#write not implemented for #{self.class.name}"
end