Class: TotalVoice::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/client.rb

Overview

Inicializa o HTTP client

Constant Summary collapse

ENDPOINT =
'https://api2.totalvoice.com.br'

Instance Method Summary collapse

Constructor Details

#initialize(access_token, host = nil) ⇒ API

  • Args :

    • Access-Token -> Access-Token TotalVoice

    • host -> Base URL para API


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/client.rb', line 32

def initialize(access_token, host = nil)
  @access_token     = access_token
  @host             = host ? host : ENDPOINT
  @options = {
    headers: {
      "Access-Token" => @access_token,
      "Content-Type" => "application/json",
      "Accept" => "application/json"
    }
  }

  @audio = nil
  @bina = nil
  @fila = nil
  @chamada = nil
  @conta = nil
  @composto = nil
  @conferencia = nil
  @did = nil
  @perfil = nil
  @ramal = nil
  @sms = nil
  @tts = nil
  @ura = nil
  @webphone = nil
  @valida_numero = nil
  @verificacao = nil
end

Instance Method Details

#audioObject


61
62
63
# File 'lib/client.rb', line 61

def audio
    @audio ||= Audio.new self
end

#binaObject


65
66
67
# File 'lib/client.rb', line 65

def bina
    @bina ||= Bina.new self
end

#chamadaObject


73
74
75
# File 'lib/client.rb', line 73

def chamada
    @chamada ||= Chamada.new self
end

#compostoObject


77
78
79
# File 'lib/client.rb', line 77

def composto
    @composto ||= Composto.new self
end

#conferenciaObject


81
82
83
# File 'lib/client.rb', line 81

def conferencia
    @conferencia ||= Conferencia.new self
end

#contaObject


85
86
87
# File 'lib/client.rb', line 85

def conta
    @conta ||= Conta.new self
end

#delete(route) ⇒ json

DELETE HTTP Method

Parameters:

Returns:

  • (json)

177
178
179
# File 'lib/client.rb', line 177

def delete(route)
  self.class.delete(@host + route.build(), @options);
end

#didObject


89
90
91
# File 'lib/client.rb', line 89

def did
    @did ||= Did.new self
end

#filaObject


69
70
71
# File 'lib/client.rb', line 69

def fila
    @fila ||= Fila.new self
end

#get(route, query = nil) ⇒ json

GET HTTP Method

Parameters:

Returns:

  • (json)

131
132
133
134
135
136
137
138
139
# File 'lib/client.rb', line 131

def get(route, query = nil)

  url = @host + route.build()
  if(query.instance_of?(Query))
    url = url + query.to_query()
  end

  self.class.get(url, @options);
end

#perfilObject


93
94
95
# File 'lib/client.rb', line 93

def perfil
    @perfil ||= Perfil.new self
end

#post(route, params) ⇒ json

POST HTTP Method

Parameters:

  • route (Route)
  • params (Hash)

Returns:

  • (json)

148
149
150
151
152
153
154
# File 'lib/client.rb', line 148

def post(route, params)
  data = {
    body: params.to_json
  }
  @options.merge!(data)
  self.class.post(@host + route.build(), @options);
end

#put(route, params) ⇒ json

PUT HTTP Method

Parameters:

  • route (Route)
  • params (Hash)

Returns:

  • (json)

163
164
165
166
167
168
169
# File 'lib/client.rb', line 163

def put(route, params)
  data = {
    body: params.to_json
  }
  @options.merge!(data)
  self.class.put(@host + route.build(), @options);
end

#ramalObject


97
98
99
# File 'lib/client.rb', line 97

def ramal
    @ramal ||= Ramal.new self
end

#smsObject


101
102
103
# File 'lib/client.rb', line 101

def sms
    @sms ||= Sms.new self
end

#ttsObject


105
106
107
# File 'lib/client.rb', line 105

def tts
    @tts ||= Tts.new self
end

#uraObject


109
110
111
# File 'lib/client.rb', line 109

def ura
    @ura ||= Ura.new self
end

#valida_numeroObject


117
118
119
# File 'lib/client.rb', line 117

def valida_numero
  @valida_numero ||= ValidaNumero.new self
end

#verificacaoObject


121
122
123
# File 'lib/client.rb', line 121

def verificacao
  @verificacao ||= Verificacao.new self
end

#webphoneObject


113
114
115
# File 'lib/client.rb', line 113

def webphone
    @webphone ||= Webphone.new self
end