Skip to content

Commit

Permalink
alterar e deletar
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigomsdevs committed Jul 1, 2021
1 parent a8e98c3 commit c8ef196
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
18 changes: 15 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ const b2w = require('./b2w');
const variacao = require('./b2w_variacao');

var teste = new b2w();


var variacoes = new variacao();

teste.setName('Teste Integracao ' + Date.now());
teste.setSku(Date.now());
teste.setName('Teste Alteracao do Produto');
teste.setSku("1625164865889");
teste.setDescricao('Descricao top');
teste.setPreco('46');
teste.setPrecoPromocional('30');
Expand Down Expand Up @@ -75,4 +77,14 @@ variacoes.addVariacao("SKUP", 10, "", [
teste.setProdutoComVariacao(true);
teste.setVariavoes(variacoes.retornaVariacoes());

teste.enviarProduto();
//deleta
teste.enviarRequisicao('DELETE');

//altera
//teste.enviarRequisicao('PUT');


//cria
//teste.enviarRequisicao('POST');


17 changes: 13 additions & 4 deletions b2w.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,25 @@ class b2w {
};
}

enviarProduto() {
enviarRequisicao(methodRe) {

var urlApi;

if (methodRe == 'POST') {
urlApi = `https://api.skyhub.com.br/products`;
} else {
urlApi = `https://api.skyhub.com.br/products/${this.sku}`;
}

request({
url: "https://api.skyhub.com.br/products",
method: "POST",
url: urlApi,
method: methodRe,
headers: this.preparaHeaders(),
json: true,
body: this.preparaArrayProduto()
}, function (error, response, body) {
if (response.statusCode == 201 || response.statusCode == 200 || response.statusCode == 204) {
console.log('Produto adicionado com sucesso!');
console.log('Executado com sucesso!');
} else {
console.log('Error => ' + JSON.stringify(body));
}
Expand Down
29 changes: 0 additions & 29 deletions b2w_variacao.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,6 @@ class b2w_variacao {
}


/*[
{
"sku": "F21",
"qty": 10,
"ean": "9876543210987",
"images": [
"http://d26lpennugtm8s.cloudfront.net/stores/154/284/products/camiseta-lisa-verde-bandeira-algodo-p-ao-gg-pronta-entrega-355901-mlb20431777049_092015-o-07fadec89e5ed54705c1b9ab5411dec8-1024-1024.jpg"
],
"specifications": [
{
"key": "Cor",
"value": "Verde"
},
{
"key": "Tamanho",
"value": "M"
},
{
"key": "price",
"value": "50.00"
},
{
"key": "promotional_price",
"value": "40.00"
}
]
}
]*/

}

module.exports = b2w_variacao;

0 comments on commit c8ef196

Please sign in to comment.