Class: ClickClientScrap::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/clickclient_scrap.rb

Overview

クライアント

Constant Summary collapse

DEFAULT_HOST_NAME =

ホスト名

"https://sec-sso.click-sec.com/mf/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy = nil) ⇒ Client

コンストラクタ

proxy

プロキシホストを利用する場合、そのホスト名とパスを指定します。

例) proxyhost.com:80



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/clickclient_scrap.rb', line 48

def initialize( proxy=nil )
  @client = WWW::Mechanize.new {|c|
    # プロキシ
    if proxy 
      uri = URI.parse( proxy )
      c.set_proxy( uri.host, uri.port )
    end
  }
  @client.keep_alive = false
  @client.max_history=0
  @client.user_agent_alias = 'Windows IE 7'
  @host_name = DEFAULT_HOST_NAME
end

Instance Attribute Details

#host_nameObject

ホスト名



101
102
103
# File 'lib/clickclient_scrap.rb', line 101

def host_name
  @host_name
end

Class Method Details

.error(page) ⇒ Object



94
95
96
97
98
# File 'lib/clickclient_scrap.rb', line 94

def self.error( page )
    msgs = page.body.scan( /<font color="red">([^<]*)</ ).flatten
    error = !msgs.empty? ? msgs.map{|m| m.strip}.join(",") : page.body
    raise "operation failed.detail=#{error}".toutf8 
end

Instance Method Details

#fx_session(userid, password, options = {}, &block) ⇒ Object

ログインし、セッションを開始します。-ブロックを指定した場合、引数としてセッションを指定してブロックを実行します。ブロック実行後、ログアウトします。-そうでない場合、セッションを返却します。この場合、ClickClientScrap::FX::FxSession#logoutを実行しログアウトしてください。

userid

ユーザーID

password

パスワード

options

オプション

戻り値

ClickClientScrap::FX::FxSession



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/clickclient_scrap.rb', line 70

def fx_session( userid, password, options={}, &block )
  page = @client.get(@host_name)
  ClickClientScrap::Client.error(page)  if page.forms.length <= 0
  form = page.forms.first
  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
  else
    ClickClientScrap::Client.error( result )
  end
end