nvoip 0.1.0 → 3.0.1
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 +4 -4
- data/.env.example +1 -3
- data/README.md +17 -5
- data/lib/nvoip/client.rb +18 -27
- metadata +19 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e78256cfa3334c13290dddeba58c10842b19618cca4e44df626e2c11dcdda5d4
|
|
4
|
+
data.tar.gz: befd14ab195e9ae6c214f0fcc09cc84878e84c2e806632f36e5123543729d446
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2cdde4fe4599f390183a0c5332179a565f9f6319372fe6645876183d7075e4f6ae756873b85d43dc9272181e71bd58eb54bb20aebe311b8ad0d42b5066fb0006
|
|
7
|
+
data.tar.gz: e5f711101a86b2c56420437ba46eaeea54ad2ded7489aa445ce0843a8a66a62a64ceaa5e5b8202f72fa85117f438dfad99e3cbd8bbcfba9246d0218650455176
|
data/.env.example
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
NVOIP_BASE_URL=https://api.nvoip.com.br/
|
|
1
|
+
NVOIP_BASE_URL=https://api.nvoip.com.br/v3
|
|
2
2
|
NVOIP_NUMBERSIP=
|
|
3
3
|
NVOIP_USER_TOKEN=
|
|
4
4
|
NVOIP_OAUTH_CLIENT_ID=
|
|
5
5
|
NVOIP_OAUTH_CLIENT_SECRET=
|
|
6
|
-
NVOIP_OAUTH_BASIC_AUTH=
|
|
7
|
-
NVOIP_NAPIKEY=
|
|
8
6
|
NVOIP_ACCESS_TOKEN=
|
|
9
7
|
NVOIP_CALLER=
|
|
10
8
|
NVOIP_TARGET_NUMBER=11999999999
|
data/README.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# nvoip-ruby
|
|
2
2
|
|
|
3
|
-
[](https://www.nvoip.com.br/) [](https://github.com/Nvoip/nvoip-ruby/actions/workflows/ci.yml) [](https://rubygems.org/gems/nvoip) [](https://rubygems.org/gems/nvoip) [](https://www.nvoip.com.br/) [](https://www.nvoip.com.br/api/) [](https://nvoip.docs.apiary.io/) [](https://nvoip-api.postman.co/workspace/e671d01f-168a-4c38-8d0e-c217229dd61a/team-quickstart) [](https://github.com/Nvoip/nvoip-api-examples) [](LICENSE)
|
|
4
4
|
|
|
5
|
-
SDK e exemplos oficiais da [Nvoip](https://www.nvoip.com.br/) para integrar a API
|
|
5
|
+
SDK e exemplos oficiais da [Nvoip](https://www.nvoip.com.br/) para integrar a API v3 com OAuth, chamadas, OTP, WhatsApp, SMS e saldo em Ruby.
|
|
6
|
+
|
|
7
|
+
## Migração para v3
|
|
8
|
+
|
|
9
|
+
Esta é uma quebra de compatibilidade: use `create_client_credentials_token` e envie o access token RS256 em `Authorization: Bearer`. O SDK usa `https://api.nvoip.com.br/auth/oauth2/token`; não use `napikey`, password grant ou `/v3/oauth/token`. Para SMS de texto livre, valide antes a política e o template aprovado aplicáveis à sua conta.
|
|
10
|
+
|
|
11
|
+
Os tokens retornados devem ser consumidos somente pelo backend. Não os registre em logs, commits ou mensagens. Em OTP, `methods` é um objeto, por exemplo `{ sms: true }` para `phoneNumber` ou `{ email: true }` para `email`.
|
|
6
12
|
|
|
7
13
|
## Requisitos
|
|
8
14
|
|
|
@@ -23,8 +29,6 @@ cp .env.example .env
|
|
|
23
29
|
Ou exporte:
|
|
24
30
|
|
|
25
31
|
```bash
|
|
26
|
-
export NVOIP_NUMBERSIP="seu_numbersip"
|
|
27
|
-
export NVOIP_USER_TOKEN="seu_user_token"
|
|
28
32
|
export NVOIP_OAUTH_CLIENT_ID="seu_client_id"
|
|
29
33
|
export NVOIP_OAUTH_CLIENT_SECRET="seu_client_secret"
|
|
30
34
|
export NVOIP_CALLER="1049"
|
|
@@ -45,7 +49,7 @@ export NVOIP_TARGET_NUMBER="11999999999"
|
|
|
45
49
|
|
|
46
50
|
## Exemplos
|
|
47
51
|
|
|
48
|
-
- `ruby examples/
|
|
52
|
+
- `ruby examples/create_client_credentials_token.rb`
|
|
49
53
|
- `ruby examples/get_balance.rb`
|
|
50
54
|
- `ruby examples/send_sms.rb`
|
|
51
55
|
- `ruby examples/create_call.rb`
|
|
@@ -54,6 +58,14 @@ export NVOIP_TARGET_NUMBER="11999999999"
|
|
|
54
58
|
- `ruby examples/list_whatsapp_templates.rb`
|
|
55
59
|
- `ruby examples/send_whatsapp_template.rb`
|
|
56
60
|
|
|
61
|
+
### Destinatário WhatsApp
|
|
62
|
+
|
|
63
|
+
O exemplo mantém `NVOIP_WA_DESTINATION` para telefone. Para o contrato tipado,
|
|
64
|
+
use `NVOIP_WA_RECIPIENT_TYPE=phone|bsuid|parent_bsuid` e
|
|
65
|
+
`NVOIP_WA_RECIPIENT_VALUE`, sem `destination`. BSUID é opaco; não use
|
|
66
|
+
`@username` nem o coloque em campo de telefone. Exemplos mascarados:
|
|
67
|
+
`US.MASKED_BSUID_001` e `PARENT.MASKED_BSUID_001`.
|
|
68
|
+
|
|
57
69
|
## SDK web
|
|
58
70
|
|
|
59
71
|
Para o fluxo de popup com telefone e código, use em conjunto o repositório `nvoip-web-sdk`. Este repo cobre o consumo server-side da API.
|
data/lib/nvoip/client.rb
CHANGED
|
@@ -15,25 +15,24 @@ module Nvoip
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
class Client
|
|
18
|
-
def initialize(base_url: "https://api.nvoip.com.br/
|
|
19
|
-
oauth_client_id: ENV["NVOIP_OAUTH_CLIENT_ID"], oauth_client_secret: ENV["NVOIP_OAUTH_CLIENT_SECRET"])
|
|
18
|
+
def initialize(base_url: "https://api.nvoip.com.br/v3",
|
|
19
|
+
oauth_client_id: ENV["NVOIP_OAUTH_CLIENT_ID"], oauth_client_secret: ENV["NVOIP_OAUTH_CLIENT_SECRET"], token_url: "https://api.nvoip.com.br/auth/oauth2/token")
|
|
20
20
|
@base_url = base_url.sub(%r{/+$}, "")
|
|
21
21
|
@oauth_client_id = oauth_client_id
|
|
22
22
|
@oauth_client_secret = oauth_client_secret
|
|
23
|
+
@token_url = token_url
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def self.encode_basic_auth(client_id, client_secret)
|
|
26
|
-
Base64.strict_encode64("#{client_id}:#{client_secret}")
|
|
27
|
+
Base64.strict_encode64("#{URI.encode_www_form_component(client_id)}:#{URI.encode_www_form_component(client_secret)}")
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
def
|
|
30
|
+
def create_client_credentials_token
|
|
30
31
|
request_form(
|
|
31
32
|
"POST",
|
|
32
|
-
|
|
33
|
+
@token_url,
|
|
33
34
|
{
|
|
34
|
-
|
|
35
|
-
password: user_token,
|
|
36
|
-
grant_type: "password"
|
|
35
|
+
grant_type: "client_credentials"
|
|
37
36
|
},
|
|
38
37
|
{
|
|
39
38
|
"Authorization" => "Basic #{resolve_basic_auth}"
|
|
@@ -44,7 +43,7 @@ module Nvoip
|
|
|
44
43
|
def refresh_access_token(refresh_token:)
|
|
45
44
|
request_form(
|
|
46
45
|
"POST",
|
|
47
|
-
|
|
46
|
+
@token_url,
|
|
48
47
|
{
|
|
49
48
|
grant_type: "refresh_token",
|
|
50
49
|
refresh_token: refresh_token
|
|
@@ -59,7 +58,7 @@ module Nvoip
|
|
|
59
58
|
request("GET", "/balance", headers: auth_headers(access_token))
|
|
60
59
|
end
|
|
61
60
|
|
|
62
|
-
def send_sms(number_phone:, message:, flash_sms: false, access_token:
|
|
61
|
+
def send_sms(number_phone:, message:, flash_sms: false, access_token:)
|
|
63
62
|
request_json(
|
|
64
63
|
"POST",
|
|
65
64
|
"/sms",
|
|
@@ -68,8 +67,7 @@ module Nvoip
|
|
|
68
67
|
message: message,
|
|
69
68
|
flashSms: flash_sms
|
|
70
69
|
},
|
|
71
|
-
access_token: access_token
|
|
72
|
-
napikey: napikey
|
|
70
|
+
access_token: access_token
|
|
73
71
|
)
|
|
74
72
|
end
|
|
75
73
|
|
|
@@ -85,12 +83,12 @@ module Nvoip
|
|
|
85
83
|
)
|
|
86
84
|
end
|
|
87
85
|
|
|
88
|
-
def send_otp(payload:, access_token:
|
|
89
|
-
request_json("POST", "/otp", payload, access_token: access_token
|
|
86
|
+
def send_otp(payload:, access_token:)
|
|
87
|
+
request_json("POST", "/otp", payload, access_token: access_token)
|
|
90
88
|
end
|
|
91
89
|
|
|
92
|
-
def check_otp(code:, key:)
|
|
93
|
-
request("GET", "/check/otp?code=#{URI.encode_www_form_component(code)}&key=#{URI.encode_www_form_component(key)}")
|
|
90
|
+
def check_otp(code:, key:, access_token:)
|
|
91
|
+
request("GET", "/check/otp?code=#{URI.encode_www_form_component(code)}&key=#{URI.encode_www_form_component(key)}", headers: auth_headers(access_token))
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
def list_whatsapp_templates(access_token:)
|
|
@@ -109,13 +107,13 @@ module Nvoip
|
|
|
109
107
|
raise ArgumentError, "Missing OAuth client credentials. Configure oauth_client_id + oauth_client_secret."
|
|
110
108
|
end
|
|
111
109
|
|
|
112
|
-
def request_json(method, path, payload, access_token:
|
|
110
|
+
def request_json(method, path, payload, access_token:)
|
|
113
111
|
request(
|
|
114
112
|
method,
|
|
115
|
-
|
|
113
|
+
path,
|
|
116
114
|
headers: {
|
|
117
115
|
"Content-Type" => "application/json"
|
|
118
|
-
}.merge(
|
|
116
|
+
}.merge(auth_headers(access_token)),
|
|
119
117
|
body: JSON.generate(payload)
|
|
120
118
|
)
|
|
121
119
|
end
|
|
@@ -132,7 +130,7 @@ module Nvoip
|
|
|
132
130
|
end
|
|
133
131
|
|
|
134
132
|
def request(method, path, headers: {}, body: nil)
|
|
135
|
-
uri = URI("#{@base_url}#{path}")
|
|
133
|
+
uri = URI(path.start_with?("http") ? path : "#{@base_url}#{path}")
|
|
136
134
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
137
135
|
http.use_ssl = uri.scheme == "https"
|
|
138
136
|
http.read_timeout = 30
|
|
@@ -161,13 +159,6 @@ module Nvoip
|
|
|
161
159
|
payload
|
|
162
160
|
end
|
|
163
161
|
|
|
164
|
-
def with_napikey(path, napikey)
|
|
165
|
-
return path if blank?(napikey)
|
|
166
|
-
|
|
167
|
-
separator = path.include?("?") ? "&" : "?"
|
|
168
|
-
"#{path}#{separator}napikey=#{URI.encode_www_form_component(napikey)}"
|
|
169
|
-
end
|
|
170
|
-
|
|
171
162
|
def auth_headers(access_token)
|
|
172
163
|
{ "Authorization" => "Bearer #{access_token}" }
|
|
173
164
|
end
|
metadata
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nvoip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 3.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nvoip
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2026-10-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: base64
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.1'
|
|
13
27
|
description: SDK Ruby oficial para integrar OAuth, chamadas, OTP, WhatsApp, SMS e
|
|
14
|
-
saldo com a API
|
|
28
|
+
saldo com a API v3 da Nvoip.
|
|
15
29
|
email:
|
|
16
30
|
executables: []
|
|
17
31
|
extensions: []
|
|
@@ -48,5 +62,5 @@ requirements: []
|
|
|
48
62
|
rubygems_version: 3.5.22
|
|
49
63
|
signing_key:
|
|
50
64
|
specification_version: 4
|
|
51
|
-
summary: SDK Ruby oficial para a API
|
|
65
|
+
summary: SDK Ruby oficial para a API v3 da Nvoip
|
|
52
66
|
test_files: []
|