Git Product home page Git Product logo

zenvia-rb's Introduction

Zenvia

Esta biblioteca -não oficial- segue as diretivas da documentação API REST da Zenvia.

Instalação

Adicione esta linha ao seu Gemfile

gem 'zenvia-rb', '~> 0.1.0'

E depois execute:

$ bundle

Ou instale através do "gem install":

$ gem install zenvia-rb

A única dependência desta Gem é o HTTParty.

Uso

Para usar esta biblioteca, você vai precisar informar alguns dados, que são obtidos através da própria Zenvia.

require 'zenvia'
  

Zenvia.configure {|config|
    config.account = 'SUA-CONTA'
    config.code = 'SEU-CODIGO'
    config.from = 'NOME-DA-EMPRESA-OU-PESSOA' # opcional
}

Se você pretende usar esta Gem com Rails, insira o snippet acima em config/initializers.

Feito isso, para enviar uma mensagem, será preciso apenas chamar a função "send_message":

options = {from: config.from, id: 'SEU-ID', schedule: '2017-07-18T02:01:23'}
Zenvia.send_message(number, message, options)
  
# no hash 'options', você ainda pode inserir o aggregateId. Todos esses valores são opcionais  
 
# Exemplo de resposta:
{"sendSmsResponse"=>{"statusCode"=>"00", "statusDescription"=>"Ok", "detailCode"=>"000", "detailDescription"=>"Message Sent"}}

Se preferir, você pode definir um array de números e enviar a mesma mensagem a eles:

numbers = ['DDNNNNNNNNN', 'DDNNNNNNNNM']
Zenvia.send_message(numbers, message)
  

# Exemplo de resposta
 
[
  {"sendSmsResponse"=>{"statusCode"=>"00", "statusDescription"=>"Ok", "detailCode"=>"000", "detailDescription"=>"Message Sent"}}, 
  {"sendSmsResponse"=>{"statusCode"=>"00", "statusDescription"=>"Ok", "detailCode"=>"000", "detailDescription"=>"Message Sent"}}
]

Ou usar a função nativa do Zenvia, de enviar múltiplos SMSs:

list = [
 {
   from: "remetente",
   to: "555192551015",
   msg: "uma mensagem",
   callbackOption: "NONE"
 },
 {
   from: "remetente",
   to: "555199668010",
   schedule: "2014-07-18T02:01:23",
   msg: "outra mensagem",
   callbackOption: "NONE",
   id: "004"
 }
]  
  

Zenvia.send_multiple_messages list

Caso tenha definido o ID no envio de uma mensagem, poderá buscar seu status chamando a função "lookup":

id = 'SEU-ID'  
    
Zenvia.lookup(id)
      

# Exemplo de resposta 
    
{"sendSmsResponse": {"statusCode": "00", "statusDescription": "Ok", "detailCode": "000", "detailDescription": "Message Sent" }}

Isso é tudo, pessoal!

License

The gem is available as open source under the terms of the MIT License.

zenvia-rb's People

Contributors

jefersonhuan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.