lib/nexpose/data_table.rb
# Helper method to get the YUI tables into a consumable Ruby object.
#
# @param [Connection] console API connection to a Nexpose console.
# @param [String] address Controller address relative to https://host:port
# @param [Hash] parameters Parameters that need to be sent to the controller
# @param [Integer] pagination size
# @param [Integer] number of records to return, gets all if not specified
#    The following attributes need to be provided:
#      'sort' Column to sort by
#      'table-id' The ID of the table to get from this controller
# @return [Array[Hash]] An array of hashes representing the requested table.
#
# Example usage:
#   DataTable._get_json_table(@console,
#                             '/data/asset/site',
#                             { 'sort' => 'assetName',
#                               'table-id' => 'site-assets',
#                               'siteID' => site_id })
#
Helper method to get the YUI tables into a consumable Ruby object.
Helper method to get the YUI tables into a consumable Ruby object .
def _get_json_table(console, address, parameters = {}, page_size = 500, records = nil)
      parameters['dir'] = 'DESC'
      parameters['startIndex'] = -1
      parameters['results'] = -1
      post = AJAX.form_post(console, address, parameters)
      data = JSON.parse(post)
      total = records || data['totalRecords']
      return [] if total == 0
      rows = []
      parameters['results'] = page_size
      while rows.length < total
        parameters['startIndex'] = rows.length
        data = JSON.parse(AJAX.form_post(console, address, parameters))
        rows.concat data['records']
      end
      rows
    end
def _get_json_table ( console , address , parameters = { } , page_size = 500 , records = nil ) parameters [ 'dir' ] = 'DESC' parameters [ 'startIndex' ] = - 1 parameters [ 'results' ] = - 1 post = AJAX . form_post ( console , address , parameters ) data = JSON . parse ( post ) total = records || data [ 'totalRecords' ] return [ ] if total == 0 rows = [ ] parameters [ 'results' ] = page_size while rows . length < total parameters [ 'startIndex' ] = rows . length data = JSON . parse ( AJAX . form_post ( console , address , parameters ) ) rows . concat data [ 'records' ] end rows end
Helper method to get the YUI tables into a consumable Ruby object.
Helper method to get the YUI tables into a consumable Ruby object .
] An array of hashes representing the requested table. Example usage: DataTable._get_json_table(@console, '/data/asset/site', { 'sort' => 'assetName', 'table-id' => 'site-assets', 'siteID' => site_id })
] An array of hashes representing the requested table . Example usage : DataTable . _get_json_table ( @console ' / data / asset / site ' { ' sort ' = > ' assetName ' ' table - id ' = > ' site - assets ' ' siteID ' = > site_id } )
Array[Hash
console
<not_specific>
address
<not_specific>
parameters
<not_specific>
page_size
<not_specific>
records
<not_specific>
<not_specific>
number of records to return, gets all if not specified The following attributes need to be provided: 'sort' Column to sort by 'table-id' The ID of the table to get from this controller
number of records to return gets all if not specified The following attributes need to be provided : ' sort ' Column to sort by ' table - id ' The ID of the table to get from this controller