class Sbirsp::Client

Attributes

client[RW]
login_status[RW]
loop_status[RW]
now_code[RW]
now_price[RW]

Public Class Methods

new() click to toggle source
# File lib/sbirsp.rb, line 24
def initialize
@client = Masque.new(:display => 99, :driver => :poltergeist)
@now_price = 0 
  login
end

Public Instance Methods

code=(stock_code) click to toggle source
# File lib/sbirsp.rb, line 43
def code=(stock_code)
  @now_code = stock_code
end
get_stock_price() click to toggle source
# File lib/sbirsp.rb, line 74
def get_stock_price
   Thread.fork(@now_code) do |stock_code|
       @loop_status = true
          while @loop_status do
            now_price = @now_price
            @client.run do
          now_price = find("#flash").text.delete(",").to_i
        end
        @now_price = now_price
         if stock_code != @now_code
          @loop_status = false
          Thread.stop
        end
      end
        end
end
login() click to toggle source
# File lib/sbirsp.rb, line 30
def login
  @client.run do
    visit Sbirsp.configuration.default_host
    fill_in("user_id", :with => Sbirsp.configuration.username)
    fill_in("user_password", :with => Sbirsp.configuration.password)
    find('*[name="ACT_login"]').click
  end
    sleep 5
    puts "logined"
    @login_status = true
    @current_host ||= "#{@client.agent.page.current_host}"
end
price() click to toggle source
# File lib/sbirsp.rb, line 95
def price
  @now_price
end
realtime_on() click to toggle source
# File lib/sbirsp.rb, line 57
def realtime_on
  check_login
  check_stock_code
  @client.run do
    puts "visited: #{@now_code}"
    find("#imgRefArea_MTB0_on").click
  end
end
show_stock_price() click to toggle source
# File lib/sbirsp.rb, line 66
def show_stock_price
      check_login
  @loop_status = false
  visit_stock_page
  realtime_on
  get_stock_price unless @loop_status
end
stop_get_stock_price() click to toggle source
# File lib/sbirsp.rb, line 91
def stop_get_stock_price
  @loop_status = false
end
visit_stock_page() click to toggle source
# File lib/sbirsp.rb, line 47
def visit_stock_page
  check_login
  check_stock_code
    url = "#{@current_host}/ETGate/?_ControlID=WPLETsiR001Control&_DataStoreID=DSWPLETsiR001Control&_PageID=WPLETsiR001Idtl10&_ActionID=getInfoOfCurrentMarket&s_rkbn=&i_dom_flg=1&stock_sec_code_mul=#{@now_code}&exchange_code=&ref_from=1&ref_to=20"
  @client.run do
    visit(url)
    sleep 5
  end
end

Private Instance Methods

check_login() click to toggle source
# File lib/sbirsp.rb, line 100
def check_login
  unless @login_status
    puts "not logined" 
    return false
  end
end
check_stock_code() click to toggle source
# File lib/sbirsp.rb, line 107
def check_stock_code
  unless @now_code
    puts "please set stock_code" 
    return false
  end
end