Class: RetrieveRecords

Inherits:
DataverseOperations show all
Defined in:
lib/dvla/dataverse/operations/retrieve_records.rb

Instance Method Summary collapse

Methods inherited from DataverseOperations

#apply_filter, #get_url_from_config_file, #http_request_artifacts, #initialize, #send_request, #setup_http_headers

Constructor Details

This class inherits a constructor from DataverseOperations

Instance Method Details

#get_records(record_name: nil, max_return: nil) ⇒ Array

Get all the records as an array. If no records is found, this function will throw http 404 error. You can retrieve sub-records using the filter. You can only set the maximum records to be return if specify the record name

Examples:

ex.get_all_records
ex.get_all_records(record_name: 'emails')
ex.get_all_records(record_name: 'emails', max_return: 3)

Parameters:

  • record_name (String) (defaults to: nil)

    the name of the record

  • max_return (Int) (defaults to: nil)

    the number of records to be returned

Returns:

  • (Array)

    the list of records

Raises:

  • 404 Not Found



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dvla/dataverse/operations/retrieve_records.rb', line 25

def get_records(record_name: nil, max_return: nil)
  unless record_name.nil?
    apply_filter({
                   record_name: record_name,
                   top: max_return
                 })
  end

  send_request
    &.body
    .then { |response| JSON.parse(response) if response }
    .then { |values| values['value'] || values }
end

#setup_artifactsObject



5
6
7
8
9
# File 'lib/dvla/dataverse/operations/retrieve_records.rb', line 5

def setup_artifacts
  setup_http_headers
  http_request_artifacts.url = get_url_from_config_file
  http_request_artifacts.method = :get
end