didww-v3 6.2.0 → 7.0.0
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/.github/workflows/tests.yml +8 -6
- data/.rubocop.yml +0 -110
- data/CHANGELOG.md +65 -0
- data/FILTERS.md +36 -12
- data/Gemfile +0 -2
- data/README.md +431 -58
- data/didww-v3.gemspec +11 -8
- data/docs/resource_relationships.md +35 -15
- data/examples/README.md +54 -61
- data/examples/capacity_pools.rb +28 -10
- data/examples/countries.rb +1 -1
- data/examples/did_groups.rb +1 -1
- data/examples/did_reservations.rb +35 -37
- data/examples/did_sms_routing.rb +91 -0
- data/examples/did_trunk_assignment.rb +106 -80
- data/examples/emergency_calling_services.rb +3 -3
- data/examples/emergency_requirements.rb +3 -3
- data/examples/emergency_scenario.rb +11 -11
- data/examples/emergency_verifications.rb +7 -5
- data/examples/exports.rb +1 -1
- data/examples/exports_sms.rb +72 -0
- data/examples/identity_address_proofs.rb +118 -0
- data/examples/includes.rb +65 -0
- data/examples/orders.rb +8 -6
- data/examples/orders_all_item_types.rb +63 -125
- data/examples/orders_emergency.rb +3 -3
- data/examples/{orders_by_sku.rb → orders_sku.rb} +12 -10
- data/examples/prices_download.rb +45 -0
- data/examples/prices_lookup.rb +43 -0
- data/examples/regions.rb +1 -1
- data/examples/sample.pdf +14 -0
- data/examples/sender_id_verifications.rb +63 -0
- data/examples/shared_capacity_groups.rb +44 -35
- data/examples/sms_trunk_groups.rb +71 -0
- data/examples/sms_trunks.rb +84 -0
- data/examples/test_readme.rb +1216 -0
- data/examples/trunks.rb +115 -0
- data/examples/upload_file.rb +44 -0
- data/examples/voice_in_trunk_groups.rb +57 -33
- data/examples/voice_in_trunk_sip_registration.rb +4 -1
- data/examples/voice_out_trunks.rb +11 -1
- data/examples/webhook.rb +51 -0
- data/lib/didww/auth/bearer_middleware.rb +74 -0
- data/lib/didww/auth/memory_store.rb +40 -0
- data/lib/didww/auth/token.rb +45 -0
- data/lib/didww/auth/token_provider.rb +215 -0
- data/lib/didww/base_middleware.rb +7 -8
- data/lib/didww/callback/request_validator.rb +7 -5
- data/lib/didww/client.rb +122 -13
- data/lib/didww/complex_objects/authentication_methods/generic.rb +6 -0
- data/lib/didww/complex_objects/configurations/base.rb +0 -18
- data/lib/didww/complex_objects/configurations/pstn_configuration.rb +0 -4
- data/lib/didww/complex_objects/configurations/sip_configuration.rb +86 -38
- data/lib/didww/complex_objects/emergency_order_item.rb +1 -1
- data/lib/didww/complex_objects/export_filters.rb +72 -6
- data/lib/didww/complex_objects/generic_order_item.rb +15 -0
- data/lib/didww/complex_objects/sms_trunk_configuration.rb +33 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/base.rb +26 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/generic.rb +32 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/http_in.rb +75 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/http_out.rb +35 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/smpp_esme.rb +37 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/smpp_smsc.rb +56 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/sms_to_email.rb +27 -0
- data/lib/didww/errors.rb +103 -0
- data/lib/didww/http.rb +34 -0
- data/lib/didww/prices/lookup_result.rb +37 -0
- data/lib/didww/prices/price.rb +56 -0
- data/lib/didww/prices/price_file.rb +51 -0
- data/lib/didww/prices/service.rb +248 -0
- data/lib/didww/prices/sms_in_price.rb +43 -0
- data/lib/didww/prices/sms_out_price.rb +52 -0
- data/lib/didww/prices/voice_in_price.rb +48 -0
- data/lib/didww/prices/voice_out_price.rb +88 -0
- data/lib/didww/prices.rb +82 -0
- data/lib/didww/resource/address_requirement.rb +13 -3
- data/lib/didww/resource/base.rb +5 -2
- data/lib/didww/resource/concerns/number_types.rb +24 -0
- data/lib/didww/resource/did.rb +42 -3
- data/lib/didww/resource/did_group.rb +12 -1
- data/lib/didww/resource/emergency_calling_service.rb +10 -5
- data/lib/didww/resource/emergency_requirement.rb +27 -14
- data/lib/didww/resource/encrypted_file.rb +19 -6
- data/lib/didww/resource/export.rb +59 -12
- data/lib/didww/resource/identity.rb +9 -4
- data/lib/didww/resource/order.rb +1 -0
- data/lib/didww/resource/proof_type.rb +1 -1
- data/lib/didww/resource/sender_id_verification.rb +114 -0
- data/lib/didww/resource/sms_trunk.rb +76 -0
- data/lib/didww/resource/sms_trunk_group.rb +31 -0
- data/lib/didww/resource/sms_trunk_regenerate_credential.rb +16 -0
- data/lib/didww/resource/voice_in_trunk.rb +24 -1
- data/lib/didww/resource/voice_out_trunk.rb +72 -0
- data/lib/didww/types/ip_addresses.rb +1 -1
- data/lib/didww/types/strings.rb +1 -1
- data/lib/didww/types.rb +3 -1
- data/lib/didww/version.rb +1 -1
- data/lib/didww.rb +7 -0
- metadata +63 -25
- data/examples/identities_and_proofs.rb +0 -67
- data/examples/voice_in_trunks.rb +0 -108
- data/lib/didww/resource/did_group_type.rb +0 -10
- data/lib/didww/resource/exclusive_relationship.rb +0 -54
- data/lib/didww/resource/pop.rb +0 -10
data/README.md
CHANGED
|
@@ -18,11 +18,12 @@ Read more https://doc.didww.com/api
|
|
|
18
18
|
|
|
19
19
|
## API Version
|
|
20
20
|
|
|
21
|
-
This SDK
|
|
21
|
+
This SDK targets DIDWW API version `2026-11-19` (`DIDWW::Client::DEFAULT_API_VERSION`). The version is not sent as a header: it is requested in the `api_version` of every access token the SDK mints (see [Authentication](#authentication)).
|
|
22
22
|
|
|
23
23
|
| Gem Version | Branch | DIDWW API Version |
|
|
24
24
|
|-------------|--------|-------------------|
|
|
25
|
-
| **
|
|
25
|
+
| **7.x** | [`master`](https://github.com/didww/didww-v3-ruby) | [`2026-11-19`](https://doc.didww.com/api3/2026-11-19/index.html) |
|
|
26
|
+
| **6.x** | [`release-6`](https://github.com/didww/didww-v3-ruby/tree/release-6) | [`2026-04-16`](https://doc.didww.com/api3/2026-04-16/index.html) |
|
|
26
27
|
| **5.x** | [`2022-05-10`](https://github.com/didww/didww-v3-ruby/tree/2022-05-10) | [`2022-05-10`](https://doc.didww.com/api3/2022-05-10/index.html) |
|
|
27
28
|
| **3.x** | [`release-3`](https://github.com/didww/didww-v3-ruby/tree/release-3) | [`2021-12-15`](https://doc.didww.com/api3/2021-12-15/index.html) |
|
|
28
29
|
| **2.x** | [`release-2`](https://github.com/didww/didww-v3-ruby/tree/release-2) | [`2021-04-19`](https://doc.didww.com/api3/2021-04-19/index.html) |
|
|
@@ -63,10 +64,10 @@ balance = DIDWW::Client.balance
|
|
|
63
64
|
puts "Balance: #{balance.total_balance}"
|
|
64
65
|
|
|
65
66
|
# List DID groups with stock keeping units
|
|
66
|
-
did_groups = DIDWW::Client.did_groups
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
did_groups = DIDWW::Client.did_groups
|
|
68
|
+
.includes(:stock_keeping_units)
|
|
69
|
+
.where(area_name: 'Acapulco')
|
|
70
|
+
.all
|
|
70
71
|
|
|
71
72
|
puts "DID groups: #{did_groups.count}"
|
|
72
73
|
```
|
|
@@ -75,6 +76,7 @@ For details on obtaining your API key please visit https://doc.didww.com/api3/co
|
|
|
75
76
|
|
|
76
77
|
## Examples
|
|
77
78
|
|
|
79
|
+
- Scripts for every resource: [`examples/`](examples/README.md)
|
|
78
80
|
- Rails integration sample: https://github.com/didww/didww-v3-rails-sample
|
|
79
81
|
|
|
80
82
|
## Configuration
|
|
@@ -95,16 +97,37 @@ DIDWW::Client.configure do |config|
|
|
|
95
97
|
end
|
|
96
98
|
```
|
|
97
99
|
|
|
100
|
+
| Option | Default | Description |
|
|
101
|
+
|--------|---------|-------------|
|
|
102
|
+
| `api_key` | — | Your DIDWW API key. It is sent only to the token service. |
|
|
103
|
+
| `api_mode` | `:sandbox` | `:sandbox` or `:production`. |
|
|
104
|
+
| `api_version` | `DIDWW::Client::DEFAULT_API_VERSION` | API version requested in every token. See [API Version](#api-version-1). |
|
|
105
|
+
| `scope` | `nil` | `nil`, `:read` or `:full`. `nil` leaves the scope to the token service, which grants `full`. See [Scope](#scope). |
|
|
106
|
+
| `token_store` | `DIDWW::Auth::MemoryStore.new` | Cache for access tokens. See [Token cache](#token-cache). |
|
|
107
|
+
| `logger` | `Logger.new($stderr, level: :warn)` | Receives the token warnings. Set it to `Rails.logger`, or to `nil` to silence them. |
|
|
108
|
+
| `customize_connection { \|conn\| }` | — | Customizes the JSON:API connection. |
|
|
109
|
+
| `customize_faraday { \|faraday\| }` | — | Customizes the other connections: token service, prices, export download and file upload. |
|
|
110
|
+
|
|
98
111
|
### Environments
|
|
99
112
|
|
|
100
|
-
| Environment |
|
|
101
|
-
|
|
102
|
-
| `:production` | `https://api.didww.com/v3/` |
|
|
103
|
-
| `:sandbox` | `https://sandbox-api.didww.com/v3/` |
|
|
113
|
+
| Environment | API | Token service | Voice IN prices | Voice OUT prices | SMS prices |
|
|
114
|
+
|-------------|-----|---------------|-----------------|------------------|------------|
|
|
115
|
+
| `:production` | `https://api.didww.com/v3/` | `https://auth.didww.com` | `https://api-vin.didww.com/v3/` | `https://api-vout.didww.com/v3/` | `https://api-sms.didww.com/v3/` |
|
|
116
|
+
| `:sandbox` | `https://sandbox-api.didww.com/v3/` | `https://auth-sandbox.didww.com` | `https://api-vin-sandbox.didww.com/v3/` | `https://api-vout-sandbox.didww.com/v3/` | `https://api-sms-sandbox.didww.com/v3/` |
|
|
117
|
+
|
|
118
|
+
Each base URL can be overridden with an environment variable, for example to send the traffic through a proxy. Tokens are still requested for the production audiences listed in [Authentication](#authentication).
|
|
119
|
+
|
|
120
|
+
| Variable | Overrides |
|
|
121
|
+
|----------|-----------|
|
|
122
|
+
| `DIDWW_API_URL` | API base URL. End it with `/`. |
|
|
123
|
+
| `DIDWW_AUTH_URL` | Token service base URL |
|
|
124
|
+
| `DIDWW_API_VIN_URL` | Voice IN prices base URL |
|
|
125
|
+
| `DIDWW_API_VOUT_URL` | Voice OUT prices base URL |
|
|
126
|
+
| `DIDWW_API_SMS_URL` | SMS prices base URL |
|
|
104
127
|
|
|
105
128
|
### Connection Customization
|
|
106
129
|
|
|
107
|
-
Use `customize_connection` to customize the underlying
|
|
130
|
+
Use `customize_connection` to customize the underlying JSON:API connection, for example to configure a proxy or add custom middleware:
|
|
108
131
|
|
|
109
132
|
```ruby
|
|
110
133
|
# Using a proxy
|
|
@@ -132,16 +155,101 @@ DIDWW::Client.configure do |config|
|
|
|
132
155
|
end
|
|
133
156
|
```
|
|
134
157
|
|
|
158
|
+
The token service, prices, export download and file upload use their own Faraday connections. `customize_faraday` is called with each of them after it is built, so a proxy has to be set in both blocks:
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
DIDWW::Client.configure do |config|
|
|
162
|
+
config.api_key = 'YOUR_API_KEY'
|
|
163
|
+
config.api_mode = :production
|
|
164
|
+
config.customize_connection { |conn| conn.faraday.proxy = 'http://proxy.example.com:8080' }
|
|
165
|
+
config.customize_faraday do |faraday|
|
|
166
|
+
# faraday is a Faraday::Connection instance
|
|
167
|
+
faraday.proxy = 'http://proxy.example.com:8080'
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
These connections open with a 10 s timeout and read with 60 s, except the token service, which reads with 10 s. A timeout set in `customize_faraday` applies to all of them, the token service included.
|
|
173
|
+
|
|
135
174
|
### API Version
|
|
136
175
|
|
|
137
|
-
|
|
176
|
+
Every token is requested for `DIDWW::Client.api_version`, which defaults to `DIDWW::Client::DEFAULT_API_VERSION`. `with_api_version` overrides it for a block. The override applies only to the current thread, so concurrent requests on other threads keep their own version:
|
|
138
177
|
|
|
139
178
|
```ruby
|
|
140
|
-
DIDWW::Client.with_api_version('
|
|
179
|
+
DIDWW::Client.with_api_version('2099-01-01') do
|
|
141
180
|
DIDWW::Client.countries.all
|
|
142
181
|
end
|
|
143
182
|
```
|
|
144
183
|
|
|
184
|
+
Both `api_version=` and `with_api_version` raise `ArgumentError` for a value that is not a `YYYY-MM-DD` date, and for a version earlier than `DIDWW::Client::DEFAULT_API_VERSION`. The resources of earlier API versions are not in this gem: use didww-v3 6.x from the [`release-6`](https://github.com/didww/didww-v3-ruby/tree/release-6) branch for API `2026-04-16`.
|
|
185
|
+
|
|
186
|
+
## Authentication
|
|
187
|
+
|
|
188
|
+
Every request carries `Authorization: Bearer <token>`. The SDK mints the token itself with `POST /token` on the token service, sending your `api_key` in the `Api-Key` header. The API key is sent nowhere else. No code change is needed: `api_key` and `api_mode` work as before.
|
|
189
|
+
|
|
190
|
+
- **Audience.** Each token names the one service it is used for, as the production hostname of that service, in the sandbox too:
|
|
191
|
+
|
|
192
|
+
| Calls | Token audience |
|
|
193
|
+
|-------|----------------|
|
|
194
|
+
| JSON:API resources, export download, encrypted file upload | `api.didww.com` |
|
|
195
|
+
| Voice IN prices | `api-vin.didww.com` |
|
|
196
|
+
| Voice OUT prices | `api-vout.didww.com` |
|
|
197
|
+
| SMS OUT (A2P, P2P, OTP) and SMS IN prices | `api-sms.didww.com` |
|
|
198
|
+
|
|
199
|
+
A token is minted on the first call to a service and reused until it expires. `GET /public_keys` is sent without a token.
|
|
200
|
+
- **Expiry and 401.** The SDK asks for the longest lifetime the token service grants, one hour (`expires_in: 3600`); a cached token expires with the `expires_in` granted, with no local expiry margin. When a request is answered 401, the SDK drops that token, mints a new one and sends the request again, once. A second 401 drops the new token too and is raised (see [Error Handling](#error-handling)). A 403 is never retried.
|
|
201
|
+
- **Token service errors.** A 429 raises `DIDWW::Auth::RateLimited` with `retry_after`; until that time has passed, plus a small random delay so that clients do not retry in step, every further mint in the process raises the same error without a request. A 5xx answer, a connection failure or a timeout is retried with exponential backoff and jitter (0.5 s base, 8 s cap, 4 attempts in all). A 400, a 401 or a TLS failure is raised at once. See [Error Handling](#error-handling) for the error classes.
|
|
202
|
+
|
|
203
|
+
### Scope
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
DIDWW::Client.scope = :read # GET and HEAD only
|
|
207
|
+
DIDWW::Client.scope = :full
|
|
208
|
+
DIDWW::Client.scope = nil # the default: scope is not sent, the token service grants full
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
A `read` token is enough for the price lookups and price files. A write with a `read` token is answered 403: resources raise `JsonApiClient::Errors::AccessDenied`, and `EncryptedFile.upload` raises `DIDWW::Resource::EncryptedFile::UploadError`.
|
|
212
|
+
|
|
213
|
+
The SDK compares each token it receives with what it asked for:
|
|
214
|
+
|
|
215
|
+
- a different `scope` (for example `full` granted for a `read` request) or a different `api_version` is logged as a warning through `DIDWW::Client.logger`, and the token is used;
|
|
216
|
+
- a token whose `aud` does not include the requested audience raises `DIDWW::Auth::InvalidGrant`.
|
|
217
|
+
|
|
218
|
+
### Token cache
|
|
219
|
+
|
|
220
|
+
Tokens are cached in `DIDWW::Client.token_store`, keyed by environment, API key (as a SHA-256 hash), audience, API version and scope. Each entry expires with the token's `expires_in`.
|
|
221
|
+
|
|
222
|
+
The default `DIDWW::Auth::MemoryStore` lives in the Ruby process, so a Puma or Sidekiq worker reuses a token across requests. Threads of one process that need the same token wait for a single mint. To share tokens between processes, use any store that responds to `read(key)`, `write(key, value, expires_in:)` and `delete(key)`, such as an `ActiveSupport::Cache::Store`:
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
225
|
+
DIDWW::Client.token_store = Rails.cache
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
A store that keeps nothing, such as Rails' `:null_store`, makes the SDK mint a token on every call. A shared store holds live bearer tokens, so protect it like a credential. Processes that share a store can each mint once when a token is missing.
|
|
229
|
+
|
|
230
|
+
### Logging and instrumentation
|
|
231
|
+
|
|
232
|
+
Token warnings go to `DIDWW::Client.logger`. Each mint is also published as the `ActiveSupport::Notifications` event `mint_token.didww`, with the payload keys `aud`, `scope_requested`, `scope_granted`, `api_version` and `expires_in`. A mint that fails publishes the event too, with ActiveSupport's `exception` and `exception_object` keys and only `aud` and `scope_requested` set. A token taken from the cache, a mint refused inside a `Retry-After` window and an error shared with threads that waited for the same mint publish nothing. Neither the logs nor the event include the token or the API key.
|
|
233
|
+
|
|
234
|
+
```ruby
|
|
235
|
+
ActiveSupport::Notifications.subscribe('mint_token.didww') do |event|
|
|
236
|
+
aud = event.payload[:aud].join(', ')
|
|
237
|
+
if event.payload[:exception]
|
|
238
|
+
Rails.logger.warn("DIDWW token mint for #{aud} failed after #{event.duration.round} ms: #{event.payload[:exception].first}")
|
|
239
|
+
else
|
|
240
|
+
Rails.logger.info("DIDWW token minted for #{aud} in #{event.duration.round} ms")
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### SDK design decisions
|
|
246
|
+
|
|
247
|
+
- **Audience strategy.** One token per audience, minted on first use, rather than one token naming every service. An account that never calls the prices services never requests their audiences, so a refused audience cannot break DID management, and every token is valid for one service only.
|
|
248
|
+
- **Cache store.** In-process memory by default, because Ruby processes serve many requests in their lifetime. A shared store is opt-in through `token_store`.
|
|
249
|
+
- **Token lifetime.** The longest the token service grants, one hour, so that a process mints each token as rarely as possible. Lifetime is decided by the server through the 401 refresh, not by a local expiry margin.
|
|
250
|
+
- **Gzip handling.** Price files are streamed to disk exactly as served, still gzipped and in binary mode, without being held in memory. The SDK never decompresses them on its own: `DIDWW::Prices.each_row` reads a downloaded file when you want rows.
|
|
251
|
+
- **Streamed-upload retry limitation.** The 401 retry sends the request body a second time. `EncryptedFile.upload` rewinds its multipart body for that; when the file IO cannot be rewound (a pipe or a socket), the refused token is still discarded, but the 401 is not retried and the upload raises `DIDWW::Resource::EncryptedFile::UploadError`. Pass a `File`, `Tempfile` or `StringIO` to keep the retry.
|
|
252
|
+
|
|
145
253
|
## Resources
|
|
146
254
|
|
|
147
255
|
### Read-Only Resources
|
|
@@ -151,31 +259,34 @@ end
|
|
|
151
259
|
countries = DIDWW::Client.countries.all
|
|
152
260
|
country = DIDWW::Client.countries.find('uuid')
|
|
153
261
|
|
|
154
|
-
# Regions, Cities, Areas
|
|
262
|
+
# Regions, Cities, Areas
|
|
155
263
|
regions = DIDWW::Client.regions.all
|
|
156
264
|
cities = DIDWW::Client.cities.all
|
|
157
265
|
areas = DIDWW::Client.areas.all
|
|
158
|
-
pops = DIDWW::Client.pops.all
|
|
159
|
-
|
|
160
|
-
# DID Group Types
|
|
161
|
-
types = DIDWW::Client.did_group_types.all
|
|
162
266
|
|
|
163
|
-
# DID Groups (with stock keeping units)
|
|
164
|
-
did_groups = DIDWW::Client.did_groups
|
|
267
|
+
# DID Groups (with stock keeping units), filtered by number type
|
|
268
|
+
did_groups = DIDWW::Client.did_groups
|
|
269
|
+
.where(number_type: DIDWW::Resource::DidGroup::NUMBER_TYPE_TOLL_FREE)
|
|
270
|
+
.includes(:stock_keeping_units)
|
|
271
|
+
.all
|
|
165
272
|
|
|
166
273
|
# Available DIDs (with DID group and stock keeping units)
|
|
167
|
-
available_dids = DIDWW::Client.available_dids
|
|
274
|
+
available_dids = DIDWW::Client.available_dids
|
|
275
|
+
.includes('did_group.stock_keeping_units')
|
|
276
|
+
.all
|
|
168
277
|
|
|
169
278
|
# Public Keys
|
|
170
279
|
public_keys = DIDWW::Client.public_keys.all
|
|
171
280
|
|
|
172
|
-
#
|
|
173
|
-
requirements = DIDWW::Client.
|
|
281
|
+
# Address requirements
|
|
282
|
+
requirements = DIDWW::Client.address_requirements.all
|
|
174
283
|
|
|
175
284
|
# Balance (singleton)
|
|
176
285
|
balance = DIDWW::Client.balance
|
|
177
286
|
```
|
|
178
287
|
|
|
288
|
+
`DidGroup`, `AddressRequirement`, `EmergencyRequirement` and `EmergencyCallingService` carry a `number_type`, one of `DIDWW::Resource::NumberTypes::NUMBER_TYPES` (`local`, `national`, `mobile`, `toll_free`, `shared_cost`, `global`). `DidGroup#is_demo` flags demo groups.
|
|
289
|
+
|
|
179
290
|
### DIDs
|
|
180
291
|
|
|
181
292
|
```ruby
|
|
@@ -183,28 +294,53 @@ balance = DIDWW::Client.balance
|
|
|
183
294
|
dids = DIDWW::Client.dids.all
|
|
184
295
|
|
|
185
296
|
# Update DID
|
|
186
|
-
did = DIDWW::Client.dids.find('uuid')
|
|
297
|
+
did = DIDWW::Client.dids.find('uuid').first
|
|
187
298
|
did.description = 'Updated'
|
|
188
299
|
did.capacity_limit = 20
|
|
189
300
|
did.save
|
|
190
301
|
```
|
|
191
302
|
|
|
303
|
+
#### SMS routing
|
|
304
|
+
|
|
305
|
+
A DID's inbound messages go to an SMS trunk or to an SMS trunk group. The two are exclusive: assigning one clears the other in the same request, as `voice_in_trunk` and `voice_in_trunk_group` do.
|
|
306
|
+
|
|
307
|
+
```ruby
|
|
308
|
+
did = DIDWW::Client.dids.find('uuid').first
|
|
309
|
+
did.sms_trunk = DIDWW::Resource::SmsTrunk.load(id: 'sms-trunk-uuid')
|
|
310
|
+
did.save # sends sms_trunk and sms_trunk_group: null
|
|
311
|
+
|
|
312
|
+
did.sms_trunk_group = DIDWW::Resource::SmsTrunkGroup.load(id: 'sms-trunk-group-uuid')
|
|
313
|
+
did.save # sends sms_trunk_group and sms_trunk: null
|
|
314
|
+
|
|
315
|
+
DIDWW::Client.dids.where('sms_trunk.id': 'sms-trunk-uuid').all
|
|
316
|
+
```
|
|
317
|
+
|
|
192
318
|
### Voice In Trunks
|
|
193
319
|
|
|
194
320
|
```ruby
|
|
195
321
|
trunk = DIDWW::Client.voice_in_trunks.new(
|
|
196
322
|
name: 'My SIP Trunk',
|
|
197
|
-
|
|
198
|
-
|
|
323
|
+
pop: DIDWW::Resource::VoiceInTrunk::POP_AMS,
|
|
324
|
+
configuration: DIDWW::ComplexObject::SipConfiguration.new(
|
|
199
325
|
username: '{DID}',
|
|
200
326
|
host: 'sip.example.com',
|
|
201
|
-
port: 5060
|
|
202
|
-
|
|
327
|
+
port: 5060,
|
|
328
|
+
codecs: [
|
|
329
|
+
DIDWW::ComplexObject::SipConfiguration::CODEC_PCMA,
|
|
330
|
+
DIDWW::ComplexObject::SipConfiguration::CODEC_PCMU,
|
|
331
|
+
DIDWW::ComplexObject::SipConfiguration::CODEC_TELEPHONE_EVENT
|
|
332
|
+
],
|
|
333
|
+
ice_mode: DIDWW::ComplexObject::SipConfiguration::ICE_MODE_ACCEPT
|
|
334
|
+
)
|
|
203
335
|
)
|
|
204
336
|
|
|
205
337
|
trunk.save
|
|
206
338
|
```
|
|
207
339
|
|
|
340
|
+
`pop` is a plain attribute, one of `DIDWW::Resource::VoiceInTrunk::POPS` (`nyc`, `fra`, `lac`, `mia`, `sg`, `hk`, `ams`). Leave it `nil` to let DIDWW choose.
|
|
341
|
+
|
|
342
|
+
`codecs` lists the codecs offered on calls to the trunk by name, in priority order: the first has the highest priority. It replaces `codec_ids`; the names are `DIDWW::ComplexObject::SipConfiguration::CODECS`. Left out, the trunk offers `pcmu`, `pcma`, `g729`, `g723` and `telephone_event`. `ice_mode`, `rtcp_mux_mode` and `rtcp_feedback_mode` take `disabled` (the default), `accept` or `initiate` (`ICE_MODES`, `RTCP_MUX_MODES` and `RTCP_FEEDBACK_MODES` on `SipConfiguration`).
|
|
343
|
+
|
|
208
344
|
#### SIP Registration (2026-04-16)
|
|
209
345
|
|
|
210
346
|
A Voice In Trunk can also be configured to authenticate inbound calls
|
|
@@ -261,7 +397,12 @@ trunk = DIDWW::Client.voice_out_trunks.new(
|
|
|
261
397
|
on_cli_mismatch_action: 'reject_call',
|
|
262
398
|
authentication_method: DIDWW::ComplexObject::AuthenticationMethod::CredentialsAndIp.new(
|
|
263
399
|
allowed_sip_ips: ['203.0.113.0/24']
|
|
264
|
-
)
|
|
400
|
+
),
|
|
401
|
+
codecs: [
|
|
402
|
+
DIDWW::Resource::VoiceOutTrunk::CODEC_OPUS,
|
|
403
|
+
DIDWW::Resource::VoiceOutTrunk::CODEC_PCMA,
|
|
404
|
+
DIDWW::Resource::VoiceOutTrunk::CODEC_TELEPHONE_EVENT
|
|
405
|
+
]
|
|
265
406
|
)
|
|
266
407
|
|
|
267
408
|
trunk.save
|
|
@@ -269,16 +410,115 @@ trunk.save
|
|
|
269
410
|
# trunk.authentication_method.password -- server-generated
|
|
270
411
|
```
|
|
271
412
|
|
|
413
|
+
`codecs` lists the codecs offered on calls from the trunk by name, in priority order: the first has the highest priority. The names are `DIDWW::Resource::VoiceOutTrunk::CODECS`, which differ from those of an inbound SIP trunk. Left out, the trunk offers `pcma`, `pcmu` and `telephone_event`. `ice_mode`, `rtcp_mux_mode` and `rtcp_feedback_mode` take `disabled`, `accept` (the default) or `initiate` (`ICE_MODES`, `RTCP_MUX_MODES` and `RTCP_FEEDBACK_MODES` on `VoiceOutTrunk`).
|
|
414
|
+
|
|
415
|
+
### SMS Trunks
|
|
416
|
+
|
|
417
|
+
An SMS trunk delivers inbound messages, accepts outbound ones, or both. Its `configuration` is one of five types under `DIDWW::ComplexObject::SmsTrunkConfiguration`:
|
|
418
|
+
|
|
419
|
+
| Type | Class | Notes |
|
|
420
|
+
|------|-------|-------|
|
|
421
|
+
| `sms_to_email` | `SmsToEmail` | Inbound messages are forwarded as email. `send_to`, `subject` and `message` are required. |
|
|
422
|
+
| `http_in` | `HttpIn` | Inbound messages are sent as an HTTP request to your `url`. `http_method` is one of `HttpIn::HTTP_METHODS`; `post` and `put` also need `body_type` (one of `HttpIn::BODY_TYPES`) and `body`. |
|
|
423
|
+
| `http_out` | `HttpOut` | You submit outbound messages over HTTP. `auth_name` and `auth_password` are generated. The submit URL is `trunk.host`. |
|
|
424
|
+
| `smpp_esme` | `SmppEsme` | You bind to DIDWW as an SMPP ESME. `server_location` is required; `system_id` and `password` are generated. |
|
|
425
|
+
| `smpp_smsc` | `SmppSmsc` | DIDWW binds to your SMSC with your `host`, `system_id`, `password` and `server_location`. |
|
|
426
|
+
|
|
427
|
+
The read-only `allow_in` and `allow_out` tell which directions a trunk handles. `server_location` is one of `SmsTrunkConfiguration::SERVER_LOCATIONS`; the sandbox accepts `nyc` only. A configuration type this gem does not know is read as `SmsTrunkConfiguration::Generic` and sent back unchanged.
|
|
428
|
+
|
|
429
|
+
```ruby
|
|
430
|
+
configurations = DIDWW::ComplexObject::SmsTrunkConfiguration
|
|
431
|
+
|
|
432
|
+
trunk = DIDWW::Client.sms_trunks.new(
|
|
433
|
+
name: 'Inbound webhook',
|
|
434
|
+
configuration: configurations::HttpIn.new(
|
|
435
|
+
url: 'https://example.com/sms',
|
|
436
|
+
http_method: configurations::HttpIn::HTTP_METHOD_POST,
|
|
437
|
+
body_type: configurations::HttpIn::BODY_TYPE_JSON,
|
|
438
|
+
body: '{"text":"{SMS_TEXT}","from":"{SMS_SRC_ADDR}","to":"{SMS_DST_ADDR}"}'
|
|
439
|
+
)
|
|
440
|
+
)
|
|
441
|
+
trunk.save
|
|
442
|
+
|
|
443
|
+
# On update the configuration type must stay the same; attributes left out keep their values.
|
|
444
|
+
trunk.configuration = configurations::HttpIn.new(url: 'https://example.com/sms/v2')
|
|
445
|
+
trunk.save
|
|
446
|
+
|
|
447
|
+
# List by configuration type, with the group
|
|
448
|
+
DIDWW::Client.sms_trunks.where('configuration.type': 'http_in,sms_to_email').includes(:sms_trunk_group).all
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
The generated credentials of `http_out` and `smpp_esme` trunks are read-only and are never sent back on update. They are redacted in `#inspect`, as are the `headers` of an `http_in` configuration, which may carry the credentials of your endpoint, and every value of a configuration type this gem version does not know (`Generic`). To rotate them:
|
|
452
|
+
|
|
453
|
+
```ruby
|
|
454
|
+
trunk = DIDWW::Client.sms_trunks.find('uuid').first
|
|
455
|
+
trunk.regenerate_credentials # POST /sms_trunk_regenerate_credentials
|
|
456
|
+
trunk = DIDWW::Client.sms_trunks.find(trunk.id).first
|
|
457
|
+
trunk.configuration.password # the new password
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### SMS Trunk Groups
|
|
461
|
+
|
|
462
|
+
An SMS trunk group spreads a DID's inbound messages over its trunks by their `priority`. `http_out` trunks cannot join a group. Deleting a group also deletes the trunks in it.
|
|
463
|
+
|
|
464
|
+
```ruby
|
|
465
|
+
group = DIDWW::Client.sms_trunk_groups.new(name: 'Inbound SMS')
|
|
466
|
+
group.relationships.sms_trunks = [DIDWW::Resource::SmsTrunk.load(id: 'sms-trunk-uuid')]
|
|
467
|
+
group.save
|
|
468
|
+
group.sms_trunks_count # => 1
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### Sender ID Verifications
|
|
472
|
+
|
|
473
|
+
A Sender ID verification covers the sender IDs your outbound messages use. It is created and reviewed outside the API: the API lists and reads verifications, and changes only their `name` and the SMS trunk their messages are routed through. A `closed` verification cannot be changed. `status` is one of `SenderIdVerification::STATUSES` and `sender_type` one of `SenderIdVerification::SENDER_TYPES`; `meta` carries `setup_price` and `monthly_price` as decimal strings.
|
|
474
|
+
|
|
475
|
+
```ruby
|
|
476
|
+
verifications = DIDWW::Client.sender_id_verifications
|
|
477
|
+
.where(status: DIDWW::Resource::SenderIdVerification::STATUS_ACTIVE)
|
|
478
|
+
.includes(:sms_trunk)
|
|
479
|
+
.all
|
|
480
|
+
|
|
481
|
+
verification = verifications.first
|
|
482
|
+
verification.sms_trunk = DIDWW::Resource::SmsTrunk.load(id: 'sms-trunk-uuid') # http_out, smpp_esme or smpp_smsc
|
|
483
|
+
verification.save
|
|
484
|
+
|
|
485
|
+
verification.sms_trunk = nil # outbound messages stop until a trunk is assigned again
|
|
486
|
+
verification.save
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Deleting an SMS trunk leaves the verifications routed through it without a trunk.
|
|
490
|
+
|
|
491
|
+
### Exports
|
|
492
|
+
|
|
493
|
+
```ruby
|
|
494
|
+
export = DIDWW::Client.exports.new(
|
|
495
|
+
export_type: DIDWW::Resource::Export::EXPORT_TYPE_SMS_OUT,
|
|
496
|
+
filters: DIDWW::ComplexObject::ExportFilters.new(
|
|
497
|
+
from: '2026-10-01 00:00:00', # inclusive
|
|
498
|
+
to: '2026-10-02 00:00:00', # exclusive
|
|
499
|
+
service_type: DIDWW::ComplexObject::ExportFilters::SERVICE_TYPE_A2P,
|
|
500
|
+
sms_trunk_id: ['sms-trunk-uuid'] # sent as "sms_trunk.id"
|
|
501
|
+
)
|
|
502
|
+
)
|
|
503
|
+
export.save
|
|
504
|
+
|
|
505
|
+
# Once export.completed?
|
|
506
|
+
file = export.download # binary Tempfile with the gzipped CSV
|
|
507
|
+
csv = export.csv # StringIO with the decompressed CSV
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
`download` and `csv` send the API bearer token, so they accept only a `url` on the scheme, host and port of the API base URL or of the canonical API URL of `api_mode`, which the API builds export urls from even when `DIDWW_API_URL` points elsewhere. They raise `ArgumentError` for any other, without sending a request.
|
|
511
|
+
|
|
512
|
+
`from` and `to` are required for every export type. The other filter keys depend on `export_type` (`cdr_in`, `cdr_out`, `sms_in`, `sms_out`); see `DIDWW::ComplexObject::ExportFilters`. `sms_trunk_id`, `sender_id_verification_id` and `voice_out_trunk_id` are sent as the dotted keys `sms_trunk.id`, `sender_id_verification.id` and `voice_out_trunk.id`.
|
|
513
|
+
|
|
514
|
+
Filter values are lowercase: `service_type` is `a2p` or `p2p` (`ExportFilters::SERVICE_TYPES`), `trunk_type` is one or more of `smpp_smsc`, `smpp_esme`, `sms_to_email` and `http_in` (`ExportFilters::TRUNK_TYPES`), and `status` is `success`, `failed` or `queued` for `sms_in`, and `routing_error`, `in_progress`, `queued`, `failed` or `success` for `sms_out`.
|
|
515
|
+
|
|
272
516
|
### Orders
|
|
273
517
|
|
|
274
518
|
```ruby
|
|
275
519
|
order = DIDWW::Client.orders.new(
|
|
276
520
|
items: [
|
|
277
|
-
|
|
278
|
-
type: 'did_order_items',
|
|
279
|
-
sku_id: 'sku-uuid',
|
|
280
|
-
qty: 2
|
|
281
|
-
}
|
|
521
|
+
DIDWW::ComplexObject::DidOrderItem.new(sku_id: 'sku-uuid', qty: 2)
|
|
282
522
|
]
|
|
283
523
|
)
|
|
284
524
|
|
|
@@ -290,12 +530,12 @@ order.save
|
|
|
290
530
|
```ruby
|
|
291
531
|
# List emergency requirements with filters
|
|
292
532
|
requirements = DIDWW::Client.emergency_requirements
|
|
293
|
-
.includes(:country
|
|
533
|
+
.includes(:country)
|
|
294
534
|
.all
|
|
295
535
|
|
|
296
|
-
# Filter by country
|
|
536
|
+
# Filter by country and number type
|
|
297
537
|
requirements = DIDWW::Client.emergency_requirements
|
|
298
|
-
.where('country.id': 'country-uuid')
|
|
538
|
+
.where('country.id': 'country-uuid', number_type: 'local')
|
|
299
539
|
.all
|
|
300
540
|
|
|
301
541
|
requirements.each do |req|
|
|
@@ -305,13 +545,15 @@ requirements.each do |req|
|
|
|
305
545
|
puts req.requirement_restriction_message
|
|
306
546
|
end
|
|
307
547
|
|
|
308
|
-
# Create an emergency verification
|
|
548
|
+
# Create an emergency verification; relationships go under relationships:
|
|
309
549
|
verification = DIDWW::Client.emergency_verifications.new(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
DIDWW::Resource::
|
|
313
|
-
|
|
314
|
-
|
|
550
|
+
external_reference_id: 'my-ref-123',
|
|
551
|
+
relationships: {
|
|
552
|
+
address: DIDWW::Resource::Address.load(id: 'address-uuid'),
|
|
553
|
+
emergency_calling_service:
|
|
554
|
+
DIDWW::Resource::EmergencyCallingService.load(id: 'ecs-uuid'),
|
|
555
|
+
dids: [DIDWW::Resource::Did.load(id: 'did-uuid')]
|
|
556
|
+
}
|
|
315
557
|
)
|
|
316
558
|
|
|
317
559
|
if verification.save
|
|
@@ -322,11 +564,11 @@ end
|
|
|
322
564
|
|
|
323
565
|
# List emergency calling services
|
|
324
566
|
services = DIDWW::Client.emergency_calling_services
|
|
325
|
-
.includes(:country, :
|
|
567
|
+
.includes(:country, :dids)
|
|
326
568
|
.all
|
|
327
569
|
|
|
328
570
|
services.each do |svc|
|
|
329
|
-
puts "#{svc.name} — #{svc.status}"
|
|
571
|
+
puts "#{svc.name} — #{svc.status} (#{svc.number_type})"
|
|
330
572
|
end
|
|
331
573
|
|
|
332
574
|
# Cancel (destroy) an emergency calling service
|
|
@@ -361,9 +603,86 @@ recent = DIDWW::Client.did_history
|
|
|
361
603
|
.all
|
|
362
604
|
```
|
|
363
605
|
|
|
606
|
+
## Prices
|
|
607
|
+
|
|
608
|
+
Prices are served by three services outside the JSON:API (hosts in [Environments](#environments)). Each price list has a price file and a lookup:
|
|
609
|
+
|
|
610
|
+
| Accessor | Service | Price file | Lookup | Lookup rows |
|
|
611
|
+
|----------|---------|------------|--------|-------------|
|
|
612
|
+
| `DIDWW::Client.voice_in_prices` | Voice IN | `prices.csv.gz` | `lookup/prices` | `DIDWW::Prices::VoiceInPrice` |
|
|
613
|
+
| `DIDWW::Client.voice_out_prices` | Voice OUT | `prices.csv.gz` | `lookup/prices` | `DIDWW::Prices::VoiceOutPrice` |
|
|
614
|
+
| `DIDWW::Client.sms_out_a2p_prices` | SMS | `sms_out/a2p/prices.csv.gz` | `sms_out/a2p/lookup/prices` | `DIDWW::Prices::SmsOutPrice` |
|
|
615
|
+
| `DIDWW::Client.sms_out_p2p_prices` | SMS | `sms_out/p2p/prices.csv.gz` | `sms_out/p2p/lookup/prices` | `DIDWW::Prices::SmsOutPrice` |
|
|
616
|
+
| `DIDWW::Client.sms_out_otp_prices` | SMS | `sms_out/otp/prices.csv.gz` | `sms_out/otp/lookup/prices` | `DIDWW::Prices::SmsOutPrice` |
|
|
617
|
+
| `DIDWW::Client.sms_in_prices` | SMS | `sms_in/prices.csv.gz` | `sms_in/lookup/prices` | `DIDWW::Prices::SmsInPrice` |
|
|
618
|
+
|
|
619
|
+
Each accessor returns a `DIDWW::Prices::Service`. The account needs a price plan of that service: without one, every call raises `DIDWW::Prices::PricePlanNotAssigned`.
|
|
620
|
+
|
|
621
|
+
### Price lookups
|
|
622
|
+
|
|
623
|
+
```ruby
|
|
624
|
+
result = DIDWW::Client.voice_in_prices.lookup(number: '18005550123', src_country_iso: 'US')
|
|
625
|
+
result.total_records
|
|
626
|
+
result.each do |price|
|
|
627
|
+
puts "#{price.destination} #{price.source_type}: #{price.rate&.to_s('F')} USD/min"
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
DIDWW::Client.voice_out_prices.lookup(number: '493012345678').first.category
|
|
631
|
+
DIDWW::Client.sms_out_a2p_prices.lookup(dst_number: '4915123456789')
|
|
632
|
+
DIDWW::Client.sms_in_prices.lookup(dst_country_iso: 'US')
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
| Service | Filters |
|
|
636
|
+
|---------|---------|
|
|
637
|
+
| Voice IN | `number` (required), `src_country_iso` |
|
|
638
|
+
| Voice OUT | `number` (required); no other filter |
|
|
639
|
+
| SMS OUT and SMS IN | `dst_number`, `dst_country_iso`; at least one |
|
|
640
|
+
|
|
641
|
+
A missing or unknown filter raises `ArgumentError` before any request; blank values are dropped. The server checks the value formats and answers a bad value with 400 (`DIDWW::Prices::BadRequest`).
|
|
642
|
+
|
|
643
|
+
`lookup` returns a `DIDWW::Prices::LookupResult`, an `Enumerable` of price objects with `total_records` and `size`. Prices and fees are `BigDecimal`, `VoiceOutPrice#effective_at` is a `Time`, and `#to_h` returns every attribute. `VoiceOutPrice#category` is one of `DIDWW::Prices::VoiceOutPrice::CATEGORIES`.
|
|
644
|
+
|
|
645
|
+
The `id` of an SMS OUT or SMS IN lookup row is derived from its content: it changes when the row or its price changes, so do not use it to track a destination over time. A Voice OUT `id` names the answer by the plan, the prefix and the routing conditions, and stays the same when a re-import changes only the price. A Voice IN `id` names the answering row of the plan.
|
|
646
|
+
|
|
647
|
+
### Price files
|
|
648
|
+
|
|
649
|
+
The files are gzipped CSV. The SDK writes them exactly as served and never decompresses them.
|
|
650
|
+
|
|
651
|
+
```ruby
|
|
652
|
+
prices = DIDWW::Client.voice_out_prices
|
|
653
|
+
|
|
654
|
+
# Download unless the copy at the path is current
|
|
655
|
+
file = prices.fetch('/var/data/voice_out_prices.csv.gz')
|
|
656
|
+
file.modified? # true: downloaded; false: answered 304, the file was kept
|
|
657
|
+
file.last_modified # Time
|
|
658
|
+
file.bytes_written
|
|
659
|
+
|
|
660
|
+
# Read the rows
|
|
661
|
+
DIDWW::Prices.each_row('/var/data/voice_out_prices.csv.gz') do |row|
|
|
662
|
+
puts "#{row['Prefix']}: #{row['Rate']}"
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
# Lower-level calls
|
|
666
|
+
status = prices.head(if_modified_since: file.last_modified)
|
|
667
|
+
status.not_modified?
|
|
668
|
+
status.content_length
|
|
669
|
+
status.filename # from Content-Disposition, e.g. "voice_out_prices.csv.gz"
|
|
670
|
+
|
|
671
|
+
prices.download(to: '/tmp/voice_out_prices.csv.gz')
|
|
672
|
+
File.open('/tmp/copy.csv.gz', 'wb') { |io| prices.download(to: io) }
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
- `fetch(path)` sends the modification time of the file at `path` as `If-Modified-Since`, when the file is there. A file written by `download(to: path)` or `fetch` gets the `Last-Modified` of the response as its modification time, so the date matches the copy on disk. `fetch` trusts the modification time of any file at `path`: a file copied or changed by other means can be answered 304 and kept, so replace such a file with `download(to: path)`.
|
|
676
|
+
- `download(to:)` streams the body into an IO, or into a temp file `.didww-<16 hex digits>.tmp` in the directory of `path`, unique to the call, that is synced to disk and replaces `path` only on a 200. A 304 or an error leaves an existing file untouched, and concurrent downloads to one path do not mix their bytes. An IO target receives the body as it arrives, so after an error it may hold part of it.
|
|
677
|
+
- `head` and `download` return a `DIDWW::Prices::PriceFile`: `status`, `last_modified`, `content_length`, `filename`, `bytes_written`, `modified?` and `not_modified?`.
|
|
678
|
+
- The files have a header row, and `each_row` yields each row by its column names. Prices are in USD with VAT excluded. Voice IN: Country, Src country name, Source type, Destination, Rate, Connection fee, Initial interval, Next interval and Reject calls. Voice OUT: Category, Country, Network, Prefix (one prefix per row), Rate, Connection fee, Initial increment, Recurring increment, Reject calls, Next rate, Next connection fee, Next initial increment, Next recurring increment, Effective date and Comment. SMS OUT: Source prefix, Destination prefix, Country, MCC, MCC name, MNC, MNC name, Reject SMS (`true` or `false`) and Price. SMS IN: Source prefix, Source number length min, Source number length max, Destination prefix, Destination number length min, Destination number length max, Country and Price.
|
|
679
|
+
- Only `Last-Modified` and `If-Modified-Since` are used. The service sends no `ETag`, and the SDK never sends `If-None-Match`, which would make the service ignore `If-Modified-Since`.
|
|
680
|
+
- A 503 on a price file is retried up to 2 times when its `Retry-After` is 60 seconds or less, after waiting that long, at least 1 second, plus a random delay of up to a fifth of that wait (at least up to 1 s) so that clients do not retry in step. Otherwise it raises `DIDWW::Prices::ServiceUnavailable` with `retry_after`.
|
|
681
|
+
- Redirects are not followed. Any status the API does not document for the call, such as a 3xx or a 202, raises `DIDWW::Prices::UnexpectedStatus`. An error is never turned into an empty file or an empty result.
|
|
682
|
+
|
|
364
683
|
## Filter Reference
|
|
365
684
|
|
|
366
|
-
> See [`FILTERS.md`](FILTERS.md) for the
|
|
685
|
+
> See [`FILTERS.md`](FILTERS.md) for the list of `filter[KEY]` keys accepted by every list endpoint at API version `2026-11-19`.
|
|
367
686
|
|
|
368
687
|
## Error Handling
|
|
369
688
|
|
|
@@ -371,27 +690,70 @@ The SDK uses [json_api_client](https://github.com/JsonApiClient/json_api_client)
|
|
|
371
690
|
|
|
372
691
|
```ruby
|
|
373
692
|
# Validation errors (422 Unprocessable Entity)
|
|
374
|
-
trunk = DIDWW::Client.voice_in_trunks.new(
|
|
693
|
+
trunk = DIDWW::Client.voice_in_trunks.new(
|
|
694
|
+
name: 'Office',
|
|
695
|
+
ringing_timeout: 100, # more than the allowed 32 seconds
|
|
696
|
+
configuration: DIDWW::ComplexObject::SipConfiguration.new(host: 'sip.example.com')
|
|
697
|
+
)
|
|
375
698
|
unless trunk.save
|
|
376
699
|
trunk.errors.full_messages.each do |msg|
|
|
377
700
|
puts "Validation error: #{msg}"
|
|
378
701
|
end
|
|
379
702
|
end
|
|
380
703
|
|
|
381
|
-
# HTTP errors
|
|
704
|
+
# HTTP errors
|
|
382
705
|
begin
|
|
383
706
|
DIDWW::Client.dids.find('nonexistent-uuid')
|
|
384
707
|
rescue JsonApiClient::Errors::NotFound => e
|
|
385
708
|
puts "Not found: #{e.message}"
|
|
709
|
+
rescue JsonApiClient::Errors::NotAuthorized => e
|
|
710
|
+
puts "Token refused twice: #{e.message}"
|
|
386
711
|
rescue JsonApiClient::Errors::AccessDenied => e
|
|
387
|
-
puts "Access denied: #{e.message}"
|
|
712
|
+
puts "Access denied (e.g. a write with a read token): #{e.message}"
|
|
713
|
+
rescue JsonApiClient::Errors::TooManyRequests => e
|
|
714
|
+
puts "Rate limited, retry in #{e.retry_after.inspect} s: #{e.message}"
|
|
388
715
|
rescue JsonApiClient::Errors::ServerError => e
|
|
389
716
|
puts "Server error: #{e.message}"
|
|
390
717
|
rescue JsonApiClient::Errors::ConnectionError => e
|
|
391
718
|
puts "Connection error: #{e.message}"
|
|
719
|
+
rescue DIDWW::Auth::Error => e
|
|
720
|
+
puts "No access token: #{e.message} (status #{e.status}, retry after #{e.retry_after.inspect})"
|
|
392
721
|
end
|
|
393
722
|
```
|
|
394
723
|
|
|
724
|
+
`Export#download` raises the same `JsonApiClient::Errors` classes. It does not follow redirects: any status other than 200, such as a 3xx or 204, raises `JsonApiClient::Errors::UnexpectedStatus`.
|
|
725
|
+
|
|
726
|
+
A 429 (`too_many_requests`) means the request budget of the account for the current window is spent. Resource calls and `Export#download` raise it as `DIDWW::TooManyRequests`, a `JsonApiClient::Errors::TooManyRequests` whose `retry_after` is the `Retry-After` of the response in seconds (`nil` when it is missing or is an HTTP date). The SDK does not retry it, as a write may not be safe to send twice: wait `retry_after` seconds before sending the request again. `EncryptedFile.upload` raises `DIDWW::Resource::EncryptedFile::UploadError` for any status other than 201, with the `status` of the response; on a 429 its `retry_after` is the `Retry-After` in seconds (`nil` when it is missing or is an HTTP date), and the upload is not retried either.
|
|
727
|
+
|
|
728
|
+
Errors raised by the SDK itself inherit from `DIDWW::Error`, except `DIDWW::TooManyRequests` described above.
|
|
729
|
+
|
|
730
|
+
**Token service** (`DIDWW::Auth::Error`, with `status`, `error`, `error_description` and `retry_after`). They are raised from any call that needs a new token:
|
|
731
|
+
|
|
732
|
+
| Class | Raised when |
|
|
733
|
+
|-------|-------------|
|
|
734
|
+
| `DIDWW::Auth::InvalidClient` | 401: the API key is missing, unknown or disabled, or the caller's IP is not allowed. Not retried. |
|
|
735
|
+
| `DIDWW::Auth::InvalidRequest` | 400 `invalid_request` or `invalid_scope`. |
|
|
736
|
+
| `DIDWW::Auth::RateLimited` | 429. `retry_after` is the token service's `Retry-After` in seconds, at least 1. The SDK keeps refusing mints for a random extra of up to a fifth of it (at least up to 1 s) on top of it, and a mint refused in that window raises `RateLimited` with the seconds left, so retry in a loop rather than once. |
|
|
737
|
+
| `DIDWW::Auth::ServerError` | 5xx on every attempt. |
|
|
738
|
+
| `DIDWW::Auth::ConnectionError` | Connection failure or timeout on every attempt, or a TLS failure. |
|
|
739
|
+
| `DIDWW::Auth::InvalidGrant` | The token does not cover the requested audience. |
|
|
740
|
+
| `DIDWW::Auth::Error` | Any other status. |
|
|
741
|
+
|
|
742
|
+
**Prices** (`DIDWW::Prices::Error`, with `status`, `code`, `errors` and `retry_after`):
|
|
743
|
+
|
|
744
|
+
| Class | Status |
|
|
745
|
+
|-------|--------|
|
|
746
|
+
| `DIDWW::Prices::BadRequest` | 400, e.g. a filter value of the wrong format |
|
|
747
|
+
| `DIDWW::Prices::NotAuthorized` | 401 after the token was replaced once |
|
|
748
|
+
| `DIDWW::Prices::AccessDenied` | 403 |
|
|
749
|
+
| `DIDWW::Prices::PricePlanNotAssigned` | 404 `price_plan_not_assigned`; also any 404 on `head`, which has no body |
|
|
750
|
+
| `DIDWW::Prices::PriceNotFound` | 404 `price_not_found`: no price matches the lookup |
|
|
751
|
+
| `DIDWW::Prices::NotAcceptable` | 406 |
|
|
752
|
+
| `DIDWW::Prices::TooManyRequests` | 429, with `retry_after`. Not retried. |
|
|
753
|
+
| `DIDWW::Prices::ServiceUnavailable` | 503, with `retry_after`. Retried on price files only, see [Price files](#price-files). |
|
|
754
|
+
| `DIDWW::Prices::UnexpectedStatus` | Any other status |
|
|
755
|
+
| `DIDWW::Prices::ConnectionError` | Connection failure, timeout or TLS failure. Not retried. An error writing the file or IO is raised as it is. |
|
|
756
|
+
|
|
395
757
|
## Dirty Tracking
|
|
396
758
|
|
|
397
759
|
The SDK (via `json_api_client`) tracks which attributes have been modified. When you call `save` on a fetched resource, the resulting PATCH request sends only the changed attributes, avoiding unintended overwrites of server-side values.
|
|
@@ -409,13 +771,15 @@ The SDK distinguishes between date-only and datetime fields:
|
|
|
409
771
|
|
|
410
772
|
- **Datetime fields** — deserialized as `Time`:
|
|
411
773
|
- `created_at` — present on most resources
|
|
774
|
+
- `updated_at` — `SmsTrunk`, `SmsTrunkGroup`
|
|
412
775
|
- `expires_at` — `Did`, `DidReservation`, `Proof`, `EncryptedFile` (nullable)
|
|
413
|
-
- `activated_at` — `EmergencyCallingService` (nullable)
|
|
776
|
+
- `activated_at` — `EmergencyCallingService`, `SenderIdVerification` (nullable)
|
|
414
777
|
- `canceled_at` — `EmergencyCallingService` (nullable)
|
|
415
|
-
-
|
|
416
|
-
- `
|
|
417
|
-
- **Date-only fields kept as
|
|
418
|
-
- `CapacityPool#renew_date
|
|
778
|
+
- `closed_at` — `SenderIdVerification` (nullable)
|
|
779
|
+
- `effective_at` — `DIDWW::Prices::VoiceOutPrice` (nullable)
|
|
780
|
+
- **Date-only fields** — kept as the `String` the API sends, `"YYYY-MM-DD"`; use `Date.iso8601` when a `Date` is needed:
|
|
781
|
+
- `CapacityPool#renew_date`
|
|
782
|
+
- `EmergencyCallingService#renew_date`, `SenderIdVerification#renew_date`, `Identity#birth_date` (nullable)
|
|
419
783
|
- **String fields** (not numeric):
|
|
420
784
|
- `EmergencyRequirement#estimate_setup_time` — e.g. `"7-14 days"`, `"1"`
|
|
421
785
|
- `EmergencyRequirement#requirement_restriction_message` — nullable
|
|
@@ -431,7 +795,7 @@ puts did.created_at # => 2024-01-15 10:00:00 UTC (Time)
|
|
|
431
795
|
puts did.expires_at # => nil or 2025-01-15 10:00:00 UTC (Time)
|
|
432
796
|
|
|
433
797
|
identity = DIDWW::Client.identities.find("uuid").first
|
|
434
|
-
puts identity.birth_date # => 1990-05-20 (
|
|
798
|
+
puts identity.birth_date # => 1990-05-20 (String)
|
|
435
799
|
```
|
|
436
800
|
|
|
437
801
|
## Resource Relationships
|
|
@@ -442,10 +806,12 @@ See [docs/resource_relationships.md](docs/resource_relationships.md) for a Merma
|
|
|
442
806
|
|
|
443
807
|
Validate incoming webhook callbacks from DIDWW using HMAC-SHA1 signature verification.
|
|
444
808
|
|
|
809
|
+
Initialize the validator with the callback secret that is enabled in the DIDWW User Panel (**APIs → DIDWW API 3 → Callback Secrets**). DIDWW signs every callback with it and sends callbacks only while a callback secret is enabled.
|
|
810
|
+
|
|
445
811
|
```ruby
|
|
446
812
|
require 'didww/callback/request_validator'
|
|
447
813
|
|
|
448
|
-
validator = DIDWW::Callback::RequestValidator.new("
|
|
814
|
+
validator = DIDWW::Callback::RequestValidator.new("YOUR_CALLBACK_SECRET")
|
|
449
815
|
|
|
450
816
|
# In your webhook handler:
|
|
451
817
|
valid = validator.validate(
|
|
@@ -464,7 +830,7 @@ class WebhooksController < ApplicationController
|
|
|
464
830
|
skip_before_action :verify_authenticity_token
|
|
465
831
|
|
|
466
832
|
def create
|
|
467
|
-
validator = DIDWW::Callback::RequestValidator.new("
|
|
833
|
+
validator = DIDWW::Callback::RequestValidator.new("YOUR_CALLBACK_SECRET")
|
|
468
834
|
signature = request.headers[DIDWW::Callback::RequestValidator::HEADER]
|
|
469
835
|
params_hash = request.POST
|
|
470
836
|
|
|
@@ -486,10 +852,17 @@ The SDK provides constants for all API option fields. These are defined as const
|
|
|
486
852
|
`OnCliMismatchAction`\*, `MediaEncryptionMode`, `DefaultDstAction`, `VoiceOutTrunkStatus`,
|
|
487
853
|
`EmergencyCallingServiceStatus`, `EmergencyVerificationStatus`, `DiversionRelayPolicy`,
|
|
488
854
|
`TransportProtocol`, `Codec`, `RxDtmfFormat`, `TxDtmfFormat`, `SstRefreshMethod`,
|
|
489
|
-
`ReroutingDisconnectCode`, `Feature`, `AreaLevel`, `AddressVerificationStatus`, `StirShakenMode
|
|
855
|
+
`ReroutingDisconnectCode`, `Feature`, `AreaLevel`, `AddressVerificationStatus`, `StirShakenMode`,
|
|
856
|
+
`NumberType`, `Pop`, `ExportSmsTrunkType`, `ExportSmsServiceType`, `SmsHttpMethod`, `SmsBodyType`,
|
|
857
|
+
`SmsServerLocation`, `VoiceOutPriceCategory`, `SenderIdVerificationStatus`, `SenderIdVerificationSenderType`,
|
|
858
|
+
`IceMode`, `RtcpMuxMode`, `RtcpFeedbackMode`
|
|
490
859
|
|
|
491
860
|
\* `REPLACE_CLI` and `RANDOMIZE_CLI` require additional account configuration. Contact DIDWW support to enable these values.
|
|
492
861
|
|
|
862
|
+
The constants for `NumberType`, `Pop`, `ExportSmsTrunkType`, `ExportSmsServiceType`, `SmsHttpMethod`, `SmsBodyType`, `SmsServerLocation`, `VoiceOutPriceCategory`, `SenderIdVerificationStatus` and `SenderIdVerificationSenderType` are `DIDWW::Resource::NumberTypes::NUMBER_TYPES`, `DIDWW::Resource::VoiceInTrunk::POPS`, `DIDWW::ComplexObject::ExportFilters::TRUNK_TYPES` and `SERVICE_TYPES`, `DIDWW::ComplexObject::SmsTrunkConfiguration::HttpIn::HTTP_METHODS` and `BODY_TYPES`, `DIDWW::ComplexObject::SmsTrunkConfiguration::SERVER_LOCATIONS`, `DIDWW::Prices::VoiceOutPrice::CATEGORIES`, and `DIDWW::Resource::SenderIdVerification::STATUSES` and `SENDER_TYPES`.
|
|
863
|
+
|
|
864
|
+
`Codec`, `IceMode`, `RtcpMuxMode` and `RtcpFeedbackMode` are `CODECS`, `ICE_MODES`, `RTCP_MUX_MODES` and `RTCP_FEEDBACK_MODES`, with one constant per value (`CODEC_PCMA`, `ICE_MODE_ACCEPT`, ...), on `DIDWW::ComplexObject::SipConfiguration` for inbound SIP trunks and on `DIDWW::Resource::VoiceOutTrunk` for outbound trunks. The two codec lists differ.
|
|
865
|
+
|
|
493
866
|
## Development
|
|
494
867
|
|
|
495
868
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|