Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ DIDWW_API_KEY=your_api_key ./gradlew runExample -PexampleClass=com.didww.example
| [`com.didww.examples.SharedCapacityGroupsExample`](src/main/java/com/didww/examples/SharedCapacityGroupsExample.java) | Creates a shared capacity group in a capacity pool. |
| [`com.didww.examples.OrdersExample`](src/main/java/com/didww/examples/OrdersExample.java) | Lists orders and creates/cancels a DID order using live SKU lookup. |
| [`com.didww.examples.OrdersSkuExample`](src/main/java/com/didww/examples/OrdersSkuExample.java) | Creates a DID order by SKU resolved from DID groups. |
| [`com.didww.examples.OrdersNanpaExample`](src/main/java/com/didww/examples/OrdersNanpaExample.java) | Orders a DID number by NPA/NXX prefix. |
| [`com.didww.examples.OrdersCapacityExample`](src/main/java/com/didww/examples/OrdersCapacityExample.java) | Purchases capacity by creating a capacity order item. |
| [`com.didww.examples.OrdersAvailableDidsExample`](src/main/java/com/didww/examples/OrdersAvailableDidsExample.java) | Orders an available DID using included DID group SKU. |
| [`com.didww.examples.OrdersReservationDidsExample`](src/main/java/com/didww/examples/OrdersReservationDidsExample.java) | Reserves a DID and then places an order from that reservation. |
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/java/com/didww/examples/BalanceExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {
System.out.println("Credit: " + toPlainString(balance.getCredit()));
}

