class AlexaRuby::URI

URI request validator

Attributes

uri[R]

Public Class Methods

new(uri) click to toggle source

Setup new URI

@param uri [String] URI

# File lib/alexa_ruby/request/base_request/validator/uri.rb, line 9
def initialize(uri)
  @uri = Addressable::URI.parse(uri).normalize!
end

Public Instance Methods

valid?() click to toggle source

Check if it is a valid Amazon URI

@return [Boolean]

# File lib/alexa_ruby/request/base_request/validator/uri.rb, line 16
def valid?
  https? && amazon? && echo_api? && port?
end

Private Instance Methods

amazon?() click to toggle source

Check if URI host is a valid Amazon host

@return [Boolean]

# File lib/alexa_ruby/request/base_request/validator/uri.rb, line 37
def amazon?
  @uri.host.casecmp('s3.amazonaws.com').zero? ||
    raise(
      ArgumentError,
      'Certificates chain host must be equal to "s3.amazonaws.com" ' \
      "(current host: #{@uri.host})"
    )
end
echo_api?() click to toggle source

Check if URI path starts with /echo.api/

@return [Boolean]

# File lib/alexa_ruby/request/base_request/validator/uri.rb, line 49
def echo_api?
  @uri.path[0..9] == '/echo.api/' ||
    raise(
      ArgumentError,
      'Certificates chain URL path must start with "/echo.api/" ' \
      "(current path: #{@uri.path})"
    )
end
https?() click to toggle source

Check if URI scheme is HTTPS

@return [Boolean]

# File lib/alexa_ruby/request/base_request/validator/uri.rb, line 25
def https?
  @uri.scheme == 'https' ||
    raise(
      ArgumentError,
      'Certificates chain URL must be an HTTPS-enabled endpoint ' \
      "(current endpoint: #{@uri})"
    )
end
port?() click to toggle source

Check if URI port is 443 if port is present

@return [Boolean]

# File lib/alexa_ruby/request/base_request/validator/uri.rb, line 61
def port?
  @uri.port.nil? || @uri.port == 443 ||
    raise(
      ArgumentError,
      'If certificates chain URL has a port specified, it must be 443 ' \
      "(current port: #{@uri.port})"
    )
end