lib/turntabler/client.rb
def api(command, params = {})
      raise(ConnectionError, 'Connection is not open') unless @connection && @connection.connected?
      
      message_id = @connection.publish(params.merge(:api => command))

      # Wait until we get a response for the given message
      data = wait do |&resume|
        on(:response_received, :once => true, :if => {'msgid' => message_id}) {|data| resume.call(data)}
      end

      if data['success']
        data
      else
        error = data['error'] || data['err']
        raise APIError, "Command \"#{command}\" failed with message: \"#{error}\""
      end
    end
def api(command, params = {})
      raise(ConnectionError, 'Connection is not open') unless @connection && @connection.connected?
      
      message_id = @connection.publish(params.merge(:api => command))

      # Wait until we get a response for the given message
      data = wait do |&resume|
        on(:response_received, :once => true, :if => {'msgid' => message_id}) {|data| resume.call(data)}
      end

      if data['success']
        data
      else
        error = data['error'] || data['err']
        raise APIError, "Command \"#{command}\" failed with message: \"#{error}\""
      end
    end
def api ( command , params = { } ) raise ( ConnectionError , 'Connection is not open' ) unless @connection && @connection . connected? message_id = @connection . publish ( params . merge ( :api => command ) ) # Wait until we get a response for the given message data = wait do | & resume | on ( :response_received , :once => true , :if => { 'msgid' => message_id } ) { | data | resume . call ( data ) } end if data [ 'success' ] data else error = data [ 'error' ] || data [ 'err' ] raise APIError , "Command \"#{command}\" failed with message: \"#{error}\"" end end
Runs the given API command.

 @api private
 @param [String] command The name of the command to execute
 @param [Hash] params The parameters to pass into the command
 @return [Hash] The data returned from the Turntable service
 @raise [Turntabler::Error] if the connection is not open or the command fails to execute
Runs the given API command .