class VerifiData::SingleAddress

Attributes

city[R]
detail[R]
errors[R]
response[R]
state[R]
street[R]
zip[R]

Public Class Methods

human_attribute_name(attr, options = {}) click to toggle source
# File lib/verifi_data.rb, line 60
def self.human_attribute_name(attr, options = {})
  attr
end
lookup_ancestors() click to toggle source
# File lib/verifi_data.rb, line 64
def self.lookup_ancestors
  [self]
end
new(street: street_in, city: city_in, state: state_in, zip: zip_in, detail: detail_in) click to toggle source
# File lib/verifi_data.rb, line 9
def initialize(street: street_in, city: city_in, state: state_in, zip: zip_in, detail: detail_in)
  @street = street
  @city = city
  @state = state
  @zip = zip 
  @detail = detail
  @errors = ActiveModel::Errors.new(self)
  @response = {}

end

Public Instance Methods

api_key() click to toggle source
# File lib/verifi_data.rb, line 52
def api_key
  ENV["VERIFI_DATA_API_KEY"]
end
get_url() click to toggle source
# File lib/verifi_data.rb, line 48
def get_url
  "http://api.verifi.io/v1/validate/address?api_key=#{api_key}&street=#{street}&city=#{city}&state=#{state}&zip=#{zip}&detail=#{detail}"
end
read_attribute_for_validation(attr) click to toggle source
# File lib/verifi_data.rb, line 56
def read_attribute_for_validation(attr)
  send(attr)
end
validate() click to toggle source
# File lib/verifi_data.rb, line 21
def validate
  if api_key.blank?
    errors[:base] << "No API Key Found"
    return {errors: "No API Key Found"}
  end

  url = URI.encode(get_url)

  RestClient.get(url){ |response, request, result, &block|
    @code = response.code
    case response.code
    when 200
      @response = JSON.parse(response)
      #ap @response[0]["components"]
    else
      
      Rails.logger.info {"Error in #{self.class.name} #{@code}"}
      Rails.logger.info { response  }
      return response

    end
  }    

  return response

end