Class: Nordea::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/nordea/request.rb

Constant Summary collapse

HOST_NAME =
'gfs.nb.se'
HOST_PORT =
443
SCRIPT_NAME =
'/bin2/gfskod'
USER_AGENT =
'Nokia9110/1.0'

Instance Method Summary collapse

Constructor Details

#initialize(command, extra_params = {}) ⇒ Request

Returns a new instance of Request.



8
9
10
11
# File 'lib/nordea/request.rb', line 8

def initialize(command, extra_params = {})
  @command, @extra_params = command, extra_params
  request
end

Instance Method Details

#connectionObject



13
14
15
16
17
# File 'lib/nordea/request.rb', line 13

def connection
  http = Net::HTTP.new(HOST_NAME, HOST_PORT)
  http.use_ssl = true
  http
end

#headersObject



28
29
30
# File 'lib/nordea/request.rb', line 28

def headers
  { "User-Agent"  => USER_AGENT }
end

#parse_xmlObject



19
20
21
# File 'lib/nordea/request.rb', line 19

def parse_xml 
  Hpricot.XML(response)
end

#queryObject



36
37
38
39
40
# File 'lib/nordea/request.rb', line 36

def query
  @extra_params.merge({ "OBJECT" => @command }).
    inject([]) { |all, (key, value)| all << "#{key}=#{value}" }.
    join("&")
end

#requestObject



23
24
25
26
# File 'lib/nordea/request.rb', line 23

def request
  res = connection.post(SCRIPT_NAME, query, headers)
  @result = res.body
end

#responseObject



32
33
34
# File 'lib/nordea/request.rb', line 32

def response
  @result
end