Class: NgrokAPI::Services::ApiKeysClient

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

Overview

A client for interacting with the api_keys API

ngrok.com/docs/api#api-api-keys

Constant Summary collapse

LIST_PROPERTY =

The List Property from the resulting API for list calls

'keys'
PATH =

The API path for API keys

'/api_keys'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ ApiKeysClient

Returns a new instance of ApiKeysClient.



17
18
19
# File 'lib/ngrokapi/services/api_keys_client.rb', line 17

def initialize(client:)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



15
16
17
# File 'lib/ngrokapi/services/api_keys_client.rb', line 15

def client
  @client
end

Instance Method Details

#create(description: nil, metadata: nil) ⇒ NgrokAPI::Models::ApiKey

Create a new API key. The generated API key can be used to authenticate to the ngrok API.

ngrok.com/docs/api#api-api-keys-create

Parameters:

  • description (string) (defaults to: nil)

    human-readable description of what uses the API key to authenticate. optional, max 255 bytes.

  • metadata (string) (defaults to: nil)

    arbitrary user-defined data of this API key. optional, max 4096 bytes

Returns:



31
32
33
34
# File 'lib/ngrokapi/services/api_keys_client.rb', line 31

def create(description: nil, metadata: nil)
  result = @client.post(PATH, data: build_data(description: description, metadata: ))
  NgrokAPI::Models::ApiKey.new(client: self, result: result)
end

#delete(id: nil) ⇒ nil

Delete an API key by ID.

ngrok.com/docs/api#api-api-keys-delete

Parameters:

  • id (string) (defaults to: nil)

    a resource identifier

Returns:

  • (nil)

    result from delete request



44
45
46
# File 'lib/ngrokapi/services/api_keys_client.rb', line 44

def delete(id: nil)
  @client.delete("#{PATH}/#{id}")
end

#delete!(id: nil) ⇒ nil

Delete an API key by ID. Throw an exception if 404.

ngrok.com/docs/api#api-api-keys-delete

Parameters:

  • id (string) (defaults to: nil)

    a resource identifier

Returns:

  • (nil)

    result from delete request



55
56
57
# File 'lib/ngrokapi/services/api_keys_client.rb', line 55

def delete!(id: nil)
  @client.delete("#{PATH}/#{id}", danger: true)
end

#get(id: nil) ⇒ NgrokAPI::Models::ApiKey

Get the details of an API key by ID.

ngrok.com/docs/api#api-api-keys-get

Parameters:

  • id (string) (defaults to: nil)

    a resource identifier

Returns:



66
67
68
69
# File 'lib/ngrokapi/services/api_keys_client.rb', line 66

def get(id: nil)
  result = @client.get("#{PATH}/#{id}")
  NgrokAPI::Models::ApiKey.new(client: self, result: result)
end

#get!(id: nil) ⇒ NgrokAPI::Models::ApiKey

Get the details of an API key by ID. Throw an exception if 404.

ngrok.com/docs/api#api-api-keys-get

Parameters:

  • id (string) (defaults to: nil)

    a resource identifier

Returns:



78
79
80
81
# File 'lib/ngrokapi/services/api_keys_client.rb', line 78

def get!(id: nil)
  result = @client.get("#{PATH}/#{id}", danger: true)
  NgrokAPI::Models::ApiKey.new(client: self, result: result)
end

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

List all API keys owned by this account.

ngrok.com/docs/api#api-api-keys-list

Parameters:

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

    optional and mutually exclusive from before_id and limit

Returns:



92
93
94
95
96
97
98
99
100
# File 'lib/ngrokapi/services/api_keys_client.rb', line 92

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::ApiKey
  )
end

#update(id: nil, description: nil, metadata: nil) ⇒ NgrokAPI::Models::ApiKey

Update attributes of an API key by ID.

ngrok.com/docs/api#api-api-keys-update

Parameters:

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

    human-readable description of what uses the API key to authenticate. optional, max 255 bytes.

  • metadata (string) (defaults to: nil)

    arbitrary user-defined data of this API key. optional, max 4096 bytes

Returns:



113
114
115
116
# File 'lib/ngrokapi/services/api_keys_client.rb', line 113

def update(id: nil, description: nil, metadata: nil)
  result = @client.patch("#{PATH}/#{id}", data: build_data(description: description, metadata: ))
  NgrokAPI::Models::ApiKey.new(client: self, result: result)
end

#update!(id: nil, description: nil, metadata: nil) ⇒ NgrokAPI::Models::ApiKey

Update attributes of an API key by ID.

ngrok.com/docs/api#api-api-keys-update

Parameters:

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

    human-readable description of what uses the API key to authenticate. optional, max 255 bytes.

  • metadata (string) (defaults to: nil)

    arbitrary user-defined data of this API key. optional, max 4096 bytes

Returns:



127
128
129
130
131
# File 'lib/ngrokapi/services/api_keys_client.rb', line 127

def update!(id: nil, description: nil, metadata: nil)
  data = build_data(description: description, metadata: )
  result = @client.patch("#{PATH}/#{id}", danger: true, data: data)
  NgrokAPI::Models::ApiKey.new(client: self, result: result)
end