Class: A2A::Types::PushNotificationConfig

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/a2a/types/push_notification.rb

Overview

Represents a push notification configuration

Push notification configs define how and where to send notifications about task updates and other events.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type

Constructor Details

#initialize(url:, id: nil, token: nil, authentication: nil) ⇒ PushNotificationConfig

Initialize a new push notification config

Parameters:

  • The webhook URL

  • (defaults to: nil)

    Optional config identifier

  • (defaults to: nil)

    Optional authentication token

  • (defaults to: nil)

    Authentication configuration



21
22
23
24
25
26
27
28
# File 'lib/a2a/types/push_notification.rb', line 21

def initialize(url:, id: nil, token: nil, authentication: nil)
  @url = url
  @id = id
  @token = token
  @authentication = authentication

  validate!
end

Instance Attribute Details

#authenticationObject (readonly)

Returns the value of attribute authentication.



12
13
14
# File 'lib/a2a/types/push_notification.rb', line 12

def authentication
  @authentication
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/a2a/types/push_notification.rb', line 12

def id
  @id
end

#tokenObject (readonly)

Returns the value of attribute token.



12
13
14
# File 'lib/a2a/types/push_notification.rb', line 12

def token
  @token
end

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/a2a/types/push_notification.rb', line 12

def url
  @url
end

Instance Method Details

#auth_headersHash

Get authentication headers for webhook requests

Returns:

  • Headers to include in webhook requests



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/a2a/types/push_notification.rb', line 42

def auth_headers
  headers = {}

  headers["Authorization"] = "Bearer #{@token}" if @token

  if @authentication.is_a?(Hash)
    case @authentication["type"]
    when "bearer"
      headers["Authorization"] = "Bearer #{@authentication['token']}"
    when "basic"
      require "base64"
      credentials = Base64.strict_encode64("#{@authentication['username']}:#{@authentication['password']}")
      headers["Authorization"] = "Basic #{credentials}"
    when "api_key"
      key_name = @authentication["key_name"] || "X-API-Key"
      headers[key_name] = @authentication["api_key"]
    end
  end

  headers
end

#authenticated?Boolean

Check if authentication is configured

Returns:

  • True if authentication is present



34
35
36
# File 'lib/a2a/types/push_notification.rb', line 34

def authenticated?
  !@token.nil? || !@authentication.nil?
end

#validate!Object (private)



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/a2a/types/push_notification.rb', line 66

def validate!
  validate_required(:url)
  validate_type(:url, String)

  # Basic URL validation
  begin
    require "uri"
    uri = URI.parse(@url)
    raise ArgumentError, "URL must be HTTP or HTTPS" unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
  rescue URI::InvalidURIError
    raise ArgumentError, "Invalid URL: #{@url}"
  end
end