Repository navigation
Align the examples with the shared example set - #74
Conversation
The SDKs keep one example set with the same names and behaviour. CapacityPoolsExample now also finds a pool by ID, SharedCapacityGroupsExample lists, renames and deletes the group it creates, OrdersExample lists the most recent orders, and TrunksExample finds the SIP trunk by ID and updates the PSTN trunk as well. DidReservationsExample deletes its reservation also when a step fails, OrdersAllItemTypesExample explains why a capacity item cannot join the DID items of one order, and UploadFileExample prints the encrypted file ID as such.
IncludesExample reads regions with their country, DID groups with their SKUs, available DIDs with a nested include and DIDs with their Voice IN trunk, and shows that a relationship that is not included reads as null. WebhookExample signs a sample callback the way DIDWW does and RequestValidator checks it, so the genuine signature validates and the same signature on a changed payload does not.
TestReadmeExample runs one check per README snippet, or per section where the snippets belong together, records each failure with its error and goes on. Resources a check creates are deleted, and DID routing or a Sender ID verification it changes is restored, in a finally block. Production-only snippets and those DIDWW staff must review are reported as skipped with the reason. It prints 'Results: N passed, M failed' and exits with status 1 on a failure. ExampleClientFactory gains a builder with the sandbox credentials so that a check can configure scope, logger, token store or HTTP client, and UploadFileExample shares its sample PDF writer.
The table now holds every example once, in the order the SDKs share, with what each one does today, including the new IncludesExample, WebhookExample and TestReadmeExample. It also names the examples that delete what they create or restore what they change.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
🟡 Changes recommended
Cancellation errors can be swallowed, falsely reporting success despite failed cleanup, and accounts without Voice OUT configuration are treated as failures instead of skips.
2 open issues
What changed in this PR
Aligns the Java SDK examples with the shared 41-example set, expanding demonstrations and adding a sandbox runner for README snippets.
Changes:
- Adds relationship-inclusion, webhook-validation, and README-check examples.
- Extends existing examples with lookups, updates, cleanup, and clearer output.
- Adds a configurable example-client builder and reorganizes the example catalog.
| File | Description |
|---|---|
examples/src/main/java/com/didww/examples/WebhookExample.java |
Demonstrates valid and tampered callback signatures without API requests. |
examples/src/main/java/com/didww/examples/UploadFileExample.java |
Prints the encrypted file ID and exposes the PDF helper for reuse. |
examples/src/main/java/com/didww/examples/TrunksExample.java |
Adds SIP lookup, PSTN updates, and cleanup of both trunks. |
examples/src/main/java/com/didww/examples/TestReadmeExample.java |
Adds sandbox README checks with cleanup, skips, and result reporting. |
examples/src/main/java/com/didww/examples/SharedCapacityGroupsExample.java |
Adds listing, renaming, and cleanup of the created group. |
examples/src/main/java/com/didww/examples/OrdersExample.java |
Lists recent orders first and broadens SKU lookup. |
examples/src/main/java/com/didww/examples/OrdersAllItemTypesExample.java |
Clarifies in comments why capacity items require a separate order. |
examples/src/main/java/com/didww/examples/IncludesExample.java |
Demonstrates direct and nested relationship inclusion. |
examples/src/main/java/com/didww/examples/ExampleClientFactory.java |
Exposes a sandbox client builder for custom configuration. |
examples/src/main/java/com/didww/examples/DidReservationsExample.java |
Moves reservation deletion into a finally block. |
examples/src/main/java/com/didww/examples/CapacityPoolsExample.java |
Adds lookup by ID with included pricing. |
examples/README.md |
Lists the 41 examples in shared order and documents their behavior. |
Review effort: Balanced
…rivate The Voice OUT trunk check first lists trunks: the API answers every Voice OUT request with 403 while the feature is not enabled for the account, so that is reported as skipped, and an error of the create itself still fails the check. A refused order cancellation now fails the check unless the reloaded order is no longer pending. Downloaded and generated files go to a temporary directory only the current user can open. WebhookExample keeps HMAC-SHA1, the algorithm DIDWW signs callbacks with, and says so for static analysis.
…ng them The address verification check now takes a Ukrainian DID awaiting registration, or orders one, builds an identity and address with the mandatory fields, proofs and documents of the address requirement, validates them, creates the verification and updates its external reference. The emergency verification check takes or orders an emergency-capable DID and creates the verification with an account address that meets the emergency requirement. Both print a REVIEW line with the verification ID and reference; the verifications and what they reference are kept, as the API cannot delete them. The HTTP client check sends sandbox requests through the proxy of DIDWW_README_PROXY_URL and checks the connections used it. The token store check stores tokens in the Redis of DIDWW_README_REDIS_URL through a minimal Redis client, so no Redis library is needed, and a second client reuses the token the first one stored. Either check is skipped when its variable is not set.
Only some Ukrainian local DID groups have an address requirement, and it shows only with include=address_requirement, while whether a DID awaits registration depends on the account's registration rules. The check now lists those groups with the include, reuses an active DID of one of them without an address verification or orders one, and reads the requirement by the ID the group gives.
An earlier verification binds a DID to the identity of its address, and the API then accepts the DID only with that identity's address. The emergency verification check now includes the DID's identity and takes a DID without one, without an emergency calling service and without an emergency verification, or orders a new one.
An order by SKU is refused with 'exceeds available DIDs count' when the SKU's DID group has no numbers in stock. OrdersExample, OrdersSkuExample, OrdersAllItemTypesExample and TestReadmeExample now pick the SKU from a group listed with filter[is_available]=true.
The sandbox sometimes needs more than a minute to complete a DID order, so EmergencyScenarioExample and the README checks that order a DID now poll 24 times, 5 seconds apart, before giving up.
When DIDWW_README_PRODUCTION_API_KEY is set, the production client check builds the README's production client with the read scope added, so the token service issues a read-only token and production refuses any write. It reads the balance, a page of countries and one Voice IN price, and prints only that these calls succeeded. Without the variable the check is skipped.
Static analysis cannot see that require() throws, so it reported a possible null access to the SKU list. The helper now throws the same IllegalStateException itself before using the list. Two port fallbacks are written without a negated condition.
…on checks A DID order placed for a verification check is now cancelled at cleanup when the check stops before the order completes, so a time-out, a failed read or an interrupt no longer leaves it to provision a DID later. A file uploaded for a proof or permanent document is deleted when that proof or document is not created; files that proofs hold stay. An account without a Ukrainian address that meets the emergency requirement now reports the emergency verification check as skipped, as for other missing account data, instead of failing it.
|
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because Redis connection handling can send credentials without TLS for secure URLs, with additional authentication and sandbox-result reporting concerns.
No open issues 🎉
3 resolved since last review
Review effort: Balanced




