Class: NgrokAPI::Services::WeightedBackendsClient

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

Overview

A Weighted Backend balances traffic among the referenced backends. Traffic is assigned proportionally to each based on its weight. The percentage of traffic is calculated by dividing a backend's weight by the sum of all weights.

https://ngrok.com/docs/api#api-weighted-backends

Constant Summary collapse

PATH =

The API path for the requests

'/backends/weighted'
LIST_PROPERTY =

The List Property from the resulting API for list calls

'backends'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ WeightedBackendsClient

Returns a new instance of WeightedBackendsClient.



20
21
22
# File 'lib/ngrokapi/services/weighted_backends_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/weighted_backends_client.rb', line 18

def client
  @client
end

Instance Method Details

#create(description: "", metadata: "", backends: {}) ⇒ NgrokAPI::Models::WeightedBackend

Parameters:

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

    human-readable description of this backend. Optional

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

    arbitrary user-defined machine-readable data of this backend. Optional

  • backends (Map<string, int64>) (defaults to: {})

    the ids of the child backends to their weights (0-10000)

Returns:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ngrokapi/services/weighted_backends_client.rb', line 33

def create(description: "", metadata: "", backends: {})
  path = '/backends/weighted'
  replacements = {
  }
  data = {}
  data[:description] = description if description
  data[:metadata] =  if 
  data[:backends] = backends if backends
  result = @client.post(path % replacements, data: data)
  NgrokAPI::Models::WeightedBackend.new(client: self, result: result)
end

#delete(id: "") ⇒ NgrokAPI::Models::Empty

Delete a Weighted backend by ID. TODO what if used?

https://ngrok.com/docs/api#api-weighted-backends-delete

Parameters:

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

    a resource identifier

Returns:

  • (NgrokAPI::Models::Empty)

    result from the API request



52
53
54
55
56
57
58
# File 'lib/ngrokapi/services/weighted_backends_client.rb', line 52

def delete(id: "")
  path = '/backends/weighted/%{id}'
  replacements = {
    id: id,
  }
  @client.delete(path % replacements)
end

#delete!(id: "") ⇒ NgrokAPI::Models::Empty

Delete a Weighted backend by ID. TODO what if used? Throws an exception if API error.

https://ngrok.com/docs/api#api-weighted-backends-delete

Parameters:

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

    a resource identifier

Returns:

  • (NgrokAPI::Models::Empty)

    result from the API request



68
69
70
71
72
73
74
# File 'lib/ngrokapi/services/weighted_backends_client.rb', line 68

def delete!(id: "")
  path = '/backends/weighted/%{id}'
  replacements = {
    id: id,
  }
  @client.delete(path % replacements, danger: true)
end

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

Get detailed information about a Weighted backend by ID

https://ngrok.com/docs/api#api-weighted-backends-get

Parameters:

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

    a resource identifier

Returns:



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

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

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

Get detailed information about a Weighted backend by ID Throws an exception if API error.

https://ngrok.com/docs/api#api-weighted-backends-get

Parameters:

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

    a resource identifier

Returns:



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

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

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

List all Weighted backends on this account

https://ngrok.com/docs/api#api-weighted-backends-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:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ngrokapi/services/weighted_backends_client.rb', line 120

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,
    result: result,
    list_property: LIST_PROPERTY,
    klass: NgrokAPI::Models::WeightedBackend
  )
end

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

List all Weighted backends on this account Throws an exception if API error.

https://ngrok.com/docs/api#api-weighted-backends-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:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/ngrokapi/services/weighted_backends_client.rb', line 147

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,
    result: result,
    list_property: LIST_PROPERTY,
    klass: NgrokAPI::Models::WeightedBackend,
    danger: true
  )
end

#update(id: "", description: nil, metadata: nil, backends: {}) ⇒ NgrokAPI::Models::WeightedBackend

Parameters:

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

    human-readable description of this backend. Optional

  • metadata (string) (defaults to: nil)

    arbitrary user-defined machine-readable data of this backend. Optional

  • backends (Map<string, int64>) (defaults to: {})

    the ids of the child backends to their weights (0-10000)

Returns:



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ngrokapi/services/weighted_backends_client.rb', line 176

def update(id: "", description: nil, metadata: nil, backends: {})
  path = '/backends/weighted/%{id}'
  replacements = {
    id: id,
  }
  data = {}
  data[:description] = description if description
  data[:metadata] =  if 
  data[:backends] = backends if backends
  result = @client.patch(path % replacements, data: data)
  NgrokAPI::Models::WeightedBackend.new(client: self, result: result)
end

#update!(id: "", description: nil, metadata: nil, backends: {}) ⇒ NgrokAPI::Models::WeightedBackend

Update Weighted backend by ID Throws an exception if API error.

https://ngrok.com/docs/api#api-weighted-backends-update

Parameters:

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

    human-readable description of this backend. Optional

  • metadata (string) (defaults to: nil)

    arbitrary user-defined machine-readable data of this backend. Optional

  • backends (Map<string, int64>) (defaults to: {})

    the ids of the child backends to their weights (0-10000)

Returns:



200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ngrokapi/services/weighted_backends_client.rb', line 200

def update!(id: "", description: nil, metadata: nil, backends: {})
  path = '/backends/weighted/%{id}'
  replacements = {
    id: id,
  }
  data = {}
  data[:description] = description if description
  data[:metadata] =  if 
  data[:backends] = backends if backends
  result = @client.patch(path % replacements, data: data, danger: true)
  NgrokAPI::Models::WeightedBackend.new(client: self, result: result)
end