Class: Connect::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/connect/transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, accept_compression: [Compression::Gzip], send_compression: Compression::Gzip, compress_min_bytes: 1024, read_max_bytes: 0xffffffff, write_max_bytes: 0xffffffff) ⇒ Transport

Returns a new instance of Transport.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/connect/transport.rb', line 12

def initialize(
  base_url:,
  accept_compression: [Compression::Gzip],
  send_compression: Compression::Gzip,
  compress_min_bytes: 1024,
  read_max_bytes: 0xffffffff,
  write_max_bytes: 0xffffffff
)
  @base_url = base_url
  @accept_compression = accept_compression
  @send_compression = send_compression
  @compress_min_bytes = compress_min_bytes
  @read_max_bytes = read_max_bytes
  @write_max_bytes = write_max_bytes
end

Instance Attribute Details

#accept_compressionObject (readonly)

Returns the value of attribute accept_compression.



5
6
7
# File 'lib/connect/transport.rb', line 5

def accept_compression
  @accept_compression
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



5
6
7
# File 'lib/connect/transport.rb', line 5

def base_url
  @base_url
end

#compress_min_bytesObject (readonly)

Returns the value of attribute compress_min_bytes.



5
6
7
# File 'lib/connect/transport.rb', line 5

def compress_min_bytes
  @compress_min_bytes
end

#read_max_bytesObject (readonly)

Returns the value of attribute read_max_bytes.



5
6
7
# File 'lib/connect/transport.rb', line 5

def read_max_bytes
  @read_max_bytes
end

#send_compressionObject (readonly)

Returns the value of attribute send_compression.



5
6
7
# File 'lib/connect/transport.rb', line 5

def send_compression
  @send_compression
end

#write_max_bytesObject (readonly)

Returns the value of attribute write_max_bytes.



5
6
7
# File 'lib/connect/transport.rb', line 5

def write_max_bytes
  @write_max_bytes
end

Instance Method Details

#stream(service:, method:, input:, header:, trailer:) ⇒ Object

Raises:

  • (NotImplementedError)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/connect/transport.rb', line 44

def stream(service:, method:, input:, header:, trailer:)
  raise NotImplementedError, "Bidi streaming is not supported with HTTP/1.1" if method.bidi_stream?

  uri = build_uri(service: service, method: method)

  response = do_response(
    uri: uri,
    request: build_stream_request(uri: uri, method: method, input: input, header: header, trailer: trailer),
  )

  case response.code
  when "200"
    parse_stream_response(response: response, method: method)
  else
    raise Connect::Error.new(
      code: Code.for_http_code(response.code),
      message: "Unexpected HTTP status code: #{response.code}",
    )
  end
end

#unary(service:, method:, input:, header:, trailer:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/connect/transport.rb', line 28

def unary(service:, method:, input:, header:, trailer:)
  uri = build_uri(service: service, method: method)

  response = do_response(
    uri: uri,
    request: build_unary_request(uri: uri, method: method, input: input, header: header, trailer: trailer),
  )

  case response.code
  when "200"
    parse_unary_response(response: response, method: method)
  else
    raise parse_unary_error(response: response)
  end
end