class Geocoder::Result::Geoip2

def self.response_attributes

def self.response_attributes
  %w[ip]
end

def city

def city
  fetch_name(
    data.fetch('city', {}).fetch('names', {})
  )
end

def coordinates

def coordinates
  %w[latitude longitude].map do |l|
    data.fetch('location', {}).fetch(l, 0.0)
  end
end

def country

def country
  fetch_name(
    data.fetch('country', {}).fetch('names', {})
  )
end

def country_code

def country_code
  data.fetch('country', {}).fetch('iso_code', '')
end

def data

def data
  @data.to_hash
end

def default_language

def default_language
  @default_language = Geocoder.config[:language].to_s
end

def fetch_name(names)

def fetch_name(names)
  names[language] || names[default_language] || ''
end

def language

def language
  @language ||= default_language
end

def language=(l)

def language=(l)
  @language = l.to_s
end

def postal_code

def postal_code
  data.fetch('postal', {}).fetch('code', '')
end

def state

def state
  fetch_name(
    data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {})
  )
end

def state_code

def state_code
  data.fetch('subdivisions', []).fetch(0, {}).fetch('iso_code', '')
end