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

Returns the value of attribute fields.



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

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.



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

def paginated_field
  @paginated_field
end

#response_typeObject

Returns the value of attribute response_type.



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

def response_type
  @response_type
end

#scopesObject (readonly)

Returns the value of attribute scopes.



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

def scopes
  @scopes
end

Instance Method Details

#argument_setObject



29
30
31
32
33
34
35
# File 'lib/apia/definitions/endpoint.rb', line 29

def argument_set
  @argument_set ||= begin
    as = Apia::ArgumentSet.create("#{@id}/BaseArgumentSet")
    as.definition.schema = schema?
    as
  end
end

#dslObject



54
55
56
# File 'lib/apia/definitions/endpoint.rb', line 54

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

#fields_overriden?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/apia/definitions/endpoint.rb', line 50

def fields_overriden?
  @fields_overriden == true
end

#http_status_codeObject



58
59
60
61
62
63
64
# File 'lib/apia/definitions/endpoint.rb', line 58

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



37
38
39
# File 'lib/apia/definitions/endpoint.rb', line 37

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

#setupObject



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

def setup
  @fields = FieldSet.new
  @http_status = 200
  @response_type = Apia::Response::JSON
  @scopes = []
end

#validate(errors) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/apia/definitions/endpoint.rb', line 66

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