Class: NgrokV1::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ngrok-v1/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ngrok-v1/client.rb', line 5

def initialize(options = {})
  raise "Failed to find ngrok v1 binary." unless binary_installed?
  raise "Port number not specified." unless options.key?(:port)
  raise "Protocol not specified." unless options.key?(:protocol)

  @port = options[:port]
  @protocol = options[:protocol]
  @log = nil
  @pid = nil
  @uri = nil
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ngrok-v1/client.rb', line 36

def running?
  !@pid.nil?
end

#startObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/ngrok-v1/client.rb', line 17

def start
  return if running?

  @log = Tempfile.new("ngrok-v1")
  @pid = Process.spawn(execution_string)

  at_exit { stop } # Ensure process is killed if Ruby exits.

  @uri = parse_uri!
end

#stopObject



28
29
30
31
32
33
34
# File 'lib/ngrok-v1/client.rb', line 28

def stop
  return unless running?

  Process.kill("KILL", @pid)

  @pid = nil
end

#uriObject



40
41
42
# File 'lib/ngrok-v1/client.rb', line 40

def uri
  @uri if running?
end