fixes error in census_api and refactors constructor
This commit is contained in:
@@ -67,7 +67,7 @@ class Verification::Residence
|
|||||||
private
|
private
|
||||||
|
|
||||||
def residency_valid?
|
def residency_valid?
|
||||||
response = CensusApi.new(document_type, document_number).call
|
response = CensusApi.new.call(document_type, document_number)
|
||||||
|
|
||||||
response.valid? &&
|
response.valid? &&
|
||||||
response.postal_code == postal_code &&
|
response.postal_code == postal_code &&
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
class CensusApi
|
class CensusApi
|
||||||
attr_accessor :document_type, :document_number
|
|
||||||
|
|
||||||
def initialize(document_type, document_number)
|
def call(document_type, document_number)
|
||||||
@document_type = document_type
|
Response.new(get_response_body(document_type, document_number))
|
||||||
@document_number = document_number
|
|
||||||
end
|
|
||||||
|
|
||||||
def call
|
|
||||||
Response.new(get_response_body)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Response
|
class Response
|
||||||
@@ -15,6 +9,10 @@ class CensusApi
|
|||||||
@body = body
|
@body = body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid?
|
||||||
|
data[:datos_habitante][:item].present?
|
||||||
|
end
|
||||||
|
|
||||||
def date_of_birth
|
def date_of_birth
|
||||||
data[:datos_habitante][:item][:fecha_nacimiento_string]
|
data[:datos_habitante][:item][:fecha_nacimiento_string]
|
||||||
end
|
end
|
||||||
@@ -23,10 +21,6 @@ class CensusApi
|
|||||||
data[:datos_vivienda][:item][:codigo_postal]
|
data[:datos_vivienda][:item][:codigo_postal]
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid?
|
|
||||||
data[:datos_habitante][:item].present?
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def data
|
def data
|
||||||
@@ -36,9 +30,9 @@ class CensusApi
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_response_body
|
def get_response_body(document_type, document_number)
|
||||||
if end_point_available
|
if end_point_available?
|
||||||
client.call(:get_habita_datos, message: request).body
|
client.call(:get_habita_datos, message: request(document_type, document_number)).body
|
||||||
else
|
else
|
||||||
stubbed_response_body
|
stubbed_response_body
|
||||||
end
|
end
|
||||||
@@ -48,7 +42,7 @@ class CensusApi
|
|||||||
@client = Savon.client(wsdl: Rails.application.secrets.census_api_end_point)
|
@client = Savon.client(wsdl: Rails.application.secrets.census_api_end_point)
|
||||||
end
|
end
|
||||||
|
|
||||||
def request
|
def request(document_type, document_number)
|
||||||
{ request:
|
{ request:
|
||||||
{ codigo_institucion: Rails.application.secrets.census_api_institution_code,
|
{ codigo_institucion: Rails.application.secrets.census_api_institution_code,
|
||||||
codigo_portal: Rails.application.secrets.census_api_portal_name,
|
codigo_portal: Rails.application.secrets.census_api_portal_name,
|
||||||
|
|||||||
Reference in New Issue
Block a user