Module: Dvla::Dataverse::Helper

Defined in:
lib/dvla/dataverse/helper.rb,
lib/dvla/dataverse/helper/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.4"

Class Method Summary collapse

Class Method Details

.create_record(record_name, record_data) ⇒ Object

create a new record. You must provide the record name and the record payload/data. The payload/data must be a hash

Examples:

payload = {email => '[email protected]'}
new_record('user', payload)

Parameters:

  • record_name (String)

    the name of the record

  • record_data (Hash)

    the record payload



51
52
53
54
55
# File 'lib/dvla/dataverse/helper.rb', line 51

def self.create_record(record_name, record_data)
  CreateRecords
    .new
    .new_record(record_name, record_data)
end

.delete_record(record_name, record_id) ⇒ Object

remove the record. You must provide the record ID and the record name. The record ID and the record name should be string

Examples:

remove_record('user', '123-123-123')

Parameters:

  • record_name (String)

    the name of the record

  • record_id (String)

    the record ID usually its UUID



65
66
67
68
69
# File 'lib/dvla/dataverse/helper.rb', line 65

def self.delete_record(record_name, record_id)
  DeleteRecord
    .new
    .remove_record(record_name, record_id)
end

.retrieve_record(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



36
37
38
39
40
# File 'lib/dvla/dataverse/helper.rb', line 36

def self.retrieve_record(record_name: nil, max_return: nil)
  RetrieveRecords
    .new
    .get_records(record_name: record_name, max_return: max_return)
end

.service_checkObject

check if the service is online, also, check if the connection is established without and error.



89
90
91
92
93
# File 'lib/dvla/dataverse/helper.rb', line 89

def self.service_check
  ServiceCheck
    .new
    .send_request
end

.update_record(record_name, record_id, record_data) ⇒ Object

update the record. You must provide the record name, the record ID, and the record data.

Examples:

payload = {email => '[email protected]'}
alter_record('user', '123-123-123', payload)

Parameters:

  • record_name (String)

    the name of the record

  • record_id (String)

    the record ID usually its UUID

  • record_data (Hash)

    the record payload



81
82
83
84
85
# File 'lib/dvla/dataverse/helper.rb', line 81

def self.update_record(record_name, record_id, record_data)
  UpdateRecord
    .new
    .alter_record(record_name, record_id, record_data)
end