Class: Apia::Definitions::Endpoint

Inherits:
Apia::Definition show all
Defined in:
lib/apia/definitions/endpoint.rb

Instance Attribute Summary collapse

Attributes inherited from Apia::Definition

#description, #id, #name, #schema

Instance Method Summary collapse

Methods inherited from Apia::Definition

#initialize, #schema?

Constructor Details

This class inherits a constructor from Apia::Definition

Instance Attribute Details

#actionObject

Returns the value of attribute action.



15
16
17
# File 'lib/apia/definitions/endpoint.rb', line 15

def action
  @action
end

#authenticatorObject

Returns the value of attribute authenticator.



14
15
16
# File 'lib/apia/definitions/endpoint.rb', line 14

def authenticator
  @authenticator
end

#fieldsObject (readonly)

Returns the value of attribute fields.



18
19
20
# File 'lib/apia/definitions/endpoint.rb', line 18

def fields
  @fields
end

#http_statusObject

Returns the value of attribute http_status.



16
17
18
# File 'lib/apia/definitions/endpoint.rb', line 16

def http_status
  @http_status
end

#paginated_fieldObject

Returns the value of attribute paginated_field.



17
18
19
# File 'lib/apia/definitions/endpoint.rb', line 17

def paginated_field
  @paginated_field
end

#scopesObject (readonly)

Returns the value of attribute scopes.



19
20
21
# File 'lib/apia/definitions/endpoint.rb', line 19

def scopes
  @scopes
end

Instance Method Details

#argument_setObject



27
28
29
30
31
32
33
# 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

#dslObject



39
40
41
# File 'lib/apia/definitions/endpoint.rb', line 39

def dsl
  @dsl ||= DSLs::Endpoint.new(self)
end

#http_status_codeObject



43
44
45
46
47
48
49
# 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_errorsObject



35
36
37
# File 'lib/apia/definitions/endpoint.rb', line 35

def potential_errors
  @potential_errors ||= Apia::ErrorSet.new
end

#setupObject



21
22
23
24
25
# File 'lib/apia/definitions/endpoint.rb', line 21

def setup
  @fields = FieldSet.new
  @http_status = 200
  @scopes = []
end

#validate(errors) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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