Class: FinTS::HTTPSConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/fints/https_connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ HTTPSConnection

Returns a new instance of HTTPSConnection.



3
4
5
# File 'lib/fints/https_connection.rb', line 3

def initialize(url)
  @url = URI(url)
end

Instance Method Details

#send_msg(msg) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fints/https_connection.rb', line 7

def send_msg(msg)
  message_string = msg.to_s.encode('iso-8859-1')
  FinTS::Client.logger.debug("<< #{message_string}")
  data = Base64.encode64(message_string)

  response = Net::HTTP.start(@url.host, @url.port, use_ssl: @url.scheme == 'https') do |http|
    http.post(@url.path, data, {'Content-Type' => 'text/plain'})
  end
  code = response.code.to_i
  if code < 200 || code > 299
    raise ConnectionError, "Bad status code #{code}"
  end
  res = Base64.decode64(response.body).force_encoding('iso-8859-1').encode('utf-8')
  FinTS::Client.logger.debug(">> #{res}")
  res
end