Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
デモサイトでの取引に対応(動作確認は未)。
  • Loading branch information
unageanu committed Dec 21, 2009
1 parent 938f21e commit 10f2637
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions lib/clickclient_scrap.rb
Expand Up @@ -38,14 +38,15 @@ module ClickClientScrap
class Client
# ホスト名
DEFAULT_HOST_NAME = "https://sec-sso.click-sec.com/mf/"

DEFAULT_DEMO_HOST_NAME = "https://www.click-sec.com/m/demo/"

#
#===コンストラクタ
#
#*proxy*:: プロキシホストを利用する場合、そのホスト名とパスを指定します。
# 例) https://proxyhost.com:80
#
def initialize( proxy=nil )
def initialize( proxy=ENV["http_proxy"], demo=false )
@client = WWW::Mechanize.new {|c|
# プロキシ
if proxy
Expand All @@ -56,7 +57,8 @@ def initialize( proxy=nil )
@client.keep_alive = false
@client.max_history=0
@client.user_agent_alias = 'Windows IE 7'
@host_name = DEFAULT_HOST_NAME
@demo = demo
@host_name = @demo ? DEFAULT_DEMO_HOST_NAME : DEFAULT_HOST_NAME
end

#ログインし、セッションを開始します。
Expand All @@ -74,21 +76,24 @@ def fx_session( userid, password, options={}, &block )
form.j_username = userid
form.j_password = password
result = @client.submit(form, form.buttons.first)
if result.body.toutf8 =~ /<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=([^"]*)">/
result = @client.get($1)
ClickClientScrap::Client.error( result ) if result.links.size <= 0
session = FX::FxSession.new( @client, result.links, options )
if block_given?
begin
yield session
ensure
session.logout
end
else
return session
end
# デモサイトではjsによるリダイレクトは不要。
if !@demo
if result.body.toutf8 =~ /<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=([^"]*)">/
result = @client.get($1)
ClickClientScrap::Client.error( result ) if result.links.size <= 0
else
ClickClientScrap::Client.error( result )
end
end
session = FX::FxSession.new( @client, result.links, options )
if block_given?
begin
yield session
ensure
session.logout
end
else
ClickClientScrap::Client.error( result )
return session
end
end
def self.error( page )
Expand Down Expand Up @@ -669,5 +674,15 @@ def link_click( no )
end
end

class << WWW::Mechanize::Util
def from_native_charset(s, code)
if WWW::Mechanize.html_parser == Nokogiri::HTML
return unless s
Iconv.iconv(code, "UTF-8", s).join("") rescue s # エラーになった場合、変換前の文字列を返す
else
return s
end
end
end


0 comments on commit 10f2637

Please sign in to comment.