Class: VerifiData::SingleAddress
- Inherits:
-
Object
- Object
- VerifiData::SingleAddress
- Defined in:
- lib/verifi_data.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#street ⇒ Object
readonly
Returns the value of attribute street.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
Class Method Summary collapse
Instance Method Summary collapse
- #api_key ⇒ Object
- #get_url ⇒ Object
-
#initialize(street: street_in, city: city_in, state: state_in, zip: zip_in, detail: detail_in) ⇒ SingleAddress
constructor
A new instance of SingleAddress.
- #read_attribute_for_validation(attr) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(street: street_in, city: city_in, state: state_in, zip: zip_in, detail: detail_in) ⇒ SingleAddress
Returns a new instance of SingleAddress.
9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
7 8 9 |
# File 'lib/verifi_data.rb', line 7 def city @city end |
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
7 8 9 |
# File 'lib/verifi_data.rb', line 7 def detail @detail end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/verifi_data.rb', line 7 def errors @errors end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/verifi_data.rb', line 7 def response @response end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
7 8 9 |
# File 'lib/verifi_data.rb', line 7 def state @state end |
#street ⇒ Object (readonly)
Returns the value of attribute street.
7 8 9 |
# File 'lib/verifi_data.rb', line 7 def street @street end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
7 8 9 |
# File 'lib/verifi_data.rb', line 7 def zip @zip end |
Class Method Details
.human_attribute_name(attr, options = {}) ⇒ Object
60 61 62 |
# File 'lib/verifi_data.rb', line 60 def self.human_attribute_name(attr, = {}) attr end |
.lookup_ancestors ⇒ Object
64 65 66 |
# File 'lib/verifi_data.rb', line 64 def self.lookup_ancestors [self] end |
Instance Method Details
#api_key ⇒ Object
52 53 54 |
# File 'lib/verifi_data.rb', line 52 def api_key ENV["VERIFI_DATA_API_KEY"] end |
#get_url ⇒ Object
48 49 50 |
# 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) ⇒ Object
56 57 58 |
# File 'lib/verifi_data.rb', line 56 def read_attribute_for_validation(attr) send(attr) end |
#validate ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |