Class: A2A::Protocol::HttpJson

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/protocol/http_json.rb,
lib/a2a/protocol/http_json/transport.rb

Defined Under Namespace

Classes: Transport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, version: Versioning::CURRENT, headers: {}, extensions: [], transport: Transport.new) ⇒ HttpJson

Returns a new instance of HttpJson.



10
11
12
13
14
15
16
17
# File 'lib/a2a/protocol/http_json.rb', line 10

def initialize(url:, version: Versioning::CURRENT, headers: {}, extensions: [], transport: Transport.new)
  @url = url.chomp("/")
  @version = version
  @headers = headers
  @extensions = extensions
  @transport = transport
  @built_headers = build_headers
end

Instance Attribute Details

#extensionsObject (readonly)

Returns the value of attribute extensions.



8
9
10
# File 'lib/a2a/protocol/http_json.rb', line 8

def extensions
  @extensions
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/a2a/protocol/http_json.rb', line 8

def headers
  @headers
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/a2a/protocol/http_json.rb', line 8

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/a2a/protocol/http_json.rb', line 8

def version
  @version
end

Instance Method Details

#delete(path) ⇒ Object



27
28
29
# File 'lib/a2a/protocol/http_json.rb', line 27

def delete(path)
  @transport.delete("#{@url}#{path}", headers: @built_headers)
end

#get(path, query: {}) ⇒ Object



19
20
21
# File 'lib/a2a/protocol/http_json.rb', line 19

def get(path, query: {})
  @transport.get("#{@url}#{path}", query: query, headers: @built_headers)
end

#post(path, body: {}) ⇒ Object



23
24
25
# File 'lib/a2a/protocol/http_json.rb', line 23

def post(path, body: {})
  @transport.post("#{@url}#{path}", body: body, headers: @built_headers)
end

#stream(path, method: :post, body: {}, query: {}) ⇒ Object



31
32
33
34
# File 'lib/a2a/protocol/http_json.rb', line 31

def stream(path, method: :post, body: {}, query: {}, &)
  sse_headers = @built_headers.merge("Accept" => "text/event-stream")
  @transport.stream("#{@url}#{path}", headers: sse_headers, method: method, body: body, query: query, &)
end