Skip to content

Instantly share code, notes, and snippets.

@jusk02
Created April 3, 2017 23:39
Show Gist options
  • Save jusk02/9a1cb4e20626fba53c2f320456cae992 to your computer and use it in GitHub Desktop.
Save jusk02/9a1cb4e20626fba53c2f320456cae992 to your computer and use it in GitHub Desktop.
class Identificacion
include ActiveModel::Model
include ActiveModel::Serializers::JSON
include ActiveModel::AttributeMethods
include ActiveModel::Validations
define_attribute_methods :numeroIdentificacion, :tipoIdentificacion, :lugarExpedicion, :anulado, :fechaCreacion, :preferido, :id, :perfilId
attr_accessor :numeroIdentificacion, :tipoIdentificacion, :lugarExpedicion, :anulado, :fechaCreacion, :preferido, :id, :perfilId
# attr_reader :errors
#for :Serializers:JSON
TIPOS = [['RC','Registro Civil'],['TI','Tarjeta id'],['CC','Cedula']]
def attributes
{
'numeroIdentificacion' => numeroIdentificacion, 'tipoIdentificacion' => tipoIdentificacion,
'lugarExpedicion' => lugarExpedicion,'anulado' => anulado,'preferido' => preferido,'perfilId' => perfilId, 'fechaCreacion' => fechaCreacion
}
end
#asignar valores a los atributos del Identificacion
def assign_params(params)
params.each do |k,v|
send("#{k}=",v)
end
end
def create(access_token,identificacion_id_ant)
self.fechaCreacion = Time.now.strftime("%Y-%m-%dT%T")
self.anulado = false
self.preferido = true
p self.to_json
response = ApiConecction.post("/IdentificacionesPerfil",self.to_json,access_token)
if response.successful?
Identificacion.preferido_update(identificacion_id_ant,access_token) unless identificacion_id_ant.nil?
return true
else
data_or_error = response.extract_data_or_message_error_from_response_api
return data_or_error
end
end
def self.preferido_update(identificacion_id_ant,access_token)
json = {'preferido' => false}
p identificacion_id_ant
response = ApiConecction.patch("/IdentificacionesPerfil/#{identificacion_id_ant}",json,access_token)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment