class Responsys::Api::Client

Attributes

client[RW]

Public Class Methods

new() click to toggle source
# File lib/responsys/api/client.rb, line 13
def initialize
  @raise_exceptions = false
end

Public Instance Methods

api_method(action, message = nil, response_type = :hash) click to toggle source
# File lib/responsys/api/client.rb, line 17
def api_method(action, message = nil, response_type = :hash)
  raise ParameterException.new("api.client.api_method.wrong_action_#{action.to_s}") if action.to_sym == :login || action.to_sym == :logout

  unless Responsys.configuration.enabled?
    raise DisabledException.new if @raise_exceptions
    return "disabled"
  end

  SessionPool.instance.with do |session|
    begin
      session.login
      response = session.run_with_credentials(action, message)
      session.logout
      case response_type
      when :result
       Responsys::Helper.format_response_result(response, action)
      when :hash
       Responsys::Helper.format_response_hash(response, action)
      else
       response
      end
    rescue Savon::Error => e
      Responsys::Helper.format_response_with_errors(e)
    end
  end
end
available_operations() click to toggle source
# File lib/responsys/api/client.rb, line 58
def available_operations
  SessionPool.instance.with do |session|
    session.operations
  end
end
run(exception_raising = false) { |self| ... } click to toggle source

For internal use ONLY

# File lib/responsys/api/client.rb, line 45
def run(exception_raising = false)
  old_raise_exceptions = @raise_exceptions
  @raise_exceptions = exception_raising
  begin
    yield(self)
  rescue DisabledException => e
    raise e if @raise_exceptions
    return "disabled"
  ensure
    @raise_exceptions = old_raise_exceptions
  end
end