Class: LanguageOperator::Dsl::WebhookDefinition
- Inherits:
-
Object
- Object
- LanguageOperator::Dsl::WebhookDefinition
- Defined in:
- lib/language_operator/dsl/webhook_definition.rb
Overview
Webhook Definition
Defines webhook endpoints for reactive agents.
Instance Attribute Summary collapse
-
#authentication ⇒ Object
readonly
Returns the value of attribute authentication.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#validations ⇒ Object
readonly
Returns the value of attribute validations.
Instance Method Summary collapse
-
#authenticate { ... } ⇒ void
Define authentication for this webhook.
-
#initialize(path) ⇒ WebhookDefinition
constructor
Initialize webhook definition.
-
#method(method_name) ⇒ void
Set HTTP method.
-
#on_request {|context| ... } ⇒ void
Define the request handler.
-
#register(web_server) ⇒ void
Register this webhook with a web server.
-
#require_content_type(*content_types) ⇒ void
Require specific content type.
-
#require_headers(headers) ⇒ void
Require specific headers.
-
#validate {|context| ... } ⇒ void
Add custom validation.
Constructor Details
#initialize(path) ⇒ WebhookDefinition
Initialize webhook definition
30 31 32 33 34 35 36 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 30 def initialize(path) @path = path @http_method = :post @handler = nil @authentication = nil @validations = [] end |
Instance Attribute Details
#authentication ⇒ Object (readonly)
Returns the value of attribute authentication.
25 26 27 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 25 def authentication @authentication end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
25 26 27 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 25 def handler @handler end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
25 26 27 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 25 def http_method @http_method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 25 def path @path end |
#validations ⇒ Object (readonly)
Returns the value of attribute validations.
25 26 27 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 25 def validations @validations end |
Instance Method Details
#authenticate { ... } ⇒ void
This method returns an undefined value.
Define authentication for this webhook
50 51 52 53 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 50 def authenticate(&block) @authentication = WebhookAuthentication.new @authentication.instance_eval(&block) if block end |
#method(method_name) ⇒ void
This method returns an undefined value.
Set HTTP method
42 43 44 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 42 def method(method_name) @http_method = method_name end |
#on_request {|context| ... } ⇒ void
This method returns an undefined value.
Define the request handler
85 86 87 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 85 def on_request(&block) @handler = block end |
#register(web_server) ⇒ void
This method returns an undefined value.
Register this webhook with a web server
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 93 def register(web_server) return unless @handler web_server.register_route( @path, method: @http_method, authentication: @authentication, validations: @validations, &@handler ) end |
#require_content_type(*content_types) ⇒ void
This method returns an undefined value.
Require specific content type
67 68 69 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 67 def require_content_type(*content_types) @validations << { type: :content_type, config: content_types.flatten } end |
#require_headers(headers) ⇒ void
This method returns an undefined value.
Require specific headers
59 60 61 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 59 def require_headers(headers) @validations << { type: :headers, config: headers } end |
#validate {|context| ... } ⇒ void
This method returns an undefined value.
Add custom validation
76 77 78 |
# File 'lib/language_operator/dsl/webhook_definition.rb', line 76 def validate(&block) @validations << { type: :custom, config: block } end |