Class: SBISecuritiesPluginSession

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

Instance Method Summary collapse

Constructor Details

#initialize(props, logger) ⇒ SBISecuritiesPluginSession

Returns a new instance of SBISecuritiesPluginSession.



105
106
107
108
109
# File 'lib/jiji_plugin.rb', line 105

def initialize( props, logger ) 
  @props = props
  @logger = logger
  @m = Mutex.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/jiji_plugin.rb', line 110

def method_missing( name, *args )
  @m.synchronize { 
    begin
      session.send( name, *args )
    rescue
      # エラーになった場合はセッションを再作成する
      close
      
      # セッションタイムアウトの場合1回だけリトライ
      if $!.to_s == "session-time-out"
        @logger.warn "session time out. retry..."
        begin
          session.send( name, *args )
        rescue
          close
          raise $!
        end
      else
        raise $!
      end
    end
  }
end

Instance Method Details

#closeObject



133
134
135
136
137
138
139
140
141
142
# File 'lib/jiji_plugin.rb', line 133

def close
  begin
    @session.logout if @session
  rescue
    @logger.error $!
  ensure
    @session = nil
    @client = nil
  end
end

#sessionObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/jiji_plugin.rb', line 143

def session
  begin
    proxy = nil
    if @props.key?(:proxy) && @props[:proxy] != nil && @props[:proxy].length > 0
      proxy = @props[:proxy]
    end
    @client ||= SBIClient::Client.new( proxy )
    @session ||= @client.fx_session( @props[:user], @props[:password], @props[:trade_password] )
  rescue
    @logger.error $!
    raise $!
  end
  @session
end