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.



102
103
104
105
106
# File 'lib/jiji_plugin.rb', line 102

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



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

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
          close
          session.send( name, *args )
        rescue
          close
          raise $!
        end
      else
        raise $!
      end
    end
  }
end

Instance Method Details

#closeObject



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

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

#sessionObject



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

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