fixes error in census_api and refactors constructor

This commit is contained in:
kikito
2015-09-30 10:56:57 +02:00
parent 1c372328d9
commit cc1a69c7a5
2 changed files with 11 additions and 17 deletions

View File

@@ -67,7 +67,7 @@ class Verification::Residence
private
def residency_valid?
response = CensusApi.new(document_type, document_number).call
response = CensusApi.new.call(document_type, document_number)
response.valid? &&
response.postal_code == postal_code &&

View File

@@ -1,13 +1,7 @@
class CensusApi
attr_accessor :document_type, :document_number
def initialize(document_type, document_number)
@document_type = document_type
@document_number = document_number
end
def call
Response.new(get_response_body)
def call(document_type, document_number)
Response.new(get_response_body(document_type, document_number))
end
class Response
@@ -15,6 +9,10 @@ class CensusApi
@body = body
end
def valid?
data[:datos_habitante][:item].present?
end
def date_of_birth
data[:datos_habitante][:item][:fecha_nacimiento_string]
end
@@ -23,10 +21,6 @@ class CensusApi
data[:datos_vivienda][:item][:codigo_postal]
end
def valid?
data[:datos_habitante][:item].present?
end
private
def data
@@ -36,9 +30,9 @@ class CensusApi
private
def get_response_body
if end_point_available
client.call(:get_habita_datos, message: request).body
def get_response_body(document_type, document_number)
if end_point_available?
client.call(:get_habita_datos, message: request(document_type, document_number)).body
else
stubbed_response_body
end
@@ -48,7 +42,7 @@ class CensusApi
@client = Savon.client(wsdl: Rails.application.secrets.census_api_end_point)
end
def request
def request(document_type, document_number)
{ request:
{ codigo_institucion: Rails.application.secrets.census_api_institution_code,
codigo_portal: Rails.application.secrets.census_api_portal_name,