class Apia::Definitions::Endpoint

Attributes

action[RW]
authenticator[RW]
fields[R]
http_status[RW]
paginated_field[RW]
scopes[R]

Public Instance Methods

argument_set() click to toggle source
# File lib/apia/definitions/endpoint.rb, line 27
def argument_set
  @argument_set ||= begin
    as = Apia::ArgumentSet.create("#{@id}/BaseArgumentSet")
    as.definition.schema = schema?
    as
  end
end
dsl() click to toggle source
# File lib/apia/definitions/endpoint.rb, line 39
def dsl
  @dsl ||= DSLs::Endpoint.new(self)
end
http_status_code() click to toggle source
# File lib/apia/definitions/endpoint.rb, line 43
def http_status_code
  if @http_status.is_a?(Symbol)
    ::Rack::Utils::SYMBOL_TO_STATUS_CODE[@http_status]
  else
    @http_status
  end
end
potential_errors() click to toggle source
# File lib/apia/definitions/endpoint.rb, line 35
def potential_errors
  @potential_errors ||= Apia::ErrorSet.new
end
setup() click to toggle source
# File lib/apia/definitions/endpoint.rb, line 21
def setup
  @fields = FieldSet.new
  @http_status = 200
  @scopes = []
end
validate(errors) click to toggle source
# File lib/apia/definitions/endpoint.rb, line 51
def validate(errors)
  if @action && !@action.is_a?(Proc)
    errors.add self, 'InvalidAction', 'The action provided must be a Proc'
  end

  if http_status_code.is_a?(Integer) && ::Rack::Utils::HTTP_STATUS_CODES[http_status_code]
    # OK
  elsif http_status_code.is_a?(Integer)
    errors.add self, 'InvalidHTTPStatus', "The HTTP status is not valid (must be one of #{::Rack::Utils::HTTP_STATUS_CODES.keys.join(', ')})"
  else
    errors.add self, 'InvalidHTTPStatus', 'The HTTP status is not valid (must be an integer)'
  end

  if @authenticator && !(@authenticator.respond_to?(:ancestors) && @authenticator.ancestors.include?(Apia::Authenticator))
    errors.add self, 'InvalidAuthenticator', 'The authenticator must be a class that inherits from Apia::Authenticator'
  end

  @fields.validate(errors, self)
  @potential_errors&.validate(errors, self)
end