Class: AlfaBank::RequestSender

Inherits:
Object
  • Object
show all
Defined in:
lib/alfa_bank/request_sender.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_type, params) ⇒ RequestSender

Returns a new instance of RequestSender.



8
9
10
# File 'lib/alfa_bank/request_sender.rb', line 8

def initialize(request_type, params)
  @data_builder = DataBuilder.new(request_type, params)
end

Instance Attribute Details

#data_builderObject

Returns the value of attribute data_builder.



6
7
8
# File 'lib/alfa_bank/request_sender.rb', line 6

def data_builder
  @data_builder
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/alfa_bank/request_sender.rb', line 12

def call
  uri = URI.parse(data_builder.link)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
  params = data_builder.call
  request.set_form_data params

  http.request(request)
end