-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bidirectional call/sms send #18
base: master
Are you sure you want to change the base?
Conversation
Parece uma feature legal! Só precisamos adaptar o coding-style:
Obrigado! ❤️ |
src/cli.js
Outdated
@@ -34,6 +51,10 @@ cli(yargs | |||
describe: 'Se definido, será enviado um SMS ao invés de uma chamada', | |||
type: 'boolean' | |||
}) | |||
.option('bidirecional', { | |||
describe: 'Defini se a chamada deve ser enviada para ambos os números', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sugestão de descrição: Se definido, realiza uma nova ligação, desta vez com o de/para invertidos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Defini -> Define
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/cli.js
Outdated
var temp = args.de; | ||
args.de = args.para; | ||
args.para = temp; | ||
send(args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sugestão de código utilizando ES6:
send(args);
let { de: para, para: de } = args;
send({...args, de, para});
É importante ressalvar que send()
é assíncrono. Eu não sei como a API se comportaria com duas chamadas simultâneas. Talvez fosse bacana você encadear a promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pela minha configuração do linter atual, até o let
vai ser barrado. Ele vai permitir somente const
, e vai bloquear reatribuição/mutabilidade (paradigma funcional).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O ideal também é que a lógica aconteça dentro do gemidao.js
, que é onde lida com os argumentos. O cli.js
só despacha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opa, bem lembrado, @haskellcamargo. Nem cheguei a ler as configs do Lint ainda.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ele tá barrando let
, var
, try
, for
e while
, pelo que lembro.
Vou testar a branch na prática a branch ao chegar em casa para poder mesclar! |
@haskellcamargo quando eu chegar em casa vou dar uma melhorada, passar a usar promises. Mas se quiser ir aceitando o PR já pode, posso abrir outro em breve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
src/cli.js
Outdated
if (args.bidirecional) { | ||
send(args); | ||
const temp = args.de; | ||
args.de = args.para; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não querendo ser muito chato, mas já sendo, esse pedacinho que vc faz o swap, da pra dar uma melhoradinha, não? rsrs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu usaria o ramda
:
const swapValues = (key1, key2, obj) => pipe(
assoc(key1, obj[key2]),
assoc(key2, obj[key1]))
(obj);
// ...
if (args.bidirecional) {
send(args);
send(swapValues('de', 'para', args))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Achei elegante
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolvi desacoplando os dados da msg, isso possibilita modificar o padrão from/to e fazer outra chamada send após gerar a call invertendo os valores, o que vocês acham @williamokano @cuchi?
src/cli.js
Outdated
if (args.bidirecional) { | ||
send(args); | ||
const temp = args.de; | ||
args.de = args.para; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu usaria o ramda
:
const swapValues = (key1, key2, obj) => pipe(
assoc(key1, obj[key2]),
assoc(key2, obj[key1]))
(obj);
// ...
if (args.bidirecional) {
send(args);
send(swapValues('de', 'para', args))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PT BR?
.send(msg_data(from, to)); | ||
|
||
function msg_data(from, to) { | ||
return { | ||
numero_destino: to, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deixa as variáveis em inglês. E bina é o sistema de identificação, não sei se seria o melhor nome para deixar o from, prefiro os nomes originais from
e to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@williamokano eu mantive o que vinha sendo feito porque isso é a estrutura de dados que o endpoint recebe, os nomes dos parâmetros foram mantidos também, só fiz desacoplar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@walteraa numero_destino e bina já existiam?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, viajei aqui, talvez sejam requisitos para enviar a totalvoice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sim, são os dados recebidos pelo totalvoice, segundo a doc deles(https://api2.totalvoice.com.br/doc/#!/Composto/post_composto)
Não gostou da minha ideia? 😢 |
Sim @cuchi, mas desacoplar os dados e usar promises "seems better"! |
Puts @walteraa ! |
Adiciona a flag
--bidirecional
para fazer chamada para ambos os números.gemidao-do-zap --de=x --para=y --token=t --bidirecional
Resolve a issue #16