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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/client.rb', line 29

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
  @chamada = nil
  @conta = nil
  @composto = nil
  @conferencia = nil
  @did = nil
  @perfil = nil
  @ramal = nil
  @sms = nil
  @tts = nil
  @ura = nil
  @webphone = nil
end

Instance Method Details

#audioObject



55
56
57
# File 'lib/client.rb', line 55

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

#binaObject



59
60
61
# File 'lib/client.rb', line 59

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

#chamadaObject



63
64
65
# File 'lib/client.rb', line 63

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

#compostoObject



67
68
69
# File 'lib/client.rb', line 67

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

#conferenciaObject



71
72
73
# File 'lib/client.rb', line 71

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

#contaObject



75
76
77
# File 'lib/client.rb', line 75

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

#delete(route) ⇒ json

DELETE HTTP Method

Parameters:

Returns:

  • (json)


160
161
162
# File 'lib/client.rb', line 160

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

#didObject



79
80
81
# File 'lib/client.rb', line 79

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

#get(route, query = nil) ⇒ json

GET HTTP Method

Parameters:

Returns:

  • (json)


114
115
116
117
118
119
120
121
122
# File 'lib/client.rb', line 114

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



83
84
85
# File 'lib/client.rb', line 83

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

#post(route, params) ⇒ json

POST HTTP Method

Parameters:

  • route (Route)
  • params (Hash)

Returns:

  • (json)


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

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)


146
147
148
149
150
151
152
# File 'lib/client.rb', line 146

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

#ramalObject



87
88
89
# File 'lib/client.rb', line 87

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

#smsObject



91
92
93
# File 'lib/client.rb', line 91

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

#ttsObject



95
96
97
# File 'lib/client.rb', line 95

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

#uraObject



99
100
101
# File 'lib/client.rb', line 99

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

#webphoneObject



103
104
105
# File 'lib/client.rb', line 103

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