Class: Apia::Definitions::Endpoint
- Inherits:
-
Apia::Definition
- Object
- Apia::Definition
- Apia::Definitions::Endpoint
- Defined in:
- lib/apia/definitions/endpoint.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#authenticator ⇒ Object
Returns the value of attribute authenticator.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#http_status ⇒ Object
Returns the value of attribute http_status.
-
#paginated_field ⇒ Object
Returns the value of attribute paginated_field.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
Attributes inherited from Apia::Definition
#description, #id, #name, #schema
Instance Method Summary collapse
- #argument_set ⇒ Object
- #dsl ⇒ Object
- #http_status_code ⇒ Object
- #potential_errors ⇒ Object
- #setup ⇒ Object
- #validate(errors) ⇒ Object
Methods inherited from Apia::Definition
Constructor Details
This class inherits a constructor from Apia::Definition
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
15 16 17 |
# File 'lib/apia/definitions/endpoint.rb', line 15 def action @action end |
#authenticator ⇒ Object
Returns the value of attribute authenticator.
14 15 16 |
# File 'lib/apia/definitions/endpoint.rb', line 14 def authenticator @authenticator end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
18 19 20 |
# File 'lib/apia/definitions/endpoint.rb', line 18 def fields @fields end |
#http_status ⇒ Object
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_field ⇒ Object
Returns the value of attribute paginated_field.
17 18 19 |
# File 'lib/apia/definitions/endpoint.rb', line 17 def paginated_field @paginated_field end |
#scopes ⇒ Object (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_set ⇒ Object
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 |
#dsl ⇒ Object
39 40 41 |
# File 'lib/apia/definitions/endpoint.rb', line 39 def dsl @dsl ||= DSLs::Endpoint.new(self) end |
#http_status_code ⇒ Object
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_errors ⇒ Object
35 36 37 |
# File 'lib/apia/definitions/endpoint.rb', line 35 def potential_errors @potential_errors ||= Apia::ErrorSet.new end |
#setup ⇒ Object
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 |