clickclient_scrap 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -1
- data/lib/clickclient_scrap.rb +39 -22
- data/test/test_jiji_plugin.rb +2 -2
- metadata +2 -2
data/ChangeLog
CHANGED
data/lib/clickclient_scrap.rb
CHANGED
@@ -38,14 +38,15 @@ module ClickClientScrap
|
|
38
38
|
class Client
|
39
39
|
# ホスト名
|
40
40
|
DEFAULT_HOST_NAME = "https://sec-sso.click-sec.com/mf/"
|
41
|
-
|
41
|
+
DEFAULT_DEMO_HOST_NAME = "https://www.click-sec.com/m/demo/"
|
42
|
+
|
42
43
|
#
|
43
44
|
#===コンストラクタ
|
44
45
|
#
|
45
46
|
#*proxy*:: プロキシホストを利用する場合、そのホスト名とパスを指定します。
|
46
47
|
# 例) https://proxyhost.com:80
|
47
48
|
#
|
48
|
-
def initialize( proxy=
|
49
|
+
def initialize( proxy=ENV["http_proxy"], demo=false )
|
49
50
|
@client = WWW::Mechanize.new {|c|
|
50
51
|
# プロキシ
|
51
52
|
if proxy
|
@@ -56,7 +57,8 @@ module ClickClientScrap
|
|
56
57
|
@client.keep_alive = false
|
57
58
|
@client.max_history=0
|
58
59
|
@client.user_agent_alias = 'Windows IE 7'
|
59
|
-
@
|
60
|
+
@demo = demo
|
61
|
+
@host_name = @demo ? DEFAULT_DEMO_HOST_NAME : DEFAULT_HOST_NAME
|
60
62
|
end
|
61
63
|
|
62
64
|
#ログインし、セッションを開始します。
|
@@ -74,21 +76,24 @@ module ClickClientScrap
|
|
74
76
|
form.j_username = userid
|
75
77
|
form.j_password = password
|
76
78
|
result = @client.submit(form, form.buttons.first)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
79
|
+
# デモサイトではjsによるリダイレクトは不要。
|
80
|
+
if !@demo
|
81
|
+
if result.body.toutf8 =~ /<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=([^"]*)">/
|
82
|
+
result = @client.get($1)
|
83
|
+
ClickClientScrap::Client.error( result ) if result.links.size <= 0
|
84
|
+
else
|
85
|
+
ClickClientScrap::Client.error( result )
|
86
|
+
end
|
87
|
+
end
|
88
|
+
session = FX::FxSession.new( @client, result.links, options )
|
89
|
+
if block_given?
|
90
|
+
begin
|
91
|
+
yield session
|
92
|
+
ensure
|
93
|
+
session.logout
|
94
|
+
end
|
90
95
|
else
|
91
|
-
|
96
|
+
return session
|
92
97
|
end
|
93
98
|
end
|
94
99
|
def self.error( page )
|
@@ -200,13 +205,13 @@ module ClickClientScrap
|
|
200
205
|
@swaps = list_swaps
|
201
206
|
@last_update_time_of_swaps = Time.now.to_i
|
202
207
|
end
|
203
|
-
reg = />([A-Z]+\/[A-Z]+)<\/a>[^\-\.\d]*?([\d]+\.[\d]
|
208
|
+
reg = />([A-Z]+\/[A-Z]+)<\/a>[^\-\.\d]*?([\d]+\.[\d]+)\-[^\-\.\d]*([\d\.]+)/
|
204
209
|
tokens = result.body.toutf8.scan( reg )
|
205
210
|
ClickClientScrap::Client.error( result ) if !tokens || tokens.empty?
|
206
211
|
return tokens.inject({}) {|r,l|
|
207
212
|
pair = to_pair( l[0] )
|
208
213
|
swap = @swaps[pair]
|
209
|
-
rate = FxSession.convert_rate l[1]
|
214
|
+
rate = FxSession.convert_rate "#{l[1]}-#{l[2]}"
|
210
215
|
if ( rate && swap )
|
211
216
|
r[pair] = Rate.new( pair, rate[0], rate[1], swap.sell_swap, swap.buy_swap )
|
212
217
|
end
|
@@ -215,7 +220,7 @@ module ClickClientScrap
|
|
215
220
|
end
|
216
221
|
#12.34-35 形式の文字列をbidレート、askレートに変換する。
|
217
222
|
def self.convert_rate( str ) #:nodoc:
|
218
|
-
if str =~
|
223
|
+
if str =~ /^([\d]+)\.([\d]+)\-([\d]+)$/
|
219
224
|
high = $1
|
220
225
|
low = $2
|
221
226
|
low2 = $3
|
@@ -226,6 +231,8 @@ module ClickClientScrap
|
|
226
231
|
end
|
227
232
|
ask = high.to_f+(ask_low/10**low.length)
|
228
233
|
return [bid,ask]
|
234
|
+
elsif str =~ /^([\d]+\.[\d]+)\-([\d]+\.[\d]+)$/
|
235
|
+
return [$1.to_f,$2.to_f]
|
229
236
|
end
|
230
237
|
end
|
231
238
|
|
@@ -234,10 +241,10 @@ module ClickClientScrap
|
|
234
241
|
#戻り値:: 通貨ペアをキーとするClickClientScrap::FX::Swapのハッシュ。
|
235
242
|
def list_swaps
|
236
243
|
result = link_click( "8" )
|
237
|
-
reg = /<dd>([A-Z]+\/[A-Z]+) <font[^>]*>売<\/font>[^\-\d]*?([\-\d]+)[^\-\d]*<font[^>]*>買<\/font>[^\-\d]*([\-\d]+)[^\-\d]*<\/dd>/
|
244
|
+
reg = /<dd>([A-Z]+\/[A-Z]+) <font[^>]*>売<\/font>[^\-\d]*?([\-\d,]+)[^\-\d]*<font[^>]*>買<\/font>[^\-\d]*([\-\d,]+)[^\-\d]*<\/dd>/
|
238
245
|
return result.body.toutf8.scan( reg ).inject({}) {|r,l|
|
239
246
|
pair = to_pair( l[0] )
|
240
|
-
r[pair] = Swap.new( pair, l[1].to_i, l[2].to_i ); r
|
247
|
+
r[pair] = Swap.new( pair, l[1].sub(/,/,"").to_i, l[2].sub(/,/,"").to_i ); r
|
241
248
|
}
|
242
249
|
end
|
243
250
|
|
@@ -669,5 +676,15 @@ module ClickClientScrap
|
|
669
676
|
end
|
670
677
|
end
|
671
678
|
|
679
|
+
class << WWW::Mechanize::Util
|
680
|
+
def from_native_charset(s, code)
|
681
|
+
if WWW::Mechanize.html_parser == Nokogiri::HTML
|
682
|
+
return unless s
|
683
|
+
Iconv.iconv(code, "UTF-8", s).join("") rescue s # エラーになった場合、変換前の文字列を返す
|
684
|
+
else
|
685
|
+
return s
|
686
|
+
end
|
687
|
+
end
|
688
|
+
end
|
672
689
|
|
673
690
|
|
data/test/test_jiji_plugin.rb
CHANGED
@@ -15,8 +15,8 @@ class JIJIPluginTest < RUNIT::TestCase
|
|
15
15
|
|
16
16
|
def setup
|
17
17
|
@logger = Logger.new STDOUT
|
18
|
-
@user = IO.read( "../
|
19
|
-
@pass = IO.read( "../
|
18
|
+
@user = IO.read( "../etc/user" )
|
19
|
+
@pass = IO.read( "../etc/pass" )
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_basic
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickclient_scrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaya Yamauchi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-27 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|