Class: NgrokAPI::Services::TunnelsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ngrokapi/services/tunnels_client.rb

Overview

Tunnels provide endpoints to access services exposed by a running ngrok agent tunnel session or an SSH reverse tunnel session.

https://ngrok.com/docs/api#api-tunnels

Constant Summary collapse

LIST_PROPERTY =

The List Property from the resulting API for list calls

'tunnels'
PATH =

The API path for the requests

'/tunnels'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ TunnelsClient

Returns a new instance of TunnelsClient.



20
21
22
# File 'lib/ngrokapi/services/tunnels_client.rb', line 20

def initialize(client:)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



18
19
20
# File 'lib/ngrokapi/services/tunnels_client.rb', line 18

def client
  @client
end

Instance Method Details

#get(id: "") ⇒ NgrokAPI::Models::Tunnel

Get the status of a tunnel by ID

https://ngrok.com/docs/api#api-tunnels-get

Parameters:

  • id (string) (defaults to: "")

    a resource identifier

Returns:



84
85
86
87
88
89
90
91
92
# File 'lib/ngrokapi/services/tunnels_client.rb', line 84

def get(id: "")
  path = '/tunnels/%{id}'
  replacements = {
    id: id,
  }
  data = {}
  result = @client.get(path % replacements, data: data)
  NgrokAPI::Models::Tunnel.new(client: self, attrs: result)
end

#get!(id: "") ⇒ NgrokAPI::Models::Tunnel

Get the status of a tunnel by ID Throws an exception if API error.

https://ngrok.com/docs/api#api-tunnels-get

Parameters:

  • id (string) (defaults to: "")

    a resource identifier

Returns:



102
103
104
105
106
107
108
109
110
# File 'lib/ngrokapi/services/tunnels_client.rb', line 102

def get!(id: "")
  path = '/tunnels/%{id}'
  replacements = {
    id: id,
  }
  data = {}
  result = @client.get(path % replacements, data: data, danger: true)
  NgrokAPI::Models::Tunnel.new(client: self, attrs: result)
end

#list(before_id: nil, limit: nil, url: nil) ⇒ NgrokAPI::Models::Listable

List all online tunnels currently running on the account.

https://ngrok.com/docs/api#api-tunnels-list

Parameters:

  • before_id (string) (defaults to: nil)
  • limit (string) (defaults to: nil)
  • url (string) (defaults to: nil)

    optional and mutually exclusive from before_id and limit

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ngrokapi/services/tunnels_client.rb', line 33

def list(before_id: nil, limit: nil, url: nil)
  result = @client.list(
    before_id: before_id,
    limit: limit,
    url: url,
    path: PATH
  )

  NgrokAPI::Models::Listable.new(
    client: self,
    attrs: result,
    list_property: LIST_PROPERTY,
    klass: NgrokAPI::Models::Tunnel
  )
end

#list!(before_id: nil, limit: nil, url: nil) ⇒ NgrokAPI::Models::Listable

List all online tunnels currently running on the account. Throws an exception if API error.

https://ngrok.com/docs/api#api-tunnels-list

Parameters:

  • before_id (string) (defaults to: nil)
  • limit (string) (defaults to: nil)
  • url (string) (defaults to: nil)

    optional and mutually exclusive from before_id and limit

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ngrokapi/services/tunnels_client.rb', line 59

def list!(before_id: nil, limit: nil, url: nil)
  result = @client.list(
    before_id: before_id,
    limit: limit,
    danger: true,
    url: url,
    path: PATH
  )

  NgrokAPI::Models::Listable.new(
    client: self,
    attrs: result,
    list_property: LIST_PROPERTY,
    klass: NgrokAPI::Models::Tunnel,
    danger: true
  )
end