private static String toPlainString(Double value) {
return value == null ? "null" : BigDecimal.valueOf(value).toPlainString();
private static String toPlainString(BigDecimal value) {
return value == null ? "null" : value.toPlainString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,37 @@ public static void main(String[] args) {

try {
// 1. Assign trunk to DID (auto-nullifies trunk group)
Did update1 = Did.build(did.getId());
update1.setVoiceInTrunk(VoiceInTrunk.build(trunkId));
Did update1 = new Did().withId(did.getId());
update1.setVoiceInTrunk(new VoiceInTrunk().withId(trunkId));
client.dids().update(update1);
System.out.println("\n1. Assigned trunk:");
printDidAssignment(client, did.getId());

// 2. Assign trunk group to DID (auto-nullifies trunk)
Did update2 = Did.build(did.getId());
update2.setVoiceInTrunkGroup(VoiceInTrunkGroup.build(groupId));
Did update2 = new Did().withId(did.getId());
update2.setVoiceInTrunkGroup(new VoiceInTrunkGroup().withId(groupId));
client.dids().update(update2);
System.out.println("\n2. Assigned trunk group:");
printDidAssignment(client, did.getId());

// 3. Re-assign trunk (auto-nullifies trunk group again)
Did update3 = Did.build(did.getId());
update3.setVoiceInTrunk(VoiceInTrunk.build(trunkId));
Did update3 = new Did().withId(did.getId());
update3.setVoiceInTrunk(new VoiceInTrunk().withId(trunkId));
client.dids().update(update3);
System.out.println("\n3. Re-assigned trunk:");
printDidAssignment(client, did.getId());

// 4. Unassign: update description only (trunk stays assigned)
Did update4 = Did.build(did.getId());
Did update4 = new Did().withId(did.getId());
update4.setDescription("DID with trunk assigned");
client.dids().update(update4);
System.out.println("\n4. Updated description only (trunk stays):");
printDidAssignment(client, did.getId());
} finally {
// Cleanup: reassign DID to group (frees trunk), delete trunk, then delete group
try {
Did cleanup = Did.build(did.getId());
cleanup.setVoiceInTrunkGroup(VoiceInTrunkGroup.build(groupId));
Did cleanup = new Did().withId(did.getId());
cleanup.setVoiceInTrunkGroup(new VoiceInTrunkGroup().withId(groupId));
client.dids().update(cleanup);
} catch (Exception ignored) {}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public static void main(String[] args) throws Exception {
address.setCityName("New York");
address.setPostalCode("10001");
address.setAddress("123 Main St");
address.setIdentity(Identity.build(identity.getId()));
address.setCountry(Country.build(country.getId()));
address.setIdentity(identity);
address.setCountry(country);
address = client.addresses().create(address).getData();
System.out.println("Created address: " + address.getId() + " (" + address.getAddress() + ")");

Expand Down Expand Up @@ -106,9 +106,9 @@ public static void main(String[] args) throws Exception {
// --- Step 6: Create proof for identity ---
if (identityProofType != null) {
Proof identityProof = new Proof();
identityProof.setEntity(Identity.build(identity.getId()));
identityProof.setProofType(ProofType.build(identityProofType.getId()));
identityProof.setFiles(Arrays.asList(EncryptedFile.build(fileIds1.get(0))));
identityProof.setEntity(identity);
identityProof.setProofType(identityProofType);
identityProof.setFiles(Arrays.asList(new EncryptedFile().withId(fileIds1.get(0))));

QueryParams params = QueryParams.builder().include("proof_type").build();
Proof createdProof = client.proofs().create(identityProof, params).getData();
Expand All @@ -119,9 +119,9 @@ public static void main(String[] args) throws Exception {
// --- Step 7: Create proof for address ---
if (addressProofType != null) {
Proof addressProof = new Proof();
addressProof.setEntity(Address.build(address.getId()));
addressProof.setProofType(ProofType.build(addressProofType.getId()));
addressProof.setFiles(Arrays.asList(EncryptedFile.build(fileIds2.get(0))));
addressProof.setEntity(address);
addressProof.setProofType(addressProofType);
addressProof.setFiles(Arrays.asList(new EncryptedFile().withId(fileIds2.get(0))));

QueryParams params = QueryParams.builder().include("proof_type").build();
Proof createdProof = client.proofs().create(addressProof, params).getData();
Expand Down
63 changes: 63 additions & 0 deletions examples/src/main/java/com/didww/examples/OrdersNanpaExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.didww.examples;

import com.didww.sdk.DidwwClient;
import com.didww.sdk.http.QueryParams;
import com.didww.sdk.resource.DidGroup;
import com.didww.sdk.resource.NanpaPrefix;
import com.didww.sdk.resource.Order;
import com.didww.sdk.resource.orderitem.DidOrderItem;

import java.util.Collections;
import java.util.List;

public class OrdersNanpaExample {

public static void main(String[] args) {
DidwwClient client = ExampleClientFactory.fromEnv();

// Step 1: find the NANPA prefix by NPA/NXX (e.g. 201-221)
QueryParams nanpaParams = QueryParams.builder()
.filter("npanxx", "201221")
.page(1, 1)
.build();
List<NanpaPrefix> nanpaPrefixes = client.nanpaPrefixes().list(nanpaParams).getData();
if (nanpaPrefixes.isEmpty()) {
throw new IllegalStateException("NANPA prefix 201-221 not found");
}
NanpaPrefix nanpaPrefix = nanpaPrefixes.get(0);
System.out.println("NANPA prefix: " + nanpaPrefix.getId()

Check warning on line 28 in examples/src/main/java/com/didww/examples/OrdersNanpaExample.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of System.out by a logger.

See more on https://sonarcloud.io/project/issues?id=didww_didww-api-3-java-sdk&issues=AZzo0npjauI_4q9oq19z&open=AZzo0npjauI_4q9oq19z&pullRequest=45
+ " NPA=" + nanpaPrefix.getNpa() + " NXX=" + nanpaPrefix.getNxx());

// Step 2: find a DID group for this prefix and load its SKUs
QueryParams dgParams = QueryParams.builder()
.filter("nanpa_prefix.id", nanpaPrefix.getId())
.include("stock_keeping_units")
.page(1, 1)
.build();
List<DidGroup> didGroups = client.didGroups().list(dgParams).getData();
if (didGroups.isEmpty()
|| didGroups.get(0).getStockKeepingUnits() == null
|| didGroups.get(0).getStockKeepingUnits().isEmpty()) {
throw new IllegalStateException("No DID group with SKUs found for this NANPA prefix");
}
DidGroup didGroup = didGroups.get(0);
String skuId = didGroup.getStockKeepingUnits().get(0).getId();
System.out.println("DID group: " + didGroup.getId() + " SKU: " + skuId);

Check warning on line 45 in examples/src/main/java/com/didww/examples/OrdersNanpaExample.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of System.out by a logger.

See more on https://sonarcloud.io/project/issues?id=didww_didww-api-3-java-sdk&issues=AZzo0npjauI_4q9oq190&open=AZzo0npjauI_4q9oq190&pullRequest=45

// Step 3: create the order
DidOrderItem item = new DidOrderItem();
item.setSkuId(skuId);
item.setNanpaPrefixId(nanpaPrefix.getId());
item.setQty(1);

Order order = new Order();
order.setAllowBackOrdering(true);
order.setItems(Collections.singletonList(item));

Order created = client.orders().create(order).getData();
System.out.println("Order " + created.getId()

Check warning on line 58 in examples/src/main/java/com/didww/examples/OrdersNanpaExample.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of System.out by a logger.

See more on https://sonarcloud.io/project/issues?id=didww_didww-api-3-java-sdk&issues=AZzo0npjauI_4q9oq191&open=AZzo0npjauI_4q9oq191&pullRequest=45
+ " amount=" + created.getAmount()
+ " status=" + created.getStatus()
+ " ref=" + created.getReference());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public static void main(String[] args) {
VoiceInTrunkGroup group = new VoiceInTrunkGroup();
group.setName("My Trunk Group " + suffix);
group.setCapacityLimit(10);
group.setVoiceInTrunks(Arrays.asList(
VoiceInTrunk.build(trunkA.getId()),
VoiceInTrunk.build(trunkB.getId())
));
group.setVoiceInTrunks(Arrays.asList(trunkA, trunkB));
group = client.voiceInTrunkGroups().create(group).getData();
System.out.println("Created trunk group: " + group.getId() + " - " + group.getName());

Expand Down
Loading