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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +1 -3
  3. data/README.md +17 -5
  4. data/lib/nvoip/client.rb +18 -27
  5. metadata +19 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44d1895ada3f8fdb8092ab86ad9adfad3a8e924bf1a5fcf5ea7ff32935723379
4
- data.tar.gz: 8bbc8c7a858a056ec6357f88917d0c993cc75dc57d43b8626649c432b166f799
3
+ metadata.gz: e78256cfa3334c13290dddeba58c10842b19618cca4e44df626e2c11dcdda5d4
4
+ data.tar.gz: befd14ab195e9ae6c214f0fcc09cc84878e84c2e806632f36e5123543729d446
5
5
  SHA512:
6
- metadata.gz: e72780fe1e935baee249b3a6b82f044d6380c26d4661532817f75d744e6cf4e9f5fbe9994ae4cde06d77b6885d5ed66c222fdae7e4a4cf7d8131be65ed0b9b58
7
- data.tar.gz: 477c87c9893afefc2cdd9ae675126511ae6d65dd0d36d0969ebb905e85d48c88c8d55075530c6dbd17a4ce28d04605d9f05eeb8f0df81d76acf81deb779f8452
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/v2
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
- [![Nvoip](https://img.shields.io/badge/Nvoip-site-00A3E0?style=flat-square)](https://www.nvoip.com.br/) [![API v2](https://img.shields.io/badge/API-v2-1F6FEB?style=flat-square)](https://www.nvoip.com.br/api/) [![Docs](https://img.shields.io/badge/docs-Apiary-6A737D?style=flat-square)](https://nvoip.docs.apiary.io/) [![Postman](https://img.shields.io/badge/Postman-workspace-FF6C37?style=flat-square)](https://nvoip-api.postman.co/workspace/e671d01f-168a-4c38-8d0e-c217229dd61a/team-quickstart) [![Stack](https://img.shields.io/badge/stack-Ruby-CC342D?style=flat-square)](https://github.com/Nvoip/nvoip-api-examples) [![License: GPL-3.0](https://img.shields.io/badge/license-GPL--3.0-blue?style=flat-square)](LICENSE)
3
+ [![CI](https://github.com/Nvoip/nvoip-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/Nvoip/nvoip-ruby/actions/workflows/ci.yml) [![Gem](https://img.shields.io/gem/v/nvoip?style=flat-square)](https://rubygems.org/gems/nvoip) [![Gem downloads](https://img.shields.io/gem/dt/nvoip?style=flat-square)](https://rubygems.org/gems/nvoip) [![Nvoip](https://img.shields.io/badge/Nvoip-site-00A3E0?style=flat-square)](https://www.nvoip.com.br/) [![API v3](https://img.shields.io/badge/API-v3-1F6FEB?style=flat-square)](https://www.nvoip.com.br/api/) [![Docs](https://img.shields.io/badge/docs-Apiary-6A737D?style=flat-square)](https://nvoip.docs.apiary.io/) [![Postman](https://img.shields.io/badge/Postman-workspace-FF6C37?style=flat-square)](https://nvoip-api.postman.co/workspace/e671d01f-168a-4c38-8d0e-c217229dd61a/team-quickstart) [![Stack](https://img.shields.io/badge/stack-Ruby-CC342D?style=flat-square)](https://github.com/Nvoip/nvoip-api-examples) [![License: GPL-3.0](https://img.shields.io/badge/license-GPL--3.0-blue?style=flat-square)](LICENSE)
4
4
 
5
- SDK e exemplos oficiais da [Nvoip](https://www.nvoip.com.br/) para integrar a API v2 com OAuth, chamadas, OTP, WhatsApp, SMS e saldo em Ruby.
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/create_access_token.rb`
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/v2",
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 create_access_token(numbersip:, user_token:)
30
+ def create_client_credentials_token
30
31
  request_form(
31
32
  "POST",
32
- "/oauth/token",
33
+ @token_url,
33
34
  {
34
- username: numbersip,
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
- "/oauth/token",
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: nil, napikey: nil)
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: nil, napikey: nil)
89
- request_json("POST", "/otp", payload, access_token: access_token, napikey: napikey)
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: nil, napikey: nil)
110
+ def request_json(method, path, payload, access_token:)
113
111
  request(
114
112
  method,
115
- with_napikey(path, napikey),
113
+ path,
116
114
  headers: {
117
115
  "Content-Type" => "application/json"
118
- }.merge(access_token ? auth_headers(access_token) : {}),
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.0
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-04-30 00:00:00.000000000 Z
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 v2 da Nvoip.
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 v2 da Nvoip
65
+ summary: SDK Ruby oficial para a API v3 da Nvoip
52
66
  test_files: []