Class: LogInto::HotSpot_Train

Inherits:
Object
  • Object
show all
Defined in:
lib/weblogin/providers/hotspot_train.rb

Instance Method Summary collapse

Instance Method Details

#is_mine?(response) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/weblogin/providers/hotspot_train.rb', line 6

def is_mine? response
  response.args[:url] =~ /http:\/\/([a-zA-Z0-9.]+\.|)railnet.train/
end

#login(url, cookie, body) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/weblogin/providers/hotspot_train.rb', line 18

def  url, cookie, body
  # find out the real url of the rail site
  dom = Nokogiri::parse(body)
  redirecters = dom.css("meta").map{|i| i.attributes["content"]}.compact
  redirecter = redirecters[0].value
  referer_part = redirecter.match(/URL=(.*)/)[1]
  referer = URI::join(url, referer_part).to_s

  # load the rail site, say hello (just for the sake of saying hello)
  hotspot_train = RestClient.get referer, Cookie: cookie
  # now load the hotspot (finally)
  LogInto::HotSpot.new. referer, cookie, body
end

#login_with_response(response) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/weblogin/providers/hotspot_train.rb', line 10

def  response
  # get some fields that are set anyway
  url = URI.parse(response.args[:url])
  cookie = response.args[:headers][:cookie]
  body = response.body
  ( url, cookie, body )
end