Class: ClickSecuritiesPluginSession

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

Instance Method Summary collapse

Constructor Details

#initialize(props, logger) ⇒ ClickSecuritiesPluginSession

Returns a new instance of ClickSecuritiesPluginSession.



88
89
90
91
92
# File 'lib/jiji_plugin.rb', line 88

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



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/jiji_plugin.rb', line 93

def method_missing( name, *args )
  @m.synchronize { 
    begin
      session.send( name, *args )
    rescue
      # エラーになった場合はセッションを再作成する
      close
      raise $!
    end
  }
end

Instance Method Details

#closeObject



104
105
106
107
108
109
110
111
112
113
# File 'lib/jiji_plugin.rb', line 104

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

#sessionObject



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/jiji_plugin.rb', line 114

def session
  begin
    @client ||= ClickClientScrap::Client.new( 
       @props.key?(:proxy) ? @props[:proxy] : nil )
    @session ||= @client.fx_session( @props[:user], @props[:password] )
  rescue
    @logger.error $!
    raise $!
  end
  @session
end