totalvoice-ruby 0.0.1.pre.rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e49b91d5e0d7b03db21623428083a0cb9f39c12d
4
+ data.tar.gz: 4ec573167ef4cd3dff6ee8ab7c118b3c64237bcb
5
+ SHA512:
6
+ metadata.gz: 9e7bad81316c033f8f5fefc51cef037c69b77ef71eb51810d0b329e55e030ece136bfacdf6576b73b20b279d368f556dbdff9efe62a34120b379992c7ba17150
7
+ data.tar.gz: 5bd6ddd6671ef2af4157f77b9311b67ec5756687c37deb1a3a90609111aecaea4113ef1b9fc08eaf6fda3faab519978838b60efb2a26ff6c758da95339ccca2d
data/lib/api/audio.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'date'
2
+
3
+ require_relative '../route'
4
+ require_relative '../query'
5
+
6
+ module TotalVoice
7
+ # Inicializa o HTTP client
8
+ class Audio
9
+ attr_reader :client
10
+ ROTA_AUDIO = "/audio"
11
+
12
+ def initialize(client)
13
+ @client = client
14
+ end
15
+
16
+ ##
17
+ # Envia um Audio para numero de destino
18
+ #
19
+ # @param [String] numero_destino
20
+ # @param [String] url_audio
21
+ # @param [Boolean] resposta_usuario
22
+ # @param [String] bina
23
+ # @param [Boolean] gravar_audio
24
+ # @return [json]
25
+ #
26
+ def enviar(numero_destino, url_audio, resposta_usuario = false, bina = nil, gravar_audio = false)
27
+ @client.post(Route.new([ROTA_AUDIO]), {
28
+ numero_destino: numero_destino,
29
+ url_audio: url_audio,
30
+ resposta_usuario: resposta_usuario,
31
+ bina: bina,
32
+ gravar_audio: gravar_audio
33
+ })
34
+ end
35
+
36
+ ##
37
+ # Busca as informações do audio
38
+ #
39
+ # @param [Integer] id
40
+ # @return [json]
41
+ #
42
+ def buscar(id)
43
+ @client.get(Route.new([ROTA_AUDIO, id.to_s]))
44
+ end
45
+
46
+ ##
47
+ # Gera relatório de Audio
48
+ #
49
+ # @param [DateTime|String] data_inicio
50
+ # @param [DateTime|String] data_fim
51
+ # @return [json]
52
+ #
53
+ def relatorio(data_inicio, data_fim)
54
+ @client.get(
55
+ Route.new([ROTA_AUDIO, 'relatorio']),
56
+ Query.new({ 'data_inicio': Time.parse(data_inicio.to_s).utc, 'data_fim': Time.parse(data_fim.to_s).utc })
57
+ )
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,122 @@
1
+ require_relative '../route'
2
+ require_relative '../query'
3
+
4
+ module TotalVoice
5
+ # Inicializa o HTTP client
6
+ class Chamada
7
+ attr_reader :client
8
+ ROTA_CHAMADA = "/chamada"
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Realiza uma chamada telefônica entre dois números: A e B
16
+ #
17
+ # @param [String] numero_origem
18
+ # @param [String] numero_destino
19
+ # @param [Hash] opcoes
20
+ # @return [json]
21
+ #
22
+ def ligar(numero_origem, numero_destino, opcoes = {})
23
+
24
+ data = {
25
+ numero_origem: numero_origem,
26
+ numero_destino: numero_destino
27
+ }
28
+ data.merge!(opcoes)
29
+
30
+ @client.post(Route.new([ROTA_CHAMADA]), data)
31
+ end
32
+
33
+ ##
34
+ # Encerra uma chamada ativa
35
+ #
36
+ # @param [Integer] id
37
+ # @return [json]
38
+ #
39
+ def encerrar(id)
40
+ @client.delete(Route.new([ROTA_CHAMADA, id.to_s]))
41
+ end
42
+
43
+ ##
44
+ # Busca as informações do registro da chamada
45
+ #
46
+ # @param [Integer] id
47
+ # @return [json]
48
+ #
49
+ def buscar(id)
50
+ @client.get(Route.new([ROTA_CHAMADA, id.to_s]))
51
+ end
52
+
53
+ ##
54
+ # Busca as informações do registro da chamada
55
+ #
56
+ # @param [Integer] id
57
+ # @return [json]
58
+ #
59
+ def download_gravacao(id)
60
+ @client.get(Route.new([ROTA_CHAMADA, id.to_s, 'gravacao']))
61
+ end
62
+
63
+ ##
64
+ # Gera relatório de chamadas
65
+ #
66
+ # @param [DateTime|String] data_inicio
67
+ # @param [DateTime|String] data_fim
68
+ # @return [json]
69
+ #
70
+ def relatorio(data_inicio, data_fim)
71
+ @client.get(
72
+ Route.new([ROTA_CHAMADA, 'relatorio']),
73
+ Query.new({ 'data_inicio': Time.parse(data_inicio.to_s).utc, 'data_fim': Time.parse(data_fim.to_s).utc })
74
+ )
75
+ end
76
+
77
+ ##
78
+ # (Beta) Escuta uma chamada ativa
79
+ #
80
+ # @param [Integer] id
81
+ # @param [String] numero
82
+ # @param [Integer] modo
83
+ # @return [json]
84
+ #
85
+ def escutar(id, numero, modo)
86
+ @client.post(Route.new([ROTA_CHAMADA, id.to_s, 'escuta']), {
87
+ numero: numero,
88
+ modo: modo
89
+ })
90
+ end
91
+
92
+ ##
93
+ # (Beta) Faz uma transferência da chamada atual
94
+ #
95
+ # @param [Integer] id
96
+ # @param [String] numero
97
+ # @param [String] perna
98
+ # @return [json]
99
+ #
100
+ def transferir(id, numero, perna)
101
+ @client.post(Route.new([ROTA_CHAMADA, id.to_s, 'transfer']), {
102
+ numero: numero,
103
+ perna: perna
104
+ })
105
+ end
106
+
107
+ ##
108
+ # Avalia uma Chamada com nota de 1 a 5
109
+ #
110
+ # @param [Integer] id
111
+ # @param [String] nota
112
+ # @param [String] comentario
113
+ # @return [json]
114
+ #
115
+ def avaliar(id, nota, comentario = nil)
116
+ @client.post(Route.new([ROTA_CHAMADA, id.to_s, 'avaliar']), {
117
+ nota: nota,
118
+ comentario: comentario
119
+ })
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,56 @@
1
+ require_relative '../route'
2
+ require_relative '../query'
3
+
4
+ module TotalVoice
5
+ # Inicializa o HTTP client
6
+ class Composto
7
+ attr_reader :client
8
+ ROTA_COMPOSTO = "/composto"
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Envia um composto para um número destino
16
+ #
17
+ # @param [String] numero_destino
18
+ # @param [Hash] dados
19
+ # @param [String] bina
20
+ # @param [String] tags
21
+ # @return [json]
22
+ #
23
+ def enviar(numero_destino, dados, bina = nil, tags = nil)
24
+ @client.post(Route.new([ROTA_COMPOSTO]), {
25
+ numero_destino: numero_destino,
26
+ bina: bina,
27
+ tags: tags,
28
+ dados: dados
29
+ })
30
+ end
31
+
32
+ ##
33
+ # Busca um composto pelo seu ID
34
+ #
35
+ # @param [Integer] id
36
+ # @return [json]
37
+ #
38
+ def buscar(id)
39
+ @client.get(Route.new([ROTA_COMPOSTO, id.to_s]))
40
+ end
41
+
42
+ ##
43
+ # Relatório do Composto
44
+ #
45
+ # @param [DateTime|String] data_inicio
46
+ # @param [DateTime|String] data_fim
47
+ # @return [json]
48
+ #
49
+ def relatorio(data_inicio, data_fim)
50
+ @client.get(
51
+ Route.new([ROTA_COMPOSTO, 'relatorio']),
52
+ Query.new({ 'data_inicio': Time.parse(data_inicio.to_s).utc, 'data_fim': Time.parse(data_fim.to_s).utc })
53
+ )
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../route'
2
+
3
+ module TotalVoice
4
+ # Inicializa o HTTP client
5
+ class Conferencia
6
+ attr_reader :client
7
+ ROTA_CONFERENCIA = "/conferencia"
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ ##
14
+ # Cria uma conferência
15
+ #
16
+ # @return [json]
17
+ #
18
+ def criar()
19
+ @client.post(Route.new([ROTA_CONFERENCIA]), {})
20
+ end
21
+
22
+ ##
23
+ # Envia um audio para um número destino
24
+ #
25
+ # @param [Integer] id
26
+ # @param [String] numero
27
+ # @param [String] bina
28
+ # @param [Boolean] gravar_audio
29
+ # @return [json]
30
+ #
31
+ def add_numero_conferencia(id, numero, bina = nil, gravar_audio = false)
32
+ @client.post(Route.new([ROTA_CONFERENCIA, id.to_s]), {
33
+ numero: numero,
34
+ bina: bina,
35
+ gravar_audio: gravar_audio
36
+ })
37
+ end
38
+
39
+ ##
40
+ # Busca um composto pelo seu ID
41
+ #
42
+ # @param [Integer] id
43
+ # @return [json]
44
+ #
45
+ def buscar(id)
46
+ @client.get(Route.new([ROTA_CONFERENCIA, id.to_s]))
47
+ end
48
+
49
+ ##
50
+ # Remove uma conferência ativa
51
+ #
52
+ # @param [Integer] id
53
+ # @return [json]
54
+ #
55
+ def excluir(id)
56
+ @client.delete(Route.new([ROTA_CONFERENCIA, id.to_s]))
57
+ end
58
+ end
59
+ end
data/lib/api/conta.rb ADDED
@@ -0,0 +1,62 @@
1
+ require_relative '../route'
2
+
3
+ module TotalVoice
4
+ # Inicializa o HTTP client
5
+ class Conta
6
+ attr_reader :client
7
+ ROTA_CONTA = "/conta"
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ ##
14
+ # Cria uma conferência
15
+ #
16
+ # @param [Hash] data
17
+ # @return [json]
18
+ #
19
+ def criar(data)
20
+ @client.post(Route.new([ROTA_CONTA]), data)
21
+ end
22
+
23
+ ##
24
+ # Atualiza os dados da conta
25
+ #
26
+ # @param [Integer] id
27
+ # @param [Hash] data
28
+ # @return [json]
29
+ #
30
+ def atualizar(id, data)
31
+ @client.put(Route.new([ROTA_CONTA, id.to_s]), data)
32
+ end
33
+
34
+ ##
35
+ # Busca os dados da Conta
36
+ #
37
+ # @param [Integer] id
38
+ # @return [json]
39
+ #
40
+ def buscar(id)
41
+ @client.get(Route.new([ROTA_CONTA, id.to_s]))
42
+ end
43
+
44
+ ##
45
+ # Remove uma Conta
46
+ #
47
+ # @param [Integer] id
48
+ # @return [json]
49
+ #
50
+ def excluir(id)
51
+ @client.delete(Route.new([ROTA_CONTA, id.to_s]))
52
+ end
53
+
54
+ ##
55
+ # Lista contas criadas por mim
56
+ # @return [json]
57
+ #
58
+ def relatorio()
59
+ @client.get(Route.new([ROTA_CONTA, 'relatorio']))
60
+ end
61
+ end
62
+ end
data/lib/api/did.rb ADDED
@@ -0,0 +1,78 @@
1
+ require_relative '../route'
2
+
3
+ module TotalVoice
4
+ # Inicializa o HTTP client
5
+ class Did
6
+ attr_reader :client
7
+ ROTA_DID = "/did"
8
+ ROTA_DID_ESTOQUE = "/did/estoque"
9
+ ROTA_DID_CHAMADA = "/did/chamada"
10
+
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+
15
+ ##
16
+ # Lista todos os dids pertencentes
17
+ #
18
+ # @return [json]
19
+ #
20
+ def listar()
21
+ @client.get(Route.new([ROTA_DID]))
22
+ end
23
+
24
+ ##
25
+ # Remove uma Conta
26
+ #
27
+ # @param [Integer] id
28
+ # @return [json]
29
+ #
30
+ def excluir(id)
31
+ @client.delete(Route.new([ROTA_DID, id.to_s]))
32
+ end
33
+
34
+ ##
35
+ # Atualiza um did
36
+ #
37
+ # @param [Integer] id
38
+ # @param [Integer] ramal_id
39
+ # @param [Integer] ura_id
40
+ # @return [json]
41
+ #
42
+ def atualizar(id, ramal_id, ura_id)
43
+ @client.put(Route.new([ROTA_DID, id.to_s]), {
44
+ ramal_id: ramal_id,
45
+ ura_id: ura_id
46
+ })
47
+ end
48
+
49
+ ##
50
+ # Lista todos os dids disponiveis
51
+ #
52
+ # @return [json]
53
+ #
54
+ def lista_estoque()
55
+ @client.get(Route.new([ROTA_DID_ESTOQUE]))
56
+ end
57
+
58
+ ##
59
+ # Lista todos os dids disponiveis
60
+ #
61
+ # @param [Integer] id
62
+ # @return [json]
63
+ #
64
+ def adquirir(id)
65
+ @client.post(Route.new([ROTA_DID_ESTOQUE, id.to_s]))
66
+ end
67
+
68
+ ##
69
+ # Busca uma chamada recebida pelo seu ID
70
+ #
71
+ # @param [Integer] id
72
+ # @return [json]
73
+ #
74
+ def busca_chamada_recebida(id)
75
+ @client.get(Route.new([ROTA_DID_CHAMADA, id.to_s]))
76
+ end
77
+ end
78
+ end
data/lib/api/perfil.rb ADDED
@@ -0,0 +1,95 @@
1
+ require_relative '../route'
2
+ require_relative '../query'
3
+
4
+ module TotalVoice
5
+ # Inicializa o HTTP client
6
+ class Perfil
7
+ attr_reader :client
8
+ ROTA_SALDO = "/saldo"
9
+ ROTA_PERFIL = "/conta"
10
+ ROTA_WEBHOOK = "/webhook"
11
+
12
+ def initialize(client)
13
+ @client = client
14
+ end
15
+
16
+ ##
17
+ # Consulta saldo atual
18
+ # @return [json]
19
+ #
20
+ def consulta_saldo()
21
+ @client.get(Route.new([ROTA_SALDO]))
22
+ end
23
+
24
+ ##
25
+ # Leitura dos dados da minha conta
26
+ # @return [json]
27
+ #
28
+ def minha_conta()
29
+ @client.get(Route.new([ROTA_PERFIL]))
30
+ end
31
+
32
+ ##
33
+ # Atualiza os dados da minha conta
34
+ # @param [Hash] data
35
+ # @return [json]
36
+ #
37
+ def atualizar(data)
38
+ @client.put(Route.new([ROTA_PERFIL]), data)
39
+ end
40
+
41
+ ##
42
+ # Busca as informações do registro da chamada
43
+ #
44
+ # @param [Integer] id
45
+ # @return [json]
46
+ #
47
+ def relatorio_recarga()
48
+ @client.get(Route.new([ROTA_PERFIL, 'recargas']))
49
+ end
50
+
51
+ ##
52
+ # Gera uma URL para recarga de créditos
53
+ #
54
+ # @param [String] url
55
+ # @return [json]
56
+ #
57
+ def url_recarga(url)
58
+ @client.get(
59
+ Route.new([ROTA_PERFIL, 'urlrecarga']),
60
+ Query.new({ 'url_retorno': url })
61
+ )
62
+ end
63
+
64
+ ##
65
+ # Retorna a lista de webhooks configurados para esta conta
66
+ # @return [json]
67
+ #
68
+ def webhooks()
69
+ @client.get(Route.new([ROTA_WEBHOOK]))
70
+ end
71
+
72
+ ##
73
+ # Apaga um webhook
74
+ #
75
+ # @param [String] nome
76
+ # @return [json]
77
+ #
78
+ def excluir_webhook(nome)
79
+ @client.delete(Route.new([ROTA_WEBHOOK, nome]))
80
+ end
81
+
82
+ ##
83
+ # Cadastra ou atualiza um webhook
84
+ #
85
+ # @param [String] nome
86
+ # @param [String] url
87
+ # @return [json]
88
+ #
89
+ def salva_webhook(nome, url)
90
+ @client.put(Route.new([ROTA_WEBHOOK, nome]), {
91
+ url: url
92
+ })
93
+ end
94
+ end
95
+ end
data/lib/api/ramal.rb ADDED
@@ -0,0 +1,69 @@
1
+ require_relative '../route'
2
+ require_relative '../query'
3
+
4
+ module TotalVoice
5
+ # Inicializa o HTTP client
6
+ class Ramal
7
+ attr_reader :client
8
+ ROTA_RAMAL = "/ramal"
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Cria um novo ramal
16
+ #
17
+ # @param [Hash] data
18
+ # @return [json]
19
+ #
20
+ def criar(data)
21
+ @client.post(Route.new([ROTA_RAMAL]), data)
22
+ end
23
+
24
+ ##
25
+ # Remove um ramal
26
+ #
27
+ # @param [Integer] id
28
+ # @return [json]
29
+ #
30
+ def excluir(id)
31
+ @client.delete(Route.new([ROTA_RAMAL, id.to_s]))
32
+ end
33
+
34
+ ##
35
+ # Busca as informações do registro do ramal
36
+ #
37
+ # @param [Integer] id
38
+ # @return [json]
39
+ #
40
+ def buscar(id)
41
+ @client.get(Route.new([ROTA_RAMAL, id.to_s]))
42
+ end
43
+
44
+ ##
45
+ # Atualiza as informações do Ramal
46
+ #
47
+ # @param [Integer] id
48
+ # @param [Hash] data
49
+ # @return [json]
50
+ #
51
+ def atualizar(id, data)
52
+ @client.put(Route.new([ROTA_RAMAL, id.to_s]), data)
53
+ end
54
+
55
+ ##
56
+ # Gera relatório de ramais criados
57
+ #
58
+ # @param [DateTime|String] data_inicio
59
+ # @param [DateTime|String] data_fim
60
+ # @return [json]
61
+ #
62
+ def relatorio(data_inicio, data_fim)
63
+ @client.get(
64
+ Route.new([ROTA_RAMAL, 'relatorio']),
65
+ Query.new({ 'data_inicio': Time.parse(data_inicio.to_s).utc, 'data_fim': Time.parse(data_fim.to_s).utc })
66
+ )
67
+ end
68
+ end
69
+ end
data/lib/api/sms.rb ADDED
@@ -0,0 +1,58 @@
1
+ require_relative '../route'
2
+ require_relative '../query'
3
+
4
+ module TotalVoice
5
+ # Inicializa o HTTP client
6
+ class Sms
7
+ attr_reader :client
8
+ ROTA_SMS = "/sms"
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Enviar SMS
16
+ #
17
+ # @param [String] numero_destino
18
+ # @param [String] mensagem
19
+ # @param [Boolean] resposta_usuario
20
+ # @param [Boolean] multi_sms
21
+ # @param [DateTime|String] data_criacao
22
+ # @return [json]
23
+ #
24
+ def enviar(numero_destino, mensagem, resposta_usuario = false, multi_sms = false, data_criacao = nil)
25
+ @client.post(Route.new([ROTA_SMS]), {
26
+ numero_destino: numero_destino,
27
+ mensagem: mensagem,
28
+ resposta_usuario: resposta_usuario,
29
+ multi_sms: multi_sms,
30
+ data_criacao: data_criacao != nil ? Time.parse(data_criacao.to_s).utc : nil
31
+ })
32
+ end
33
+
34
+ ##
35
+ # Busca as informações do registro de SMS
36
+ #
37
+ # @param [Integer] id
38
+ # @return [json]
39
+ #
40
+ def buscar(id)
41
+ @client.get(Route.new([ROTA_SMS, id.to_s]))
42
+ end
43
+
44
+ ##
45
+ # Gera relatório de SMS
46
+ #
47
+ # @param [DateTime|String] data_inicio
48
+ # @param [DateTime|String] data_fim
49
+ # @return [json]
50
+ #
51
+ def relatorio(data_inicio, data_fim)
52
+ @client.get(
53
+ Route.new([ROTA_SMS, 'relatorio']),
54
+ Query.new({ 'data_inicio': Time.parse(data_inicio.to_s).utc, 'data_fim': Time.parse(data_fim.to_s).utc })
55
+ )
56
+ end
57
+ end
58
+ end
data/lib/api/tts.rb ADDED
@@ -0,0 +1,55 @@
1
+ require_relative '../route'
2
+ require_relative '../query'
3
+
4
+ module TotalVoice
5
+ # Inicializa o HTTP client
6
+ class Tts
7
+ attr_reader :client
8
+ ROTA_TTS = "/tts"
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Enviar TTS
16
+ #
17
+ # @param [String] numero_destino
18
+ # @param [String] mensagem
19
+ # @param [Hash] opcoes
20
+ # @return [json]
21
+ #
22
+ def enviar(numero_destino, mensagem, opcoes = {})
23
+ data = {
24
+ numero_destino: numero_destino,
25
+ mensagem: mensagem
26
+ }
27
+ data.merge!(opcoes)
28
+ @client.post(Route.new([ROTA_TTS]), data)
29
+ end
30
+
31
+ ##
32
+ # Busca as informações do registro de TTS
33
+ #
34
+ # @param [Integer] id
35
+ # @return [json]
36
+ #
37
+ def buscar(id)
38
+ @client.get(Route.new([ROTA_TTS, id.to_s]))
39
+ end
40
+
41
+ ##
42
+ # Gera relatório de TTS
43
+ #
44
+ # @param [DateTime|String] data_inicio
45
+ # @param [DateTime|String] data_fim
46
+ # @return [json]
47
+ #
48
+ def relatorio(data_inicio, data_fim)
49
+ @client.get(
50
+ Route.new([ROTA_TTS, 'relatorio']),
51
+ Query.new({ 'data_inicio': Time.parse(data_inicio.to_s).utc, 'data_fim': Time.parse(data_fim.to_s).utc })
52
+ )
53
+ end
54
+ end
55
+ end
data/lib/api/ura.rb ADDED
@@ -0,0 +1,49 @@
1
+ require_relative '../route'
2
+ require_relative '../query'
3
+
4
+ module TotalVoice
5
+ # Inicializa o HTTP client
6
+ class Ura
7
+ attr_reader :client
8
+ ROTA_URA = "/ura"
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ ##
15
+ # Cria um nova URA
16
+ #
17
+ # @param [String] nome
18
+ # @param [Hash] data
19
+ # @return [json]
20
+ #
21
+ def criar(nome, data)
22
+ @client.post(Route.new([ROTA_URA]), {
23
+ nome: nome,
24
+ dados: data
25
+ })
26
+ end
27
+
28
+ ##
29
+ # Remove uma Ura
30
+ #
31
+ # @param [Integer] id
32
+ # @return [json]
33
+ #
34
+ def excluir(id)
35
+ @client.delete(Route.new([ROTA_URA, id.to_s]))
36
+ end
37
+
38
+ ##
39
+ # Atualiza uma ura
40
+ #
41
+ # @param [Integer] id
42
+ # @param [Hash] data
43
+ # @return [json]
44
+ #
45
+ def atualizar(id, data)
46
+ @client.put(Route.new([ROTA_URA, id.to_s]), data)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../route'
2
+
3
+ module TotalVoice
4
+ # Inicializa o HTTP client
5
+ class Webphone
6
+ attr_reader :client
7
+ ROTA_WEBPHONE = "/webphone"
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ ##
14
+ # Requisita a URL do webphone de um ramal
15
+ #
16
+ # @param [Hash] data
17
+ # @return [json]
18
+ #
19
+ def url(data)
20
+ @client.get(Route.new([ROTA_WEBPHONE]), data)
21
+ end
22
+ end
23
+ end
data/lib/client.rb ADDED
@@ -0,0 +1,156 @@
1
+ require 'httparty'
2
+
3
+ require_relative 'query'
4
+ require_relative 'api/audio'
5
+ require_relative 'api/chamada'
6
+ require_relative 'api/composto'
7
+ require_relative 'api/conferencia'
8
+ require_relative 'api/conta'
9
+ require_relative 'api/did'
10
+ require_relative 'api/perfil'
11
+ require_relative 'api/ramal'
12
+ require_relative 'api/sms'
13
+ require_relative 'api/tts'
14
+ require_relative 'api/ura'
15
+ require_relative 'api/webphone'
16
+
17
+
18
+ module TotalVoice
19
+ # Inicializa o HTTP client
20
+ class API
21
+ include HTTParty
22
+ ENDPOINT = 'https://api2.totalvoice.com.br'
23
+ # * *Args* :
24
+ # - +Access-Token+ -> Access-Token TotalVoice
25
+ # - +host+ -> Base URL para API
26
+ #
27
+ def initialize(access_token, host = nil)
28
+ @access_token = access_token
29
+ @host = host ? host : ENDPOINT
30
+ @options = {
31
+ headers: {
32
+ "Access-Token" => @access_token,
33
+ "Accept" => "application/json"
34
+ }
35
+ }
36
+
37
+ @audio = nil
38
+ @chamada = nil
39
+ @conta = nil
40
+ @composto = nil
41
+ @conferencia = nil
42
+ @did = nil
43
+ @perfil = nil
44
+ @ramal = nil
45
+ @sms = nil
46
+ @tts = nil
47
+ @ura = nil
48
+ @webphone = nil
49
+ end
50
+
51
+ def audio
52
+ @audio ||= Audio.new self
53
+ end
54
+
55
+ def chamada
56
+ @chamada ||= Chamada.new self
57
+ end
58
+
59
+ def composto
60
+ @composto ||= Composto.new self
61
+ end
62
+
63
+ def conferencia
64
+ @conferencia ||= Conferencia.new self
65
+ end
66
+
67
+ def conta
68
+ @conta ||= Conta.new self
69
+ end
70
+
71
+ def did
72
+ @did ||= Did.new self
73
+ end
74
+
75
+ def perfil
76
+ @perfil ||= Perfil.new self
77
+ end
78
+
79
+ def ramal
80
+ @ramal ||= Ramal.new self
81
+ end
82
+
83
+ def sms
84
+ @sms ||= Sms.new self
85
+ end
86
+
87
+ def tts
88
+ @tts ||= Tts.new self
89
+ end
90
+
91
+ def ura
92
+ @ura ||= Ura.new self
93
+ end
94
+
95
+ def webphone
96
+ @webphone ||= Webphone.new self
97
+ end
98
+
99
+ #
100
+ # GET HTTP Method
101
+ #
102
+ # @param [Route] route
103
+ # @param [Query] query
104
+ # @return [json]
105
+ #
106
+ def get(route, query = nil)
107
+
108
+ url = @host + route.build()
109
+ if(query.instance_of?(Query))
110
+ url = url + query.to_query()
111
+ end
112
+
113
+ self.class.get(url, @options);
114
+ end
115
+
116
+ #
117
+ # POST HTTP Method
118
+ #
119
+ # @param [Route] route
120
+ # @param [Hash] params
121
+ # @return [json]
122
+ #
123
+ def post(route, params)
124
+ data = {
125
+ body: params
126
+ }
127
+ @options.merge!(data)
128
+ self.class.post(@host + route.build(), @options);
129
+ end
130
+
131
+ #
132
+ # PUT HTTP Method
133
+ #
134
+ # @param [Route] route
135
+ # @param [Hash] params
136
+ # @return [json]
137
+ #
138
+ def put(route, params)
139
+ data = {
140
+ body: params
141
+ }
142
+ @options.merge!(data)
143
+ self.class.put(@host + route.build(), @options);
144
+ end
145
+
146
+ #
147
+ # DELETE HTTP Method
148
+ #
149
+ # @param [Route] route
150
+ # @return [json]
151
+ #
152
+ def delete(route)
153
+ self.class.delete(@host + route.build(), @options);
154
+ end
155
+ end
156
+ end
data/lib/query.rb ADDED
@@ -0,0 +1,20 @@
1
+ module TotalVoice
2
+
3
+ class Query
4
+ # * *Args* :
5
+ # - +values+ -> Array com valores para montar a Query String
6
+ #
7
+ def initialize(values)
8
+ @values = values
9
+ end
10
+
11
+ #
12
+ # Monta a Query String
13
+ #
14
+ def to_query()
15
+ @query = "?" + @values.map{|k,v| "#{k}=#{v}"}.join('&')
16
+ end
17
+
18
+ end
19
+
20
+ end
data/lib/route.rb ADDED
@@ -0,0 +1,20 @@
1
+ module TotalVoice
2
+
3
+ class Route
4
+ # * *Args* :
5
+ # - +paths+ -> Array com valores para montar a rota
6
+ #
7
+ def initialize(paths)
8
+ @paths = paths
9
+ end
10
+
11
+ #
12
+ # Monta a URL de acordo com os parâmetros
13
+ #
14
+ def build()
15
+ @paths.join("/")
16
+ end
17
+
18
+ end
19
+
20
+ end
data/lib/totalvoice.rb ADDED
@@ -0,0 +1,3 @@
1
+ module TotalVoice
2
+ VERSION = '0.0.1-rc'
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: totalvoice-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.rc
5
+ platform: ruby
6
+ authors:
7
+ - DiloWagner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.16.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.16.2
27
+ description: Client Official API TotalVoice
28
+ email: dx@sendgrid.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/api/audio.rb
34
+ - lib/api/chamada.rb
35
+ - lib/api/composto.rb
36
+ - lib/api/conferencia.rb
37
+ - lib/api/conta.rb
38
+ - lib/api/did.rb
39
+ - lib/api/perfil.rb
40
+ - lib/api/ramal.rb
41
+ - lib/api/sms.rb
42
+ - lib/api/tts.rb
43
+ - lib/api/ura.rb
44
+ - lib/api/webphone.rb
45
+ - lib/client.rb
46
+ - lib/query.rb
47
+ - lib/route.rb
48
+ - lib/totalvoice.rb
49
+ homepage: http://github.com/totalvoice/totalvoice-ruby
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.4'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">"
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.1
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.6.14.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Official TotalVoice Gem
73
+ test_files: []