def self.qwik_auth_handler_typekey(webclient, resp)
uri = resp.uri
unless %r{>powered by <a href="http://qwik.jp/"\n>qwikWeb</a} =~ resp.body
return nil
end
unless %r{<a href="\.login"\n>Login</a\n>} =~ resp.body
return nil
end
qwik_login_uri = uri + ".login"
resp = webclient.do_request_state(WFO::ReqHTTP.get(qwik_login_uri))
if resp.code == '200'
qwik_typekey_uri = nil
HTree(resp.body).traverse_element("{http://www.w3.org/1999/xhtml}a") {|e|
if e.extract_text.to_s == "Login by TypeKey"
qwik_typekey_uri = qwik_login_uri + e.get_attr('href')
end
}
return nil if !qwik_typekey_uri
elsif resp.code == '302' && %r{/\.typekey\z} =~ resp['Location']
qwik_typekey_uri = URI(resp['Location'])
else
return nil
end
resp = webclient.do_request_state(WFO::ReqHTTP.get(qwik_typekey_uri))
return nil if resp.code != '302'
typekey_uri = URI(resp['Location'])
resp = WFO::Auth.typekey_login(webclient, typekey_uri)
if resp.code == '302'
codeblog_uri = URI(resp['Location'])
resp = webclient.do_request_state(WFO::ReqHTTP.get(codeblog_uri))
end
return nil if resp.code != '200'
return WFO::ReqHTTP.get(uri)
end