Class: Dadata::CleanClient

Inherits:
ClientBase show all
Defined in:
lib/dadata/client/clean.rb

Overview

Client for data cleaning and standardization operations

Constant Summary collapse

BASE_URL =
'https://cleaner.dadata.ru/api/v1/'

Constants inherited from ClientBase

Dadata::ClientBase::ERRORS, Dadata::ClientBase::STATUS_ERRORS

Constants included from SensitiveData

SensitiveData::SENSITIVE_HEADERS

Instance Method Summary collapse

Methods inherited from ClientBase

#close, #submit

Methods included from SensitiveData

#sanitize_headers, #sanitize_message

Constructor Details

#initialize(token = Dadata.api_key, secret = Dadata.secret_key) ⇒ CleanClient

Returns a new instance of CleanClient.



10
11
12
# File 'lib/dadata/client/clean.rb', line 10

def initialize(token = Dadata.api_key, secret = Dadata.secret_key)
  super(BASE_URL, token, secret)
end

Instance Method Details

#clean(name, source) ⇒ Hash?

Clean and standardize a single value

Parameters:

  • name (String)

    Type of cleaning to apply:

    • address - postal address

    • phone - phone number

    • passport - passport number

    • name - full name

    • email - email address

    • birthdate - date

    • vehicle - vehicle brand and model

    • simple_party_name - company name

  • source (String)

    Value to clean

Returns:

  • (Hash, nil)

    Cleaned data or nil if cleaning failed



27
28
29
30
# File 'lib/dadata/client/clean.rb', line 27

def clean(name, source)
  response = submit("clean/#{name}", [source], :post)
  response&.first
end

#clean_record(structure, record) ⇒ Hash?

Clean and standardize a composite record

Parameters:

  • structure (Array<String>)

    Record structure with fields:

    • AS_IS - leave as is (no standardization)

    • SIMPLE_PARTY_NAME - parse company name

    • NAME - parse as full name

    • BIRTHDATE - parse as date

    • ADDRESS - parse as address

    • PHONE - parse as phone

    • PASSPORT - passport number

    • EMAIL - email address

    • VEHICLE - vehicle brand and model

  • record (Array<String>)

    Record to process; field order must match structure

Returns:

  • (Hash, nil)

    Cleaned data or nil if cleaning failed



46
47
48
49
50
# File 'lib/dadata/client/clean.rb', line 46

def clean_record(structure, record)
  data = { structure:, data: [record] }
  response = submit('clean', data, :post)
  response&.dig('data', 0)
end