Class: Nordea::Session
- Inherits:
-
Object
- Object
- Nordea::Session
- Defined in:
- lib/nordea/session.rb
Instance Attribute Summary collapse
-
#num_requests ⇒ Object
readonly
Returns the value of attribute num_requests.
-
#pin ⇒ Object
Returns the value of attribute pin.
-
#pnr ⇒ Object
Returns the value of attribute pnr.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #accounts(reload = false) ⇒ Object
-
#initialize(pnr, pin, &block) ⇒ Session
constructor
A new instance of Session.
- #login ⇒ Object (also: #login!)
- #logout ⇒ Object (also: #logout!)
- #request(command, extra_params = {}) ⇒ Object
Constructor Details
#initialize(pnr, pin, &block) ⇒ Session
Returns a new instance of Session.
6 7 8 9 10 11 12 13 14 |
# File 'lib/nordea/session.rb', line 6 def initialize(pnr, pin, &block) @pnr, @pin = pnr, pin @num_requests = 0 if block_given? login yield self logout end end |
Instance Attribute Details
#num_requests ⇒ Object (readonly)
Returns the value of attribute num_requests.
4 5 6 |
# File 'lib/nordea/session.rb', line 4 def num_requests @num_requests end |
#pin ⇒ Object
Returns the value of attribute pin.
3 4 5 |
# File 'lib/nordea/session.rb', line 3 def pin @pin end |
#pnr ⇒ Object
Returns the value of attribute pnr.
3 4 5 |
# File 'lib/nordea/session.rb', line 3 def pnr @pnr end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/nordea/session.rb', line 3 def token @token end |
Instance Method Details
#accounts(reload = false) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/nordea/session.rb', line 47 def accounts(reload = false) if reload && @accounts reloaded_xml_nodes = reload_resources(Account) @accounts.each_with_index { |account, idx| account.reload_from_xml(reloaded_xml_nodes[idx]) } else @accounts ||= setup_resources(Account) end end |
#login ⇒ Object Also known as: login!
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nordea/session.rb', line 16 def login doc = request(Commands::LOGIN_PHASE_1, { "kundnr" => pnr, "pinkod" => pin, "sid" => "0" }).parse_xml begin @token = (doc/'*[@name=sid]').attr("value") contract = (doc/'postfield[@name=contract]').attr("value") rescue Exception => e if node = doc.at("card[@title='Fel']") = node.at("p").inner_text.strip else = "" end raise Nordea::InvalidLogin, end request Commands::LOGIN_PHASE_2, "bank" => "mobile_light", "no_prev" => "1", "contract" => contract end |
#logout ⇒ Object Also known as: logout!
34 35 36 |
# File 'lib/nordea/session.rb', line 34 def logout request Commands::LOGOUT end |
#request(command, extra_params = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/nordea/session.rb', line 40 def request(command, extra_params = {}) extra_params.symbolize_keys! extra_params.merge!(:sid => token) unless extra_params.has_key?(:sid) @num_requests += 1 Nordea::Request.new(command, extra_params) end |