Module: Netposti

Defined in:
lib/netposti.rb,
lib/netposti/inbox.rb,
lib/netposti/message.rb,
lib/netposti/version.rb

Defined Under Namespace

Classes: Inbox, LoginError, Message

Constant Summary collapse

LOGIN_URL =
'https://www.posti.fi/omatpalvelut/posti/login'.freeze
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.login(opts) ⇒ Object

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/netposti.rb', line 11

def self.(opts)
  agent = Mechanize.new
  agent.pluggable_parser.default = Mechanize::Download

  page = agent.get(LOGIN_URL)
  inbox = page.form_with(:name => 'loginForm') do |f|
    f['login.username'] = opts[:username]
    f['login.password'] = opts[:password]
  end.click_button

  raise LoginError unless inbox.uri.path.match(/messageListPage/)

  Inbox.new(inbox)
end