Summary
The seven DIDWW API v3 SDKs now share one set of 41 examples, with the same names and the same behaviour. This PR brings the Java examples in line with that set.
New examples
IncludesExample: reads resources with included relationships, and shows that a relationship you do not include comes back asnull.WebhookExample: signs a sample callback the wayRequestValidatorchecks it. It printsvalid: truefor that callback andvalid: falsefor a tampered payload.TestReadmeExample: one check per README snippet, 56 checks, on the sandbox only. It deletes what it creates and restores what it changes. It printsResults: N passed, M failedand exits 1 when a check fails. Snippets the sandbox cannot run are reported as skipped, each with the reason.Existing examples, aligned
TrunksExamplenow also finds the SIP trunk and updates the PSTN trunk.SharedCapacityGroupsExamplelists, renames and deletes the group it creates.CapacityPoolsExamplefinds a pool by id.DidReservationsExampledeletes the reservation even when a step fails.OrdersExamplelists recent orders first.UploadFileExampleprints the encrypted file id.OrdersAllItemTypesExampleheader says why capacity items need an order of their own.Supporting changes
ExampleClientFactoryhas abuilder(), whichTestReadmeExampleneeds to build clients the way the README does.examples/README.mdlists the 41 examples in the shared order.Tests
./gradlew compileExamplesJavapasses, andjavac -Xlint:allgives no warnings on the example sources.