diff --git a/.rubocop.yml b/.rubocop.yml index 2d310fd..0269e29 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,63 +1,12 @@ -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/StringLiterals: +inherit_from: + - .rubocop_airbnb.yml + - .rubocop_todo.yml + +Airbnb/ClassOrModuleDeclaredInWrongFile: Enabled: false -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -Layout/SpaceInsideHashLiteralBraces: +Airbnb/ConstAssignedInWrongFile: Enabled: false -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -Layout/SpaceInsideBlockBraces: - Enabled: false - -# Cop supports --auto-correct. -Layout/SpaceBeforeSemicolon: - Enabled: false - -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SignalException: - Enabled: false - -# Configuration parameters: Methods. -Style/SingleLineBlockParams: - Enabled: false - -# Cop supports --auto-correct. -Style/PerlBackrefs: - Enabled: false - -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Enabled: false - -Style/Documentation: - Enabled: false - -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. -Style/RegexpLiteral: - Enabled: false - -# Cop supports --auto-correct. -Style/NumericLiterals: - MinDigits: 6 - -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Enabled: false - -# Cop supports --auto-correct. -Lint/UnusedBlockArgument: - Enabled: false - -Lint/Void: - Enabled: false - -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Enabled: false +Layout/AlignArguments: + EnforcedStyle: with_fixed_indentation diff --git a/.rubocop_airbnb.yml b/.rubocop_airbnb.yml new file mode 100644 index 0000000..8dd3420 --- /dev/null +++ b/.rubocop_airbnb.yml @@ -0,0 +1,2 @@ +require: + - rubocop-airbnb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..e69de29 diff --git a/Gemfile b/Gemfile index 1ad879f..f246831 100644 --- a/Gemfile +++ b/Gemfile @@ -26,4 +26,6 @@ group :development, :test do gem 'pry' # https://github.com/lsegal/yard gem 'yard' + # https://github.com/airbnb/ruby/tree/master/rubocop-airbnb + gem 'rubocop-airbnb' end diff --git a/README.md b/README.md index 1ea1912..f8c1d23 100644 --- a/README.md +++ b/README.md @@ -1 +1,23 @@ -TODO +# Documentation + +Documentation can be generated with the command: + +```sh +yard doc 'lib/**/*.rb' +``` + +# Specs + +Specs can be run with the command: + +```sh +bundle exec rake +``` + +# Rubocop + +Rubocop can be run with the command: + +```sh +rubocop 'lib' +``` diff --git a/lib/ngrokapi/client.rb b/lib/ngrokapi/client.rb index 10cbd84..f5abc28 100644 --- a/lib/ngrokapi/client.rb +++ b/lib/ngrokapi/client.rb @@ -117,6 +117,7 @@ module NgrokAPI end private + def headers { 'Authorization': "Bearer #{@api_key}", @@ -140,8 +141,8 @@ module NgrokAPI end def get_uri(path, data: nil) - data = data != nil ? "?#{URI.encode_www_form(data)}" : "" - uri = URI("#{url(path)}#{data}") + data = !data.nil? ? "?#{URI.encode_www_form(data)}" : "" + URI("#{url(path)}#{data}") end def url(path) diff --git a/lib/ngrokapi/models/api_key.rb b/lib/ngrokapi/models/api_key.rb index 68d9aa9..e3720c2 100644 --- a/lib/ngrokapi/models/api_key.rb +++ b/lib/ngrokapi/models/api_key.rb @@ -46,9 +46,11 @@ module NgrokAPI ## # Update the attributes of this API key. # + # rubocop:disable LineLength # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-api-keys-update def update(description: nil, metadata: nil) diff --git a/lib/ngrokapi/models/endpoint_configuration.rb b/lib/ngrokapi/models/endpoint_configuration.rb index 9ac23ba..92c2ee9 100644 --- a/lib/ngrokapi/models/endpoint_configuration.rb +++ b/lib/ngrokapi/models/endpoint_configuration.rb @@ -42,6 +42,7 @@ module NgrokAPI end ## + # rubocop:disable LineLength # 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. @@ -60,7 +61,8 @@ module NgrokAPI # @param [string] logging logging module configuration # @param [string] saml saml module configuration # @param [string] oidc oidc module configuration - # @return + # @return [NgrokAPI::Models::EndpointConfiguration] result from update request + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-endpoint-configurations-update def update( diff --git a/lib/ngrokapi/models/listable.rb b/lib/ngrokapi/models/listable.rb index 580233e..2581f39 100644 --- a/lib/ngrokapi/models/listable.rb +++ b/lib/ngrokapi/models/listable.rb @@ -20,8 +20,8 @@ module NgrokAPI @list_property = list_property @next_page_uri = @result['next_page_uri'] @uri = @result['uri'] - @items = @result[list_property].map do |result| - klass.new(client: client, result: result) + @items = @result[list_property].map do |item| + klass.new(client: client, result: item) end @iter = NgrokAPI::PagedIterator.new( client: client, diff --git a/lib/ngrokapi/models/reserved_domain.rb b/lib/ngrokapi/models/reserved_domain.rb index efa8c3f..1a220a3 100644 --- a/lib/ngrokapi/models/reserved_domain.rb +++ b/lib/ngrokapi/models/reserved_domain.rb @@ -60,6 +60,7 @@ module NgrokAPI ## # Update the attributes of this reserved domain. # + # rubocop:disable LineLength # @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 @@ -67,6 +68,7 @@ module NgrokAPI # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-reserved-domains-update def update( diff --git a/lib/ngrokapi/models/tls_certificate.rb b/lib/ngrokapi/models/tls_certificate.rb index 8f8cdf6..16b52bd 100644 --- a/lib/ngrokapi/models/tls_certificate.rb +++ b/lib/ngrokapi/models/tls_certificate.rb @@ -44,9 +44,11 @@ module NgrokAPI ## # Update the attributes of this TLS Certificate. # + # rubocop:disable LineLength # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-tls-certificates-update def update(description: nil, metadata: nil) diff --git a/lib/ngrokapi/paged_iterator.rb b/lib/ngrokapi/paged_iterator.rb index e2e63bf..ec9a564 100644 --- a/lib/ngrokapi/paged_iterator.rb +++ b/lib/ngrokapi/paged_iterator.rb @@ -24,20 +24,18 @@ module NgrokAPI # # @return [object] Returns an instance of a class. def get_next - begin - item = @page.result[@list_property][@n] - raise "None" if item.nil? - self.n += 1 - item - rescue => exception - if self.page.next_page_uri.nil? - # Handle / raise exception - else - res = @client.list(url: @page.next_page_uri) - self.n = 0 - self.page = res - get_next - end + item = @page.result[@list_property][@n] + raise "None" if item.nil? + self.n += 1 + item + rescue + if @page.next_page_uri.nil? + # Handle / raise exception + else + res = @client.list(url: @page.next_page_uri) + self.n = 0 + self.page = res + get_next end end end diff --git a/lib/ngrokapi/services/api_keys_client.rb b/lib/ngrokapi/services/api_keys_client.rb index 141c31f..2384780 100644 --- a/lib/ngrokapi/services/api_keys_client.rb +++ b/lib/ngrokapi/services/api_keys_client.rb @@ -8,9 +8,9 @@ module NgrokAPI # https://ngrok.com/docs/api#api-api-keys class ApiKeysClient # The List Property from the resulting API for list calls - LIST_PROPERTY = 'keys'.freeze + LIST_PROPERTY = 'keys' # The API path for API keys - PATH = '/api_keys'.freeze + PATH = '/api_keys' attr_reader :client @@ -21,9 +21,11 @@ module NgrokAPI ## # Create a new API key. The generated API key can be used to authenticate to the ngrok API. # + # rubocop:disable LineLength # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-api-keys-create def create(description: nil, metadata: nil) @@ -79,10 +81,12 @@ module NgrokAPI ## # Update attributes of an API key by ID. # + # rubocop:disable LineLength # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-api-keys-update def update(id: nil, description: nil, metadata: nil) diff --git a/lib/ngrokapi/services/endpoint_configurations_client.rb b/lib/ngrokapi/services/endpoint_configurations_client.rb index ac4d646..8771042 100644 --- a/lib/ngrokapi/services/endpoint_configurations_client.rb +++ b/lib/ngrokapi/services/endpoint_configurations_client.rb @@ -8,9 +8,9 @@ module NgrokAPI # 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 + LIST_PROPERTY = 'endpoint_configurations' # The API path for endpoint configurations - PATH = '/endpoint_configurations'.freeze + PATH = '/endpoint_configurations' attr_reader :client @@ -21,6 +21,7 @@ module NgrokAPI ## # Create a new endpoint configuration # + # rubocop:disable LineLength # @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`` @@ -37,6 +38,7 @@ module NgrokAPI # @param [string] saml saml module configuration # @param [string] oidc oidc module configuration # @return [NgrokAPI::Models::EndpointConfiguration] result from create request + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-endpoint-configurations-create def create( @@ -78,7 +80,9 @@ module NgrokAPI end ## - # Delete an endpoint configuration. This operation will fail if the endpoint configuration is still referenced by any reserved domain or reserved address. + # 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 @@ -120,6 +124,7 @@ module NgrokAPI end ## + # rubocop:disable LineLength # 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. @@ -140,6 +145,7 @@ module NgrokAPI # @param [string] saml saml module configuration # @param [string] oidc oidc module configuration # @return [NgrokAPI::Models::EndpointConfiguration] result from update request + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-endpoint-configurations-update def update( diff --git a/lib/ngrokapi/services/reserved_domains_client.rb b/lib/ngrokapi/services/reserved_domains_client.rb index 072dd88..c961f1a 100644 --- a/lib/ngrokapi/services/reserved_domains_client.rb +++ b/lib/ngrokapi/services/reserved_domains_client.rb @@ -8,9 +8,9 @@ module NgrokAPI # 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 + LIST_PROPERTY = 'reserved_domains' # The API path for reserved domains - PATH = '/reserved_domains'.freeze + PATH = '/reserved_domains' attr_reader :client @@ -21,6 +21,7 @@ module NgrokAPI ## # Create a new reserved domain. # + # rubocop:disable LineLength # @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 @@ -30,6 +31,7 @@ module NgrokAPI # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-reserved-domains-create def create( @@ -101,6 +103,7 @@ module NgrokAPI ## # Update the attributes of a reserved domain. # + # rubocop:disable LineLength # @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. @@ -109,6 +112,7 @@ module NgrokAPI # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-reserved-domains-update def update( diff --git a/lib/ngrokapi/services/tls_certificates_client.rb b/lib/ngrokapi/services/tls_certificates_client.rb index 3eaaa98..80443ad 100644 --- a/lib/ngrokapi/services/tls_certificates_client.rb +++ b/lib/ngrokapi/services/tls_certificates_client.rb @@ -8,9 +8,9 @@ module NgrokAPI # 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 + LIST_PROPERTY = 'tls_certificates' # The API path for tls certificates - PATH = '/tls_certificates'.freeze + PATH = '/tls_certificates' attr_reader :client @@ -21,11 +21,13 @@ module NgrokAPI ## # Upload a new TLS certificate. # + # rubocop:disable LineLength # @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` `_. # @param [string] private_key_pem private key for the TLS certificate, PEM-encoded. See `Private Keys` `_. # @return [NgrokAPI::Models::TlsCertificate] result from create request + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-tls-certificates-create def create( @@ -89,10 +91,12 @@ module NgrokAPI ## # Update attributes of a TLS Certificate by ID. # + # rubocop:disable LineLength # @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 + # rubocop:enable LineLength # # https://ngrok.com/docs/api#api-tls-certificates-update def update( diff --git a/spec/ngrokapi/models/listable_spec.rb b/spec/ngrokapi/models/listable_spec.rb index b5abe83..a40d551 100644 --- a/spec/ngrokapi/models/listable_spec.rb +++ b/spec/ngrokapi/models/listable_spec.rb @@ -54,13 +54,13 @@ RSpec.describe NgrokAPI::Models::Listable do end describe "keys" do - it "should consistent of ApiKeys" do + it "consistent of ApiKeys" do expect(@listable.items.size).to eq @result['keys'].size end end describe "iter" do - it "should be a PagedIterator" do + it "is a PagedIterator" do expect(@listable.iter.class).to eq NgrokAPI::PagedIterator end end