Skip to content

Commit

Permalink
Add schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrprompt committed Dec 11, 2020
1 parent 8ac60e7 commit f54ca30
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 12 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"php": "^7.4|^8",
"ext-json": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^7.2"
"guzzlehttp/guzzle": "^7.2",
"justinrainbow/json-schema": "^5.2"
},
"require-dev": {
"fakerphp/faker": "^1.12",
Expand Down
68 changes: 67 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions schemas/imovelweb_anuncios_anuncios__atualizar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"caracteristicas": [
{
"id": "string",
"idValor": "string",
"nombre": "string",
"valor": "string"
}
],
"claveReferencia": "string",
"codigoAviso": "string",
"descripcion": "string",
"estado": "string",
"localizacion": {
"codigoPostal": "string",
"direccion": "string",
"idUbicacion": "string",
"latitud": "string",
"longitud": "string",
"muestraMapa": "string",
"ubicacion": "string"
},
"multimedia": {
"imagenes": [
{
"titulo": "string",
"urlImagenOriginal": "string",
"urlImagenPortal": "string"
}
],
"planos": [
{
"titulo": "string",
"urlImagenOriginal": "string",
"urlImagenPortal": "string"
}
],
"recorridos360": [
{
"codigoRecorrido360": "string",
"titulo": "string"
}
],
"videos": [
{
"codigoVideo": "string",
"titulo": "string"
}
]
},
"precios": [
{
"moneda": "string",
"monto": "string",
"operacion": "string"
}
],
"publicacion": {
"fechaOffline": "2020-12-11T19:50:26.487Z",
"fechaOnline": "2020-12-11T19:50:26.487Z",
"tipoDePublicacion": "string"
},
"publicador": {
"codigoInmobiliaria": "string",
"emailAsesor": "string",
"emailDeContacto": "string",
"nombreDeContacto": "string",
"telefonoDeContacto": "string"
},
"tipoDePropiedad": {
"idSubTipo": "string",
"idTipo": "string",
"subTipo": "string",
"tipo": "string"
},
"titulo": "string"
}
159 changes: 159 additions & 0 deletions schemas/imovelweb_anuncios_lancamentos__atualizar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"caracteristicas": [
{
"id": "string",
"idValor": "string",
"nombre": "string",
"valor": "string"
}
],
"claveReferencia": "string",
"codigoAviso": "string",
"descripcion": "string",
"estado": "string",
"etapaDesarrollo": "string",
"fechaEntrega": "string",
"localizacion": {
"codigoPostal": "string",
"direccion": "string",
"idUbicacion": "string",
"latitud": "string",
"longitud": "string",
"muestraMapa": "string",
"ubicacion": "string"
},
"multimedia": {
"imagenes": [
{
"titulo": "string",
"urlImagenOriginal": "string",
"urlImagenPortal": "string"
}
],
"planos": [
{
"titulo": "string",
"urlImagenOriginal": "string",
"urlImagenPortal": "string"
}
],
"recorridos360": [
{
"codigoRecorrido360": "string",
"titulo": "string"
}
],
"videos": [
{
"codigoVideo": "string",
"titulo": "string"
}
]
},
"precios": [
{
"moneda": "string",
"monto": "string",
"operacion": "string"
}
],
"publicacion": {
"fechaOffline": "2020-12-11T19:50:26.489Z",
"fechaOnline": "2020-12-11T19:50:26.489Z",
"tipoDePublicacion": "string"
},
"publicador": {
"codigoInmobiliaria": "string",
"emailAsesor": "string",
"emailDeContacto": "string",
"nombreDeContacto": "string",
"telefonoDeContacto": "string"
},
"tipoDePropiedad": {
"idSubTipo": "string",
"idTipo": "string",
"subTipo": "string",
"tipo": "string"
},
"titulo": "string",
"unidades": [
{
"caracteristicas": [
{
"id": "string",
"idValor": "string",
"nombre": "string",
"valor": "string"
}
],
"claveReferencia": "string",
"codigoAviso": "string",
"descripcion": "string",
"estado": "string",
"localizacion": {
"codigoPostal": "string",
"direccion": "string",
"idUbicacion": "string",
"latitud": "string",
"longitud": "string",
"muestraMapa": "string",
"ubicacion": "string"
},
"multimedia": {
"imagenes": [
{
"titulo": "string",
"urlImagenOriginal": "string",
"urlImagenPortal": "string"
}
],
"planos": [
{
"titulo": "string",
"urlImagenOriginal": "string",
"urlImagenPortal": "string"
}
],
"recorridos360": [
{
"codigoRecorrido360": "string",
"titulo": "string"
}
],
"videos": [
{
"codigoVideo": "string",
"titulo": "string"
}
]
},
"precios": [
{
"moneda": "string",
"monto": "string",
"operacion": "string"
}
],
"publicacion": {
"fechaOffline": "2020-12-11T19:50:26.489Z",
"fechaOnline": "2020-12-11T19:50:26.489Z",
"tipoDePublicacion": "string"
},
"publicador": {
"codigoInmobiliaria": "string",
"emailAsesor": "string",
"emailDeContacto": "string",
"nombreDeContacto": "string",
"telefonoDeContacto": "string"
},
"tipoDePropiedad": {
"idSubTipo": "string",
"idTipo": "string",
"subTipo": "string",
"tipo": "string"
},
"titulo": "string"
}
],
"urlLogo": "string"
}
13 changes: 9 additions & 4 deletions src/Anuncios/Anuncios.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use GuzzleHttp\Exception\ClientException;
use ImovelWeb\Base\Base;

class Anuncios extends Base
final class Anuncios extends Base
{
/**
* Resumo de todos os anúncios online de uma imobiliária.
Expand Down Expand Up @@ -40,7 +40,6 @@ public function remover(string $imobiliaria, string $anuncio): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios//{$anuncio}";

$response = $this->client->request('DELETE', $uri);

return json_decode($response->getBody(), true);
Expand Down Expand Up @@ -84,6 +83,8 @@ public function info(string $imobiliaria, string $anuncio): array
public function atualizar(string $imobiliaria, string $anuncio, array $detalhes = []): array
{
try {
$this->validate(__METHOD__, $detalhes);

$uri = "imobiliarias/{$imobiliaria}/anuncios/{$anuncio}";
$body = ['aviso' => json_encode($detalhes)];

Expand All @@ -93,6 +94,10 @@ public function atualizar(string $imobiliaria, string $anuncio, array $detalhes
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
} catch (\InvalidArgumentException $invalidArgumentException) {
$xml = explode(self::SEPARATOR, $invalidArgumentException->getMessage());

return json_decode(json_encode($xml), true);
}
}
Expand All @@ -101,8 +106,8 @@ public function atualizar(string $imobiliaria, string $anuncio, array $detalhes
* Associa o anúncio a um código do anúncio do integrador.
*
* @param string $imobiliaria
* @param string $anuncio
* @param array $detalhes
* @param string $origem
* @param string $destino
* @return mixed
*/
public function associar(string $imobiliaria, string $origem, string $destino): array
Expand Down
Loading

0 comments on commit f54ca30

Please sign in to comment.