Class: Thrift::FaradayTransport

Inherits:
BaseTransport
  • Object
show all
Defined in:
lib/thrift/faraday_transport.rb

Overview

Faraday HTTP-transport for Thrift

Defined Under Namespace

Classes: FaradayException, UnexpectedHTTPCode

Constant Summary collapse

VERSION =

Gem trhfit-faraday_transport version

Gem.loaded_specs['thrift-faraday_transport'].version.to_s
BASE_HEADERS =

Base headers for response

{ 'Content-Type' => 'application/x-thrift' }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_connection) ⇒ Thrift::FaradayTransport

Initialize new Faraday transport


42
43
44
45
# File 'lib/thrift/faraday_transport.rb', line 42

def initialize(faraday_connection)
  @faraday_connection = faraday_connection
  flush_out_buffer
end

Instance Attribute Details

#faraday_connectionFaraday::Connection (readonly)


35
36
37
# File 'lib/thrift/faraday_transport.rb', line 35

def faraday_connection
  @faraday_connection
end

Instance Method Details

#flushObject

Perform HTTP request. Implement Thrift::BaseTransport#flush

Raises:


69
70
71
72
73
74
75
76
# File 'lib/thrift/faraday_transport.rb', line 69

def flush
  response = perform_request
  raise UnexpectedHTTPCode, response.status if response.status != 200
  body = Bytes.force_binary_encoding(response.body)
  @in_buffer = StringIO.new(body)
ensure
  flush_out_buffer
end

#open?Boolean


47
48
49
# File 'lib/thrift/faraday_transport.rb', line 47

def open?
  true
end

#read(size) ⇒ Object

Implement Thrift::BaseTransport#read


61
62
63
# File 'lib/thrift/faraday_transport.rb', line 61

def read(size)
  @in_buffer.read(size)
end

#write(data) ⇒ Object

Implement Thrift::BaseTransport#write


54
55
56
# File 'lib/thrift/faraday_transport.rb', line 54

def write(data)
  @out_buffer << data
end