Add a bunch of documentation that can be generated with yard

This commit is contained in:
David Parker
2021-09-10 15:39:50 -06:00
parent e3d602c403
commit 28015a737a
17 changed files with 608 additions and 127 deletions
+2
View File
@@ -24,4 +24,6 @@ end
group :development, :test do
# https://github.com/pry/pry
gem 'pry'
# https://github.com/lsegal/yard
gem 'yard'
end
+2
View File
@@ -7,5 +7,7 @@ Dir[File.join('.', 'lib', '**/*.rb')].each do |f|
require f
end
##
# The Module which contains the Ngrok API gem
module NgrokAPI
end
+91 -29
View File
@@ -1,6 +1,9 @@
# frozen_string_literal: true
module NgrokAPI
##
# Low-level api client for communicating with Ngrok's HTTP API.
# Use this object to instantiate your clients.
class Client
attr_reader :api_key,
:base_url
@@ -13,28 +16,107 @@ module NgrokAPI
@base_url = base_url
end
##
# Creates and returns an instance of a NgrokAPI::Services::ApiKeysClient
#
# @return [NgrokAPI::Services::ApiKeysClient]
def api_keys
@_api_keys ||= NgrokAPI::Services::ApiKeysClient.new(client: self)
end
##
# Creates and returns an instance of a NgrokAPI::Services::EndpointConfigurationsClient
#
# @return [NgrokAPI::Services::EndpointConfigurationsClient]
def endpoint_configurations
@_endpoint_configurations ||= NgrokAPI::Services::EndpointConfigurationsClient.new(
client: self
)
end
def event_streams
# @_event_streams ||= NgrokAPI::Services::EventStreamsClient.new(client: self)
end
##
# Creates and returns an instance of a NgrokAPI::Services::ReservedDomainsClient
#
# @return [NgrokAPI::Services::ReservedDomainsClient]
def reserved_domains
@_reserved_domains ||= NgrokAPI::Services::ReservedDomainsClient.new(client: self)
end
##
# Creates and returns an instance of a NgrokAPI::Services::TlsCertificatesClient
#
# @return [NgrokAPI::Services::TlsCertificatesClient]
def tls_certificates
@_tls_certificates ||= NgrokAPI::Services::TlsCertificatesClient.new(client: self)
end
##
# Make a DELETE request to a given URI
#
# @param [string] path URL resource path
# @return [nil]
def delete(path)
uri = get_uri(path)
req = Net::HTTP::Delete.new(uri, headers)
json_do(uri, req)
end
##
# Make a GET request to a given URI with optional data
#
# @param [string] path URL resource path
# @param [hash] data hash which will be converted to query parameters or form data
# @return [json] response body
def get(path, data: {})
uri = get_uri(path, data: data)
req = Net::HTTP::Get.new(uri, headers)
json_do(uri, req)
end
##
# Make a GET request
#
# @param [string] before_id URL resource path
# @param [integer] limit URL resource path
# @param [string] path resource path, mutually exclusive with url
# @param [string] url Full URL of the resource, mutually exclusive with path
# @return [json] response body
def list(before_id: nil, limit: nil, path: nil, url: nil)
if path
data = {}
data[:before_id] = before_id if before_id
data[:limit] = limit if limit
get(path, data: data)
else
get(url)
end
end
##
# Make a PATCH request to a given URI with optional data
#
# @param [string] path URL resource path
# @param [hash] data hash which will be converted to query parameters or form data
# @return [json] response body
def patch(path, data: {})
uri = get_uri(path)
req = Net::HTTP::Patch.new(uri, headers_with_json)
json_do(uri, req, data: data.to_json)
end
##
# Make a POST request to a given URI with optional data
#
# @param [string] path URL resource path
# @param [hash] data hash which will be converted to query parameters or form data
# @return [json] response body
def post(path, data: {})
uri = get_uri(path)
req = Net::HTTP::Post.new(uri, headers_with_json)
json_do(uri, req, data: data.to_json)
end
private
def headers
{
'Authorization': "Bearer #{@api_key}",
@@ -57,34 +139,14 @@ module NgrokAPI
{ use_ssl: uri.scheme == 'https' }
end
def get_uri(path, data: nil)
data = data != nil ? "?#{URI.encode_www_form(data)}" : ""
uri = URI("#{url(path)}#{data}")
end
def url(path)
path = path.delete_prefix(@base_url)
"#{@base_url}#{path}"
end
def delete(path)
uri = URI(url(path))
req = Net::HTTP::Delete.new(uri, headers)
json_do(uri, req)
end
def get(path, data: {})
data = data != {} ? "?#{URI.encode_www_form(data)}" : ""
uri = URI("#{url(path)}#{data}")
req = Net::HTTP::Get.new(uri, headers)
json_do(uri, req)
end
def patch(path, data: {})
uri = URI(url(path))
req = Net::HTTP::Patch.new(uri, headers_with_json)
json_do(uri, req, data: data.to_json)
end
def post(path, data: {})
uri = URI(url(path))
req = Net::HTTP::Post.new(uri, headers_with_json)
json_do(uri, req, data: data.to_json)
end
end
end
+16
View File
@@ -2,6 +2,8 @@
module NgrokAPI
module Models
##
# A resource representing data from the api_keys API
class ApiKey
attr_reader :id,
:client,
@@ -31,10 +33,24 @@ module NgrokAPI
def to_s
end
##
# Delete this API key.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-api-keys-delete
def delete
@client.delete(id: @id)
end
##
# Update the attributes of this API key.
#
# @param [string] description human-readable description of what uses the API key to authenticate. optional, max 255 bytes.
# @param [string] metadata arbitrary user-defined data of this API key. optional, max 4096 bytes
# @return [NgrokAPI::Models::ApiKey] result from update request
#
# https://ngrok.com/docs/api#api-api-keys-update
def update(description: nil, metadata: nil)
@description = description if description
@metadata = metadata if metadata
-33
View File
@@ -1,33 +0,0 @@
# frozen_string_literal: true
module NgrokAPI
module Models
class ApiKeyList
attr_reader :client,
:keys,
:iter,
:next_page_uri,
:result,
:uri
def initialize(client:, result:)
@client = client
@result = result
@next_page_uri = @result['next_page_uri']
@uri = @result['uri']
@keys = @result['keys'].each do |result|
NgrokAPI::Models::ApiKey.new(client: client, result: result)
end
@iter = NgrokAPI::PagedIterator.new(client: client, page: self, list_property: 'keys')
end
# TODO: equality
def ==(other)
end
# TODO: to_s
def to_s
end
end
end
end
+75 -2
View File
@@ -2,6 +2,8 @@
module NgrokAPI
module Models
##
# A resource representing data from the endpoint_configuration API
class EndpointConfiguration
attr_reader :id,
:client,
@@ -29,14 +31,85 @@ module NgrokAPI
def to_s
end
##
# Delete this endpoint configuration.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-endpoint-configurations-delete
def delete
@client.delete(id: @id)
end
def update(description: nil, metadata: nil)
##
# Update this endpoint configuration. If a module is not specified in the update, it will not be modified.
# However, each module configuration that is specified will completely replace the existing value.
# There is no way to delete an existing module via this API, instead use the delete module API.
#
# @param [string] description human-readable description of what this endpoint configuration will be do when applied or what traffic it will be applied to. Optional, max 255 bytes
# @param [string] metadata arbitrary user-defined machine-readable data of this endpoint configuration. Optional, max 4096 bytes.
# @param [string] circuit_breaker circuit breaker module configuration
# @param [string] compression compression module configuration
# @param [string] request_headers request headers module configuration
# @param [string] response_headers response headers module configuration
# @param [string] ip_policy ip policy module configuration
# @param [string] mutual_tls mutual TLS module configuration
# @param [string] tls_termination TLS termination module configuration
# @param [string] webhook_validation webhook validation module configuration
# @param [string] oauth oauth module configuration
# @param [string] logging logging module configuration
# @param [string] saml saml module configuration
# @param [string] oidc oidc module configuration
# @return
#
# https://ngrok.com/docs/api#api-endpoint-configurations-update
def update(
description: nil,
metadata: nil,
circuit_breaker: nil,
compression: nil,
request_headers: nil,
response_headers: nil,
ip_policy: nil,
mutual_tls: nil,
tls_termination: nil,
webhook_validation: nil,
oauth: nil,
logging: nil,
saml: nil,
oidc: nil
)
@description = description if description
@metadata = metadata if metadata
@client.update(id: @id, description: description, metadata: metadata)
@circuit_breaker = circuit_breaker if circuit_breaker
@compression = compression if compression
@request_headers = request_headers if request_headers
@response_headers = response_headers if response_headers
@ip_policy = ip_policy if ip_policy
@mutual_tls = mutual_tls if mutual_tls
@tls_termination = tls_termination if tls_termination
@webhook_validation = webhook_validation if webhook_validation
@oauth = oauth if oauth
@logging = logging if logging
@saml = saml if saml
@oidc = oidc if oidc
@client.update(
id: @id,
description: description,
metadata: metadata,
circuit_breaker: circuit_breaker,
compression: compression,
request_headers: request_headers,
response_headers: response_headers,
ip_policy: ip_policy,
mutual_tls: mutual_tls,
tls_termination: tls_termination,
webhook_validation: webhook_validation,
oauth: oauth,
logging: logging,
saml: saml,
oidc: oidc
)
end
end
end
+3 -1
View File
@@ -2,6 +2,8 @@
module NgrokAPI
module Models
##
# A resource representing multiple instances from a given "list" API call
class Listable
attr_reader :client,
:klass,
@@ -18,7 +20,7 @@ module NgrokAPI
@list_property = list_property
@next_page_uri = @result['next_page_uri']
@uri = @result['uri']
@items = @result[list_property].each do |result|
@items = @result[list_property].map do |result|
klass.new(client: client, result: result)
end
@iter = NgrokAPI::PagedIterator.new(
+76 -4
View File
@@ -2,6 +2,8 @@
module NgrokAPI
module Models
##
# A resource representing data from the reserved_domains API
class ReservedDomain
attr_reader :id,
:certificate,
@@ -45,10 +47,28 @@ module NgrokAPI
def to_s
end
##
# Delete this reserved domain.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete
def delete
@client.delete(id: @id)
end
##
# Update the attributes of this reserved domain.
#
# @param [string] description human-readable description of what this reserved domain will be used for
# @param [string] metadata arbitrary user-defined machine-readable data of this reserved domain. Optional, max 4096 bytes.
# @param [string] http_endpoint_configuration_id ID of an endpoint configuration of type http that will be used to handle inbound http traffic to this domain
# @param [string] https_endpoint_configuration_id ID of an endpoint configuration of type https that will be used to handle inbound https traffic to this domain
# @param [string] certificate_id ID of a user-uploaded TLS certificate to use for connections to targeting this domain. Optional, mutually exclusive with ``certificate_management_policy``.
# @param [string] certificate_management_policy configuration for automatic management of TLS certificates for this domain, or null if automatic management is disabled. Optional, mutually exclusive with ``certificate_id``.
# @return [NgrokAPI::Models::ReservedDomain] result from update request
#
# https://ngrok.com/docs/api#api-reserved-domains-update
def update(
certificate_id: nil,
certificate_management_policy: nil,
@@ -80,32 +100,70 @@ module NgrokAPI
)
end
def delete_certificate(id: nil)
##
# Detach the certificate attached from this reserved domain.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-certificate
def delete_certificate
@certificate = nil
@client.delete_certificate(id: @id)
end
def delete_certificate_management_policy(id: nil)
##
# Detach the certificate management policy attached from this reserved domain.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-certificate-management-policy
def delete_certificate_management_policy
@certificate_management_policy = nil
@certificate_management_status = nil
@client.delete_certificate_management_policy(id: @id)
end
def delete_http_endpoint_config(id: nil)
##
# Detach the http endpoint configuration attached from this reserved domain.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-http-endpoint-config
def delete_http_endpoint_config
@http_endpoint_configuration = nil
@client.delete_http_endpoint_config(id: @id)
end
def delete_https_endpoint_config(id: nil)
##
# Detach the https endpoint configuration attached from this reserved domain.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-https-endpoint-config
def delete_https_endpoint_config
@https_endpoint_configuration = nil
@client.delete_https_endpoint_config(id: @id)
end
##
# Restore the certificate attached to this reserved domain.
# Only works if the @result is still present from a previous action
#
# @return [NgrokAPI::Models::ReservedDomain] result from update request
#
# https://ngrok.com/docs/api#api-reserved-domains-update
def restore_certificate
@certificate = @result['certificate']
@client.update(id: @id, certificate_id: @result['certificate']['id'])
end
##
# Restore the certificate management policy attached to this reserved domain.
# Only works if the @result is still present from a previous action
#
# @return [NgrokAPI::Models::ReservedDomain] result from update request
#
# https://ngrok.com/docs/api#api-reserved-domains-update
def restore_certificate_management_policy
@certificate_management_policy = @result['certificate_management_policy']
@certificate_management_status = @result['certificate_management_status']
@@ -115,6 +173,13 @@ module NgrokAPI
)
end
##
# Restore the http endpoint configuration attached to this reserved domain.
# Only works if the @result is still present from a previous action
#
# @return [NgrokAPI::Models::ReservedDomain] result from update request
#
# https://ngrok.com/docs/api#api-reserved-domains-update
def restore_http_endpoint_config
@http_endpoint_configuration = @result['http_endpoint_configuration']
@client.update(
@@ -123,6 +188,13 @@ module NgrokAPI
)
end
##
# Restore the https endpoint configuration attached to this reserved domain.
# Only works if the @result is still present from a previous action
#
# @return [NgrokAPI::Models::ReservedDomain] result from update request
#
# https://ngrok.com/docs/api#api-reserved-domains-update
def restore_https_endpoint_config
@https_endpoint_configuration = @result['https_endpoint_configuration']
@client.update(
+16
View File
@@ -2,6 +2,8 @@
module NgrokAPI
module Models
##
# A resource representing data from the tls_certificate API
class TlsCertificate
attr_reader :id,
:client,
@@ -29,10 +31,24 @@ module NgrokAPI
def to_s
end
##
# Delete this TLS certificate.
#
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-tls-certificates-delete
def delete
@client.delete(id: @id)
end
##
# Update the attributes of this TLS Certificate.
#
# @param [string] description human-readable description of this TLS certificate. optional, max 255 bytes.
# @param [string] metadata arbitrary user-defined machine-readable data of this TLS certificate. optional, max 4096 bytes.
# @return [NgrokAPI::Models::TlsCertificate] result from update request
#
# https://ngrok.com/docs/api#api-tls-certificates-update
def update(description: nil, metadata: nil)
@description = description if description
@metadata = metadata if metadata
+7
View File
@@ -1,6 +1,8 @@
# frozen_string_literal: true
module NgrokAPI
##
# Low level class which allows the user to iterate through the results of a list API call
class PagedIterator
attr_accessor :page, :n
attr_reader :client, :list_property
@@ -16,6 +18,11 @@ module NgrokAPI
@page = page
end
##
# Iterate through the result set, returning the next instance if we already have one, or make
# a new API call to next_page_uri to get more results and return the next one from that call.
#
# @return [object] Returns an instance of a class.
def get_next
begin
item = @page.result[@list_property][@n]
+47 -8
View File
@@ -2,8 +2,14 @@
module NgrokAPI
module Services
##
# A client for interacting with the api_keys API
#
# https://ngrok.com/docs/api#api-api-keys
class ApiKeysClient
# The List Property from the resulting API for list calls
LIST_PROPERTY = 'keys'.freeze
# The API path for API keys
PATH = '/api_keys'.freeze
attr_reader :client
@@ -12,6 +18,14 @@ module NgrokAPI
@client = client
end
##
# Create a new API key. The generated API key can be used to authenticate to the ngrok API.
#
# @param [string] description human-readable description of what uses the API key to authenticate. optional, max 255 bytes.
# @param [string] metadata arbitrary user-defined data of this API key. optional, max 4096 bytes
# @return [NgrokAPI::Models::ApiKey] result from create request
#
# https://ngrok.com/docs/api#api-api-keys-create
def create(description: nil, metadata: nil)
data = {}
data[:description] = description if description
@@ -20,24 +34,40 @@ module NgrokAPI
NgrokAPI::Models::ApiKey.new(client: self, result: result)
end
##
# Delete an API key by ID.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-api-keys-delete
def delete(id: nil)
@client.delete("#{PATH}/#{id}")
end
##
# Get the details of an API key by ID.
#
# @param [string] id a resource identifier
# @return [NgrokAPI::Models::ApiKey] result from get request
#
# https://ngrok.com/docs/api#api-api-keys-get
def get(id: nil)
result = @client.get("#{PATH}/#{id}")
NgrokAPI::Models::ApiKey.new(client: self, result: result)
end
##
# List all API keys owned by this account.
#
# @param [string] before_id
# @param [integer] limit
# @param [string] url optional and mutually exclusive from before_id and limit
# @return [NgrokAPI::Models::Listable] the result listable
#
# https://ngrok.com/docs/api#api-api-keys-list
def list(before_id: nil, limit: nil, url: nil)
result = if url.nil?
data = {}
data[:before_id] = before_id if before_id
data[:limit] = limit if limit
@client.get(PATH, data: data)
else
@client.get(url)
end
result = @client.list(before_id: before_id, limit: limit, url: url, path: PATH)
NgrokAPI::Models::Listable.new(
client: self,
result: result,
@@ -46,6 +76,15 @@ module NgrokAPI
)
end
##
# Update attributes of an API key by ID.
#
# @param [string] id
# @param [string] description human-readable description of what uses the API key to authenticate. optional, max 255 bytes.
# @param [string] metadata arbitrary user-defined data of this API key. optional, max 4096 bytes
# @return [NgrokAPI::Models::ApiKey] result from update request
#
# https://ngrok.com/docs/api#api-api-keys-update
def update(id: nil, description: nil, metadata: nil)
data = {}
data[:description] = description if description
@@ -2,8 +2,14 @@
module NgrokAPI
module Services
##
# A client for interacting with the endpoint_configuration API
#
# https://ngrok.com/docs/api#api-endpoint-configurations
class EndpointConfigurationsClient
# The List Property from the resulting API for list calls
LIST_PROPERTY = 'endpoint_configurations'.freeze
# The API path for endpoint configurations
PATH = '/endpoint_configurations'.freeze
attr_reader :client
@@ -12,38 +18,99 @@ module NgrokAPI
@client = client
end
##
# Create a new endpoint configuration
#
# @param [string] description human-readable description of what this endpoint configuration will be do when applied or what traffic it will be applied to. Optional, max 255 bytes
# @param [string] metadata arbitrary user-defined machine-readable data of this endpoint configuration. Optional, max 4096 bytes.
# @param [string] type they type of traffic this endpoint configuration can be applied to. one of: ``http``, ``https``, ``tcp``
# @param [string] circuit_breaker circuit breaker module configuration
# @param [string] compression compression module configuration
# @param [string] request_headers request headers module configuration
# @param [string] response_headers response headers module configuration
# @param [string] ip_policy ip policy module configuration
# @param [string] mutual_tls mutual TLS module configuration
# @param [string] tls_termination TLS termination module configuration
# @param [string] webhook_validation webhook validation module configuration
# @param [string] oauth oauth module configuration
# @param [string] logging logging module configuration
# @param [string] saml saml module configuration
# @param [string] oidc oidc module configuration
# @return [NgrokAPI::Models::EndpointConfiguration] result from create request
#
# https://ngrok.com/docs/api#api-endpoint-configurations-create
def create(
description: '',
metadata: '',
type: ''
type: '',
circuit_breaker: nil,
compression: nil,
request_headers: nil,
response_headers: nil,
ip_policy: nil,
mutual_tls: nil,
tls_termination: nil,
webhook_validation: nil,
oauth: nil,
logging: nil,
saml: nil,
oidc: nil
)
data = {
type: type,
description: description,
metadata: metadata,
circuit_breaker: circuit_breaker,
compression: compression,
request_headers: request_headers,
response_headers: response_headers,
ip_policy: ip_policy,
mutual_tls: mutual_tls,
tls_termination: tls_termination,
webhook_validation: webhook_validation,
oauth: oauth,
logging: logging,
saml: saml,
oidc: oidc,
}
result = @client.post(PATH, data: data)
NgrokAPI::Models::EndpointConfiguration.new(client: self, result: result)
end
##
# Delete an endpoint configuration. This operation will fail if the endpoint configuration is still referenced by any reserved domain or reserved address.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-endpoint-configurations-delete
def delete(id: nil)
@client.delete("#{PATH}/#{id}")
end
##
# Returns detailed information about an endpoint configuration by ID.
#
# @param [string] id a resource identifier
# @return [NgrokAPI::Models::EndpointConfiguration] result from get request
#
# https://ngrok.com/docs/api#api-endpoint-configurations-get
def get(id: nil)
result = @client.get("#{PATH}/#{id}")
NgrokAPI::Models::EndpointConfiguration.new(client: self, result: result)
end
##
# Returns a list of all endpoint configurations on this account.
#
# @param [string] before_id
# @param [integer] limit
# @param [string] url optional and mutually exclusive from before_id and limit
# @return [NgrokAPI::Models::Listable] the result listable
#
# https://ngrok.com/docs/api#api-endpoint-configurations-list
def list(before_id: nil, limit: nil, url: nil)
result = if url.nil?
data = {}
data[:before_id] = before_id if before_id
data[:limit] = limit if limit
@client.get(PATH, data: data)
else
@client.get(url)
end
result = @client.list(before_id: before_id, limit: limit, url: url, path: PATH)
NgrokAPI::Models::Listable.new(
client: self,
result: result,
@@ -52,28 +119,61 @@ module NgrokAPI
)
end
##
# Updates an endpoint configuration. If a module is not specified in the update, it will not be modified.
# However, each module configuration that is specified will completely replace the existing value.
# There is no way to delete an existing module via this API, instead use the delete module API.
#
# @param [string] id unique identifier of this endpoint configuration
# @param [string] description human-readable description of what this endpoint configuration will be do when applied or what traffic it will be applied to. Optional, max 255 bytes
# @param [string] metadata arbitrary user-defined machine-readable data of this endpoint configuration. Optional, max 4096 bytes.
# @param [string] circuit_breaker circuit breaker module configuration
# @param [string] compression compression module configuration
# @param [string] request_headers request headers module configuration
# @param [string] response_headers response headers module configuration
# @param [string] ip_policy ip policy module configuration
# @param [string] mutual_tls mutual TLS module configuration
# @param [string] tls_termination TLS termination module configuration
# @param [string] webhook_validation webhook validation module configuration
# @param [string] oauth oauth module configuration
# @param [string] logging logging module configuration
# @param [string] saml saml module configuration
# @param [string] oidc oidc module configuration
# @return [NgrokAPI::Models::EndpointConfiguration] result from update request
#
# https://ngrok.com/docs/api#api-endpoint-configurations-update
def update(
id: nil,
certificate_id: nil,
certificate_management_policy: nil,
description: nil,
http_endpoint_configuration_id: nil,
https_endpoint_configuration_id: nil,
metadata: nil
metadata: nil,
circuit_breaker: nil,
compression: nil,
request_headers: nil,
response_headers: nil,
ip_policy: nil,
mutual_tls: nil,
tls_termination: nil,
webhook_validation: nil,
oauth: nil,
logging: nil,
saml: nil,
oidc: nil
)
data = {}
data[:certificate_id] = certificate_id if certificate_id
if certificate_management_policy
data[:certificate_management_policy] = certificate_management_policy
end
data[:description] = description if description
if http_endpoint_configuration_id
data[:http_endpoint_configuration_id] = http_endpoint_configuration_id
end
if https_endpoint_configuration_id
data[:https_endpoint_configuration_id] = https_endpoint_configuration_id
end
data[:metadata] = metadata if metadata
data[:circuit_breaker] = circuit_breaker if circuit_breaker
data[:compression] = compression if compression
data[:request_headers] = request_headers if request_headers
data[:response_headers] = response_headers if response_headers
data[:ip_policy] = ip_policy if ip_policy
data[:mutual_tls] = mutual_tls if mutual_tls
data[:tls_termination] = tls_termination if tls_termination
data[:webhook_validation] = webhook_validation if webhook_validation
data[:oauth] = oauth if oauth
data[:logging] = logging if logging
data[:saml] = saml if saml
data[:oidc] = oidc if oidc
result = @client.patch("#{PATH}/#{id}", data: data)
NgrokAPI::Models::EndpointConfiguration.new(client: self, result: result)
end
@@ -2,8 +2,14 @@
module NgrokAPI
module Services
##
# A client for interacting with the reserved_domains API
#
# https://ngrok.com/docs/api#api-reserved-domains
class ReservedDomainsClient
# The List Property from the resulting API for list calls
LIST_PROPERTY = 'reserved_domains'.freeze
# The API path for reserved domains
PATH = '/reserved_domains'.freeze
attr_reader :client
@@ -12,6 +18,20 @@ module NgrokAPI
@client = client
end
##
# Create a new reserved domain.
#
# @param [string] name the domain name to reserve. It may be a full domain name like app.example.com. If the name does not contain a '.' it will reserve that subdomain on ngrok.io.
# @param [string] region reserve the domain in this geographic ngrok datacenter. Optional, default is us. (au, eu, ap, us, jp, in, sa)
# @param [string] description human-readable description of what this reserved domain will be used for
# @param [string] metadata arbitrary user-defined machine-readable data of this reserved domain. Optional, max 4096 bytes.
# @param [string] http_endpoint_configuration_id ID of an endpoint configuration of type http that will be used to handle inbound http traffic to this domain
# @param [string] https_endpoint_configuration_id ID of an endpoint configuration of type https that will be used to handle inbound https traffic to this domain
# @param [string] certificate_id ID of a user-uploaded TLS certificate to use for connections to targeting this domain. Optional, mutually exclusive with ``certificate_management_policy``.
# @param [string] certificate_management_policy configuration for automatic management of TLS certificates for this domain, or null if automatic management is disabled. Optional, mutually exclusive with ``certificate_id``.
# @return [NgrokAPI::Models::ReservedDomain] result from create request
#
# https://ngrok.com/docs/api#api-reserved-domains-create
def create(
name: '',
region: '',
@@ -36,24 +56,40 @@ module NgrokAPI
NgrokAPI::Models::ReservedDomain.new(client: self, result: result)
end
##
# Delete a reserved domain.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete
def delete(id: nil)
@client.delete("#{PATH}/#{id}")
end
##
# Get the details of a reserved domain.
#
# @param [string] id a resource identifier
# @return [NgrokAPI::Models::ReservedDomain] result from get request
#
# https://ngrok.com/docs/api#api-reserved-domains-get
def get(id: nil)
result = @client.get("#{PATH}/#{id}")
NgrokAPI::Models::ReservedDomain.new(client: self, result: result)
end
##
# List all reserved domains on this account.
#
# @param [string] before_id
# @param [integer] limit
# @param [string] url optional and mutually exclusive from before_id and limit
# @return [NgrokAPI::Models::Listable] result from list request
#
# https://ngrok.com/docs/api#api-reserved-domains-list
def list(before_id: nil, limit: nil, url: nil)
result = if url.nil?
data = {}
data[:before_id] = before_id if before_id
data[:limit] = limit if limit
@client.get(PATH, data: data)
else
@client.get(url)
end
result = @client.list(before_id: before_id, limit: limit, url: url, path: PATH)
NgrokAPI::Models::Listable.new(
client: self,
result: result,
@@ -62,6 +98,19 @@ module NgrokAPI
)
end
##
# Update the attributes of a reserved domain.
#
# @param [string] id
# @param [string] description human-readable description of what this reserved domain will be used for
# @param [string] metadata arbitrary user-defined machine-readable data of this reserved domain. Optional, max 4096 bytes.
# @param [string] http_endpoint_configuration_id ID of an endpoint configuration of type http that will be used to handle inbound http traffic to this domain
# @param [string] https_endpoint_configuration_id ID of an endpoint configuration of type https that will be used to handle inbound https traffic to this domain
# @param [string] certificate_id ID of a user-uploaded TLS certificate to use for connections to targeting this domain. Optional, mutually exclusive with ``certificate_management_policy``.
# @param [string] certificate_management_policy configuration for automatic management of TLS certificates for this domain, or null if automatic management is disabled. Optional, mutually exclusive with ``certificate_id``.
# @return [NgrokAPI::Models::ReservedDomain] result from update request
#
# https://ngrok.com/docs/api#api-reserved-domains-update
def update(
id: nil,
certificate_id: nil,
@@ -88,18 +137,46 @@ module NgrokAPI
NgrokAPI::Models::ReservedDomain.new(client: self, result: result)
end
def delete_certificate_management_policy(id: nil)
@client.delete("#{PATH}/#{id}/certificate_management_policy")
end
##
# Detach the certificate attached from a reserved domain.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-certificate
def delete_certificate(id: nil)
@client.delete("#{PATH}/#{id}/certificate")
end
##
# Detach the certificate management policy attached from a reserved domain.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-certificate-management-policy
def delete_certificate_management_policy(id: nil)
@client.delete("#{PATH}/#{id}/certificate_management_policy")
end
##
# Detach the http endpoint configuration attached from a reserved domain.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-http-endpoint-config
def delete_http_endpoint_config(id: nil)
@client.delete("#{PATH}/#{id}/http_endpoint_configuration")
end
##
# Detach the https endpoint configuration attached from a reserved domain.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-reserved-domains-delete-https-endpoint-config
def delete_https_endpoint_config(id: nil)
@client.delete("#{PATH}/#{id}/https_endpoint_configuration")
end
@@ -2,8 +2,14 @@
module NgrokAPI
module Services
##
# A client for interacting with the tls_certificates API
#
# https://ngrok.com/docs/api#api-tls-certificates
class TlsCertificatesClient
# The List Property from the resulting API for list calls
LIST_PROPERTY = 'tls_certificates'.freeze
# The API path for tls certificates
PATH = '/tls_certificates'.freeze
attr_reader :client
@@ -12,6 +18,16 @@ module NgrokAPI
@client = client
end
##
# Upload a new TLS certificate.
#
# @param [string] description human-readable description of this TLS certificate. optional, max 255 bytes.
# @param [string] metadata arbitrary user-defined machine-readable data of this TLS certificate. optional, max 4096 bytes.
# @param [string] certificate_pem chain of PEM-encoded certificates, leaf first. See `Certificate Bundles` <https://ngrok.com/docs/api#tls-certificates-pem>`_.
# @param [string] private_key_pem private key for the TLS certificate, PEM-encoded. See `Private Keys` <https://ngrok.com/docs/ngrok-link#tls-certificates-key>`_.
# @return [NgrokAPI::Models::TlsCertificate] result from create request
#
# https://ngrok.com/docs/api#api-tls-certificates-create
def create(
certificate_pem: '',
description: '',
@@ -28,24 +44,40 @@ module NgrokAPI
NgrokAPI::Models::TlsCertificate.new(client: self, result: result)
end
##
# Delete a TLS certificate by ID.
#
# @param [string] id a resource identifier
# @return [nil] result from delete request
#
# https://ngrok.com/docs/api#api-tls-certificates-delete
def delete(id: nil)
@client.delete("#{PATH}/#{id}")
end
##
# Get detailed information about a TLS certificate by ID.
#
# @param [string] id a resource identifier
# @return [NgrokAPI::Models::TlsCertificate] result from get request
#
# https://ngrok.com/docs/api#api-tls-certificates-get
def get(id: nil)
result = @client.get("#{PATH}/#{id}")
NgrokAPI::Models::TlsCertificate.new(client: self, result: result)
end
##
# List all TLS certificates on this account.
#
# @param [string] before_id
# @param [integer] limit
# @param [string] url optional and mutually exclusive from before_id and limit
# @return [NgrokAPI::Models::Listable] the result listable
#
# https://ngrok.com/docs/api#api-tls-certificates-list
def list(before_id: nil, limit: nil, url: nil)
result = if url.nil?
data = {}
data[:before_id] = before_id if before_id
data[:limit] = limit if limit
@client.get(PATH, data: data)
else
@client.get(url)
end
result = @client.list(before_id: before_id, limit: limit, url: url, path: PATH)
NgrokAPI::Models::Listable.new(
client: self,
result: result,
@@ -54,6 +86,15 @@ module NgrokAPI
)
end
##
# Update attributes of a TLS Certificate by ID.
#
# @param [string] id
# @param [string] description human-readable description of this TLS certificate. optional, max 255 bytes.
# @param [string] metadata arbitrary user-defined machine-readable data of this TLS certificate. optional, max 4096 bytes.
# @return [NgrokAPI::Models::TlsCertificate] result from update request
#
# https://ngrok.com/docs/api#api-tls-certificates-update
def update(
id: nil,
description: nil,
+1
View File
@@ -1,3 +1,4 @@
module NgrokAPI
# The current version of the gem
VERSION = '0.0.1.pre'.freeze
end
@@ -1,6 +1,6 @@
require 'spec_helper'
RSpec.describe NgrokAPI::Models::ApiKeyList do
RSpec.describe NgrokAPI::Models::Listable do
before(:each) do
client = class_double("ApiKeysClient")
@result = {
@@ -33,7 +33,12 @@ RSpec.describe NgrokAPI::Models::ApiKeyList do
"uri" => "https://api.ngrok.com/api_keys",
"next_page_uri" => nil
}
@api_keys = NgrokAPI::Models::ApiKeyList.new(client: client, result: @result)
@listable = NgrokAPI::Models::Listable.new(
client: client,
result: @result,
list_property: 'keys',
klass: NgrokAPI::Models::ApiKey
)
end
describe "#==" do
@@ -50,14 +55,13 @@ RSpec.describe NgrokAPI::Models::ApiKeyList do
describe "keys" do
it "should consistent of ApiKeys" do
expect(@api_keys.keys.size).to eq @result['keys'].size
expect(true).to eq true
expect(@listable.items.size).to eq @result['keys'].size
end
end
describe "iter" do
it "should be a PagedIterator" do
expect(@api_keys.iter.class).to eq NgrokAPI::PagedIterator
expect(@listable.iter.class).to eq NgrokAPI::PagedIterator
end
end
end
+1 -1
View File
@@ -3,7 +3,7 @@ require 'spec_helper'
RSpec.describe NgrokAPI::PagedIterator do
before(:each) do
client = class_double("ApiKeysClient")
page = class_double("ApiKeyList")
result = class_double("Listable")
@paged_iterator = NgrokAPI::PagedIterator.new(client: client, result: result)
end