Class: Lokal::Tunnel
- Inherits:
-
Object
- Object
- Lokal::Tunnel
- Defined in:
- lib/lokal.rb
Instance Attribute Summary collapse
-
#address_mdns ⇒ Object
Returns the value of attribute address_mdns.
-
#address_public ⇒ Object
Returns the value of attribute address_public.
-
#address_tunnel ⇒ Object
Returns the value of attribute address_tunnel.
-
#address_tunnel_port ⇒ Object
Returns the value of attribute address_tunnel_port.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ignore_duplicate ⇒ Object
Returns the value of attribute ignore_duplicate.
-
#inspect ⇒ Object
Returns the value of attribute inspect.
-
#local_address ⇒ Object
Returns the value of attribute local_address.
-
#lokal ⇒ Object
Returns the value of attribute lokal.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#server_id ⇒ Object
Returns the value of attribute server_id.
-
#startup_banner ⇒ Object
Returns the value of attribute startup_banner.
-
#tunnel_type ⇒ Object
Returns the value of attribute tunnel_type.
Instance Method Summary collapse
- #create ⇒ Object
- #get_lan_address ⇒ Object
- #get_public_address ⇒ Object
-
#initialize(lokal) ⇒ Tunnel
constructor
A new instance of Tunnel.
- #set_inspection(inspect) ⇒ Object
- #set_lan_address(lan_address) ⇒ Object
- #set_local_address(local_address) ⇒ Object
- #set_name(name) ⇒ Object
- #set_public_address(public_address) ⇒ Object
- #set_tunnel_type(tunnel_type) ⇒ Object
- #show_startup_banner ⇒ Object
Constructor Details
Instance Attribute Details
#address_mdns ⇒ Object
Returns the value of attribute address_mdns.
61 62 63 |
# File 'lib/lokal.rb', line 61 def address_mdns @address_mdns end |
#address_public ⇒ Object
Returns the value of attribute address_public.
61 62 63 |
# File 'lib/lokal.rb', line 61 def address_public @address_public end |
#address_tunnel ⇒ Object
Returns the value of attribute address_tunnel.
61 62 63 |
# File 'lib/lokal.rb', line 61 def address_tunnel @address_tunnel end |
#address_tunnel_port ⇒ Object
Returns the value of attribute address_tunnel_port.
61 62 63 |
# File 'lib/lokal.rb', line 61 def address_tunnel_port @address_tunnel_port end |
#id ⇒ Object
Returns the value of attribute id.
61 62 63 |
# File 'lib/lokal.rb', line 61 def id @id end |
#ignore_duplicate ⇒ Object
Returns the value of attribute ignore_duplicate.
61 62 63 |
# File 'lib/lokal.rb', line 61 def ignore_duplicate @ignore_duplicate end |
#inspect ⇒ Object
Returns the value of attribute inspect.
61 62 63 |
# File 'lib/lokal.rb', line 61 def inspect @inspect end |
#local_address ⇒ Object
Returns the value of attribute local_address.
61 62 63 |
# File 'lib/lokal.rb', line 61 def local_address @local_address end |
#lokal ⇒ Object
Returns the value of attribute lokal.
61 62 63 |
# File 'lib/lokal.rb', line 61 def lokal @lokal end |
#name ⇒ Object
Returns the value of attribute name.
61 62 63 |
# File 'lib/lokal.rb', line 61 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
61 62 63 |
# File 'lib/lokal.rb', line 61 def @options end |
#server_id ⇒ Object
Returns the value of attribute server_id.
61 62 63 |
# File 'lib/lokal.rb', line 61 def server_id @server_id end |
#startup_banner ⇒ Object
Returns the value of attribute startup_banner.
61 62 63 |
# File 'lib/lokal.rb', line 61 def @startup_banner end |
#tunnel_type ⇒ Object
Returns the value of attribute tunnel_type.
61 62 63 |
# File 'lib/lokal.rb', line 61 def tunnel_type @tunnel_type end |
Instance Method Details
#create ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/lokal.rb', line 112 def create raise "Please enable either LAN address or random/custom public URL" if @address_mdns.empty? && @address_public.empty? response = @lokal.rest.post('/api/tunnel/start') do |req| req.headers['Content-Type'] = 'application/json' req.body = to_json end @lokal.send(:check_server_version, response) data = JSON.parse(response.body) raise data['message'] unless data['success'] tunnel_data = data['data'].first update_attributes(tunnel_data) if @startup_banner self rescue Faraday::ClientError => e handle_duplicate_error(e) if @ignore_duplicate raise end |
#get_lan_address ⇒ Object
136 137 138 139 |
# File 'lib/lokal.rb', line 136 def get_lan_address raise "LAN address is not being set" if @address_mdns.empty? @address_mdns.end_with?('.local') ? @address_mdns : "#{@address_mdns}.local" end |
#get_public_address ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/lokal.rb', line 141 def get_public_address raise "Public address is not requested by client" if @address_public.empty? raise "Unable to assign public address" if @address_public.empty? if @tunnel_type != 'HTTP' && !@address_public.include?(':') update_public_url_port raise "Tunnel is using a random port, but it has not been assigned yet. Please try again later" end @address_public end |
#set_inspection(inspect) ⇒ Object
82 83 84 85 |
# File 'lib/lokal.rb', line 82 def set_inspection(inspect) @inspect = inspect self end |
#set_lan_address(lan_address) ⇒ Object
87 88 89 90 |
# File 'lib/lokal.rb', line 87 def set_lan_address(lan_address) @address_mdns = lan_address.chomp('.local') self end |
#set_local_address(local_address) ⇒ Object
72 73 74 75 |
# File 'lib/lokal.rb', line 72 def set_local_address(local_address) @local_address = local_address self end |
#set_name(name) ⇒ Object
97 98 99 100 |
# File 'lib/lokal.rb', line 97 def set_name(name) @name = name self end |
#set_public_address(public_address) ⇒ Object
92 93 94 95 |
# File 'lib/lokal.rb', line 92 def set_public_address(public_address) @address_public = public_address self end |
#set_tunnel_type(tunnel_type) ⇒ Object
77 78 79 80 |
# File 'lib/lokal.rb', line 77 def set_tunnel_type(tunnel_type) @tunnel_type = tunnel_type self end |
#show_startup_banner ⇒ Object
107 108 109 110 |
# File 'lib/lokal.rb', line 107 def @startup_banner = true self end |