Class: MelissaData::WebSmart::PropertyAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/melissa_data/web_smart/property_api.rb

Constant Summary collapse

USER_AGENT =
"MelissaData-Rubygem/#{MelissaData::VERSION}"
BASE_URL =
'https://property.melissadata.net'

Instance Method Summary collapse

Instance Method Details

#address(address:, city:, state:, zip:, country:) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/melissa_data/web_smart/property_api.rb', line 64

def address(address:, city:, state:, zip:, country:)
  raw = default_connection(BASE_URL, json_headers: true)
    .get '/v3/WEB/ContactVerify/doContactVerify', {
      id: MelissaData.web_smart_id,
      Actions: 'Check',
      a1: address,
      city: city,
      state: state,
      postal: zip,
      ctry: country,
      AdvancedAddressCorrection: 'on'
  }

  res = JSON.parse(raw.body).deep_transform_keys(&:underscore)
  res&.with_indifferent_access[:records]&.first
end

#default_connection(url = BASE_URL, json_headers: false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/melissa_data/web_smart/property_api.rb', line 11

def default_connection(url = BASE_URL, json_headers: false)
  Faraday.new(url: url) do |conn|
    conn.response :logger
    conn.headers[:user_agent] = USER_AGENT

    if json_headers
      conn.headers['Content-Type'] = 'application/json'
      conn.headers['Accept'] = 'application/json'
    end

    conn.adapter :typhoeus
  end
end

#property_by_address(address:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/melissa_data/web_smart/property_api.rb', line 51

def property_by_address(address:)
  raw = default_connection(BASE_URL).get '/v4/WEB/LookupProperty/', {
    id: MelissaData.web_smart_id,
    ff: address,
    cols: 'GrpAll',
    addressKey: nil,
    format: 'json'
  }

  res = JSON.parse(raw.body).deep_transform_keys(&:underscore)
  res&.with_indifferent_access
end

#property_by_address_key(address_key:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/melissa_data/web_smart/property_api.rb', line 39

def property_by_address_key(address_key:)
  raw = default_connection(BASE_URL).get '/v4/WEB/LookupProperty/', {
    id: MelissaData.web_smart_id,
    addressKey: address_key,
    cols: 'GrpAll',
    format: 'json'
  }

  res = JSON.parse(raw.body).deep_transform_keys(&:underscore)
  res&.with_indifferent_access
end

#property_by_apn(fips:, apn:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/melissa_data/web_smart/property_api.rb', line 25

def property_by_apn(fips:, apn:)
  raw = default_connection(BASE_URL).get '/v4/WEB/LookupProperty/', {
    id: MelissaData.web_smart_id,
    fips: fips,
    apn: apn,
    cols: 'GrpAll',
    addressKey: nil,
    format: 'json'
  }

  res = JSON.parse(raw.body).deep_transform_keys(&:underscore)
  res&.with_indifferent_access
end