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
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.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
-
#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
- #fields_overriden? ⇒ Boolean
- #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
Returns the value of attribute fields.
19 20 21 |
# File 'lib/apia/definitions/endpoint.rb', line 19 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.
18 19 20 |
# File 'lib/apia/definitions/endpoint.rb', line 18 def paginated_field @paginated_field end |
#response_type ⇒ Object
Returns the value of attribute response_type.
17 18 19 |
# File 'lib/apia/definitions/endpoint.rb', line 17 def response_type @response_type end |
#scopes ⇒ Object (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_set ⇒ Object
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 |
#dsl ⇒ Object
54 55 56 |
# File 'lib/apia/definitions/endpoint.rb', line 54 def dsl @dsl ||= DSLs::Endpoint.new(self) end |
#fields_overriden? ⇒ Boolean
50 51 52 |
# File 'lib/apia/definitions/endpoint.rb', line 50 def fields_overriden? @fields_overriden == true end |
#http_status_code ⇒ Object
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_errors ⇒ Object
37 38 39 |
# File 'lib/apia/definitions/endpoint.rb', line 37 def potential_errors @potential_errors ||= Apia::ErrorSet.new end |
#setup ⇒ Object
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 |