Class: ApiBrasil::Legacy::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/api_brasil/legacy/service.rb

Constant Summary collapse

BASE_URI =
"https://gateway.apibrasil.io/api/v2"

Class Method Summary collapse

Class Method Details

.auth(action = "", data = {}) ⇒ Object

POST /{action} (ex: login, logout)



26
27
28
# File 'lib/api_brasil/legacy/service.rb', line 26

def auth(action = "", data = {})
  call(action, data)
end

.cep(action = "", data = {}) ⇒ Object

POST /cep/{action}



75
76
77
# File 'lib/api_brasil/legacy/service.rb', line 75

def cep(action = "", data = {})
  call(join("cep", action), data)
end

.cnpj(action = "", data = {}) ⇒ Object

POST /dados/{action} (mantido com o nome antigo cnpj)



70
71
72
# File 'lib/api_brasil/legacy/service.rb', line 70

def cnpj(action = "", data = {})
  call(join("dados", action), data)
end

.correios(action = "", data = {}) ⇒ Object

POST /correios/{action}



65
66
67
# File 'lib/api_brasil/legacy/service.rb', line 65

def correios(action = "", data = {})
  call(join("correios", action), data)
end

.ddd(action = "", data = {}) ⇒ Object

POST /ddd/{action}



85
86
87
# File 'lib/api_brasil/legacy/service.rb', line 85

def ddd(action = "", data = {})
  call(join("ddd", action), data)
end

.device(action = "", data = {}) ⇒ Object

POST /devices/{action}



43
44
45
# File 'lib/api_brasil/legacy/service.rb', line 43

def device(action = "", data = {})
  call(join("devices", action), data)
end

.holidays(action = "", data = {}) ⇒ Object

POST /holidays/{action}



80
81
82
# File 'lib/api_brasil/legacy/service.rb', line 80

def holidays(action = "", data = {})
  call(join("holidays", action), data)
end

.plan(action = "", data = {}) ⇒ Object

POST /plan (action me) ou POST /plans/{action}



31
32
33
34
35
# File 'lib/api_brasil/legacy/service.rb', line 31

def plan(action = "", data = {})
  return call("plan", data) if action.to_s == "me"

  call(join("plans", action), data)
end

.profile(data = {}) ⇒ Object

POST /profile



38
39
40
# File 'lib/api_brasil/legacy/service.rb', line 38

def profile(data = {})
  call("profile", data)
end

.server(data = {}) ⇒ Object

POST /servers



21
22
23
# File 'lib/api_brasil/legacy/service.rb', line 21

def server(data = {})
  call("servers", data)
end

.vehicles(action = "", data = {}) ⇒ Object

POST /vehicles/{action} - normaliza o campo tipo como na SDK PHP.



53
54
55
56
57
58
59
60
61
62
# File 'lib/api_brasil/legacy/service.rb', line 53

def vehicles(action = "", data = {})
  normalized = Core::HttpClient.normalize_keys(data)
  action = action.to_s.sub(%r{\A/+}, "")
  body = normalized[:body] || {}

  body = { "tipo" => normalized[:tipo].to_s }.merge(body) if normalized[:tipo] && !key?(body, "tipo")
  body = normalize_tipo_body(body) if action.start_with?("base/")

  call(join("vehicles", action), data, {}, body)
end

.whatsapp(action = "", data = {}) ⇒ Object

POST /whatsapp/{action}



48
49
50
# File 'lib/api_brasil/legacy/service.rb', line 48

def whatsapp(action = "", data = {})
  call(join("whatsapp", action), data)
end