Method: Esi::Client#with_client

Defined in:
lib/esi/client.rb

#with_clientObject

Yield block with instance of Esi::Client and revert to

previous client or default client

Examples:

Call an Esi::Client method using an instance of client

new_client = Esi::Client.new(token: 'foo', refresh_token: 'foo', exceptionxpires_at: 30.minutes.from_now)
new_client.with_client do |client|
  client.character(1234)
end
#=> Esi::Response<#>

Yield Returns:

  • (#block)

    the passed block.



74
75
76
77
78
79
80
81
# File 'lib/esi/client.rb', line 74

def with_client
  initial_client = Esi::Client.current
  switch_to
  yield(self) if block_given?
ensure
  initial_client.switch_to if initial_client
  Esi::Client.switch_to_default unless initial_client
end