didww-v3 6.2.1 → 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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +8 -6
  3. data/.rubocop.yml +0 -110
  4. data/CHANGELOG.md +61 -0
  5. data/FILTERS.md +36 -12
  6. data/Gemfile +0 -2
  7. data/README.md +427 -56
  8. data/didww-v3.gemspec +11 -8
  9. data/docs/resource_relationships.md +35 -15
  10. data/examples/README.md +54 -61
  11. data/examples/capacity_pools.rb +28 -10
  12. data/examples/countries.rb +1 -1
  13. data/examples/did_groups.rb +1 -1
  14. data/examples/did_reservations.rb +35 -37
  15. data/examples/did_sms_routing.rb +91 -0
  16. data/examples/did_trunk_assignment.rb +106 -80
  17. data/examples/emergency_calling_services.rb +3 -3
  18. data/examples/emergency_requirements.rb +3 -3
  19. data/examples/emergency_scenario.rb +11 -11
  20. data/examples/emergency_verifications.rb +7 -5
  21. data/examples/exports.rb +1 -1
  22. data/examples/exports_sms.rb +72 -0
  23. data/examples/identity_address_proofs.rb +118 -0
  24. data/examples/includes.rb +65 -0
  25. data/examples/orders.rb +8 -6
  26. data/examples/orders_all_item_types.rb +63 -125
  27. data/examples/orders_emergency.rb +3 -3
  28. data/examples/{orders_by_sku.rb → orders_sku.rb} +12 -10
  29. data/examples/prices_download.rb +45 -0
  30. data/examples/prices_lookup.rb +43 -0
  31. data/examples/regions.rb +1 -1
  32. data/examples/sample.pdf +14 -0
  33. data/examples/sender_id_verifications.rb +63 -0
  34. data/examples/shared_capacity_groups.rb +44 -35
  35. data/examples/sms_trunk_groups.rb +71 -0
  36. data/examples/sms_trunks.rb +84 -0
  37. data/examples/test_readme.rb +1216 -0
  38. data/examples/trunks.rb +115 -0
  39. data/examples/upload_file.rb +44 -0
  40. data/examples/voice_in_trunk_groups.rb +57 -33
  41. data/examples/voice_in_trunk_sip_registration.rb +4 -1
  42. data/examples/voice_out_trunks.rb +11 -1
  43. data/examples/webhook.rb +51 -0
  44. data/lib/didww/auth/bearer_middleware.rb +74 -0
  45. data/lib/didww/auth/memory_store.rb +40 -0
  46. data/lib/didww/auth/token.rb +45 -0
  47. data/lib/didww/auth/token_provider.rb +215 -0
  48. data/lib/didww/base_middleware.rb +7 -8
  49. data/lib/didww/callback/request_validator.rb +2 -1
  50. data/lib/didww/client.rb +122 -13
  51. data/lib/didww/complex_objects/authentication_methods/generic.rb +6 -0
  52. data/lib/didww/complex_objects/configurations/base.rb +0 -18
  53. data/lib/didww/complex_objects/configurations/pstn_configuration.rb +0 -4
  54. data/lib/didww/complex_objects/configurations/sip_configuration.rb +86 -38
  55. data/lib/didww/complex_objects/emergency_order_item.rb +1 -1
  56. data/lib/didww/complex_objects/export_filters.rb +72 -6
  57. data/lib/didww/complex_objects/generic_order_item.rb +15 -0
  58. data/lib/didww/complex_objects/sms_trunk_configuration.rb +33 -0
  59. data/lib/didww/complex_objects/sms_trunk_configurations/base.rb +26 -0
  60. data/lib/didww/complex_objects/sms_trunk_configurations/generic.rb +32 -0
  61. data/lib/didww/complex_objects/sms_trunk_configurations/http_in.rb +75 -0
  62. data/lib/didww/complex_objects/sms_trunk_configurations/http_out.rb +35 -0
  63. data/lib/didww/complex_objects/sms_trunk_configurations/smpp_esme.rb +37 -0
  64. data/lib/didww/complex_objects/sms_trunk_configurations/smpp_smsc.rb +56 -0
  65. data/lib/didww/complex_objects/sms_trunk_configurations/sms_to_email.rb +27 -0
  66. data/lib/didww/errors.rb +103 -0
  67. data/lib/didww/http.rb +34 -0
  68. data/lib/didww/prices/lookup_result.rb +37 -0
  69. data/lib/didww/prices/price.rb +56 -0
  70. data/lib/didww/prices/price_file.rb +51 -0
  71. data/lib/didww/prices/service.rb +248 -0
  72. data/lib/didww/prices/sms_in_price.rb +43 -0
  73. data/lib/didww/prices/sms_out_price.rb +52 -0
  74. data/lib/didww/prices/voice_in_price.rb +48 -0
  75. data/lib/didww/prices/voice_out_price.rb +88 -0
  76. data/lib/didww/prices.rb +82 -0
  77. data/lib/didww/resource/address_requirement.rb +13 -3
  78. data/lib/didww/resource/base.rb +5 -2
  79. data/lib/didww/resource/concerns/number_types.rb +24 -0
  80. data/lib/didww/resource/did.rb +42 -3
  81. data/lib/didww/resource/did_group.rb +12 -1
  82. data/lib/didww/resource/emergency_calling_service.rb +10 -5
  83. data/lib/didww/resource/emergency_requirement.rb +27 -14
  84. data/lib/didww/resource/encrypted_file.rb +19 -6
  85. data/lib/didww/resource/export.rb +59 -12
  86. data/lib/didww/resource/identity.rb +9 -4
  87. data/lib/didww/resource/order.rb +1 -0
  88. data/lib/didww/resource/proof_type.rb +1 -1
  89. data/lib/didww/resource/sender_id_verification.rb +114 -0
  90. data/lib/didww/resource/sms_trunk.rb +76 -0
  91. data/lib/didww/resource/sms_trunk_group.rb +31 -0
  92. data/lib/didww/resource/sms_trunk_regenerate_credential.rb +16 -0
  93. data/lib/didww/resource/voice_in_trunk.rb +24 -1
  94. data/lib/didww/resource/voice_out_trunk.rb +72 -0
  95. data/lib/didww/types/ip_addresses.rb +1 -1
  96. data/lib/didww/types/strings.rb +1 -1
  97. data/lib/didww/types.rb +3 -1
  98. data/lib/didww/version.rb +1 -1
  99. data/lib/didww.rb +7 -0
  100. metadata +62 -24
  101. data/examples/identities_and_proofs.rb +0 -67
  102. data/examples/voice_in_trunks.rb +0 -108
  103. data/lib/didww/resource/did_group_type.rb +0 -10
  104. data/lib/didww/resource/exclusive_relationship.rb +0 -54
  105. data/lib/didww/resource/pop.rb +0 -10
data/didww-v3.gemspec CHANGED
@@ -24,16 +24,19 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = '>= 3.3'
26
26
 
27
- # Lower bounds match the oldest version verified by CI; upper bounds
28
- # cap on the next known-incompatible major so consumers get a clear
29
- # constraint failure rather than a runtime surprise. The CI matrix in
30
- # .github/workflows/tests.yml exercises activesupport ~> 7.2 / 8.0 /
31
- # 8.1 — declaring a wider lower bound than that would be aspirational.
27
+ # Upper bounds cap on the next known-incompatible major so consumers get
28
+ # a clear constraint failure rather than a runtime surprise. The CI matrix
29
+ # in .github/workflows/tests.yml exercises activesupport ~> 8.0 / 8.1;
30
+ # the `>= 7.2` floor is kept deliberately — 7.2 is no longer tested, but
31
+ # raising a runtime floor is a breaking change for consumers and nothing
32
+ # indicates the gem stopped working there.
32
33
  spec.add_dependency 'activesupport', '>= 7.2', '< 9'
33
- spec.add_dependency 'faraday', '~> 2.0'
34
+ spec.add_dependency 'csv', '~> 3.0'
35
+ spec.add_dependency 'faraday', '~> 2.5'
36
+ # Streamed downloads read the response status in on_data, which the
37
+ # Net::HTTP adapter provides from 3.0.
38
+ spec.add_dependency 'faraday-net_http', '>= 3.0'
34
39
  spec.add_dependency 'faraday-multipart', '~> 1.0'
35
40
  spec.add_dependency 'json_api_client', '~> 1.23'
36
- spec.add_dependency 'http', '~> 5.0'
37
- spec.add_dependency 'down', '~> 5.0'
38
41
  spec.add_dependency 'openssl-oaep', '~> 0.1'
39
42
  end
@@ -17,7 +17,7 @@ erDiagram
17
17
 
18
18
  AddressVerification ||--o| Address : "has_one address"
19
19
  AddressVerification ||--o{ Did : "has_many dids"
20
- AddressVerification ||--o{ EncryptedFile : "has_many onetime_files"
20
+ AddressVerification ||--o{ EncryptedFile : "has_many onetime_files (create only)"
21
21
 
22
22
  Area ||--o| Country : "has_one country"
23
23
 
@@ -41,10 +41,11 @@ erDiagram
41
41
  Did ||--o| CapacityPool : "has_one capacity_pool"
42
42
  Did ||--o| SharedCapacityGroup : "has_one shared_capacity_group"
43
43
  Did ||--o| AddressVerification : "has_one address_verification"
44
+ Did ||--o| SmsTrunk : "has_one sms_trunk"
45
+ Did ||--o| SmsTrunkGroup : "has_one sms_trunk_group"
44
46
 
45
47
  DidGroup ||--o| Country : "has_one country"
46
48
  DidGroup ||--o| City : "has_one city"
47
- DidGroup ||--o| DidGroupType : "has_one did_group_type"
48
49
  DidGroup ||--o| Region : "has_one region"
49
50
  DidGroup ||--o{ StockKeepingUnit : "has_many stock_keeping_units"
50
51
 
@@ -60,17 +61,16 @@ erDiagram
60
61
 
61
62
  PermanentSupportingDocument ||--o| SupportingDocumentTemplate : "has_one template"
62
63
  PermanentSupportingDocument ||--o| Identity : "has_one identity"
63
- PermanentSupportingDocument ||--o{ EncryptedFile : "has_many files"
64
+ PermanentSupportingDocument ||--o{ EncryptedFile : "has_many files (create only)"
64
65
 
65
66
  Proof ||--o| ProofType : "has_one proof_type"
66
- Proof ||--o{ EncryptedFile : "has_many files"
67
+ Proof ||--o{ EncryptedFile : "has_many files (create only)"
67
68
 
68
69
  QtyBasedPricing }o--|| CapacityPool : "belongs_to capacity_pool"
69
70
 
70
71
  Region ||--o| Country : "has_one country"
71
72
 
72
73
  Requirement ||--o| Country : "has_one country"
73
- Requirement ||--o| DidGroupType : "has_one did_group_type"
74
74
  Requirement ||--o| SupportingDocumentTemplate : "has_one personal_permanent_document"
75
75
  Requirement ||--o| SupportingDocumentTemplate : "has_one business_permanent_document"
76
76
  Requirement ||--o| SupportingDocumentTemplate : "has_one personal_onetime_document"
@@ -83,12 +83,28 @@ erDiagram
83
83
  RequirementValidation ||--o| Address : "has_one address"
84
84
  RequirementValidation ||--o| Identity : "has_one identity"
85
85
 
86
+ SenderIdVerification ||--o| SmsTrunk : "has_one sms_trunk"
87
+ SenderIdVerification ||--o{ Country : "has_many countries"
88
+ SenderIdVerification ||--o{ Did : "has_many dids"
89
+ SenderIdVerification ||--o| Order : "has_one order"
90
+ SenderIdVerification ||--o| Identity : "has_one identity"
91
+ SenderIdVerification ||--o| Address : "has_one address"
92
+
86
93
  SharedCapacityGroup ||--o| CapacityPool : "has_one capacity_pool"
87
94
  SharedCapacityGroup ||--o{ Did : "has_many dids"
88
95
 
96
+ SmsTrunk ||--o{ Did : "has_many outgoing_dids"
97
+ SmsTrunk ||--o{ Did : "has_many incoming_dids"
98
+ SmsTrunk ||--o| SmsTrunkGroup : "has_one sms_trunk_group"
99
+ SmsTrunk ||--o{ SenderIdVerification : "has_many sender_id_verifications"
100
+
101
+ SmsTrunkGroup ||--o{ SmsTrunk : "has_many sms_trunks"
102
+ SmsTrunkGroup ||--o{ Did : "has_many incoming_dids"
103
+
104
+ SmsTrunkRegenerateCredential ||--o| SmsTrunk : "has_one sms_trunk"
105
+
89
106
  StockKeepingUnit }o--|| DidGroup : "belongs_to did_group"
90
107
 
91
- VoiceInTrunk ||--o| Pop : "has_one pop"
92
108
  VoiceInTrunk ||--o| VoiceInTrunkGroup : "has_one voice_in_trunk_group"
93
109
 
94
110
  VoiceInTrunkGroup ||--o{ VoiceInTrunk : "has_many voice_in_trunks"
@@ -104,35 +120,39 @@ erDiagram
104
120
  | Resource | has_one | has_many | belongs_to |
105
121
  |----------|---------|----------|------------|
106
122
  | Address | identity, country | proofs, city, area | — |
107
- | AddressVerification | address | dids, onetime_files | — |
123
+ | AddressVerification | address | dids, onetime_files\* | — |
108
124
  | Area | country | — | — |
109
125
  | AvailableDid | did_group, nanpa_prefix | — | — |
110
126
  | Balance | — | — | — |
111
127
  | CapacityPool | — | countries, shared_capacity_groups, qty_based_pricings | — |
112
128
  | City | country, region, area | — | — |
113
129
  | Country | — | regions | — |
114
- | Did | did_group, order, voice_in_trunk, voice_in_trunk_group, capacity_pool, shared_capacity_group, address_verification | — | — |
115
- | DidGroup | country, city, did_group_type, region | stock_keeping_units | — |
116
- | DidGroupType | — | — | — |
130
+ | Did | did_group, order, voice_in_trunk, voice_in_trunk_group, sms_trunk, sms_trunk_group, capacity_pool, shared_capacity_group, address_verification | — | — |
131
+ | DidGroup | country, city, region | stock_keeping_units | — |
117
132
  | DidReservation | available_did | — | — |
118
133
  | EncryptedFile | — | — | — |
119
134
  | Export | — | — | — |
120
135
  | Identity | country | proofs, addresses, permanent_documents | — |
121
136
  | NanpaPrefix | country, region | — | — |
122
137
  | Order | — | — | — |
123
- | PermanentSupportingDocument | template, identity | files | — |
124
- | Pop | — | — | — |
125
- | Proof | proof_type | files | — |
138
+ | PermanentSupportingDocument | template, identity | files\* | — |
139
+ | Proof | proof_type | files\* | — |
126
140
  | ProofType | — | — | — |
127
141
  | PublicKey | — | — | — |
128
142
  | QtyBasedPricing | — | — | capacity_pool |
129
143
  | Region | country | — | — |
130
- | Requirement | country, did_group_type, personal_permanent_document, business_permanent_document, personal_onetime_document, business_onetime_document | personal_proof_types, business_proof_types, address_proof_types | — |
144
+ | Requirement | country, personal_permanent_document, business_permanent_document, personal_onetime_document, business_onetime_document | personal_proof_types, business_proof_types, address_proof_types | — |
131
145
  | RequirementValidation | requirement, address, identity | — | — |
146
+ | SenderIdVerification | sms_trunk, order, identity, address | countries, dids | — |
132
147
  | SharedCapacityGroup | capacity_pool | dids | — |
148
+ | SmsTrunk | sms_trunk_group | outgoing_dids, incoming_dids, sender_id_verifications | — |
149
+ | SmsTrunkGroup | — | sms_trunks, incoming_dids | — |
150
+ | SmsTrunkRegenerateCredential | sms_trunk | — | — |
133
151
  | StockKeepingUnit | — | — | did_group |
134
152
  | SupportingDocumentTemplate | — | — | — |
135
- | VoiceInTrunk | pop, voice_in_trunk_group | — | — |
153
+ | VoiceInTrunk | voice_in_trunk_group | — | — |
136
154
  | VoiceInTrunkGroup | — | voice_in_trunks | — |
137
155
  | VoiceOutTrunk | default_did | dids | — |
138
156
  | VoiceOutTrunkRegenerateCredential | voice_out_trunk | — | — |
157
+
158
+ \* Write-only: the encrypted files are sent when the proof, permanent supporting document or address verification is created. The API does not return these relationships and does not accept them in `include`, so they cannot be read.
data/examples/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Examples
2
2
 
3
- All examples read the API key from the `DIDWW_API_KEY` environment variable.
3
+ All examples read the API key from the `DIDWW_API_KEY` environment variable and run against the sandbox.
4
4
 
5
5
  ## Prerequisites
6
6
 
@@ -10,87 +10,80 @@ All examples read the API key from the `DIDWW_API_KEY` environment variable.
10
10
 
11
11
  ## Environment variables
12
12
 
13
- - `DIDWW_API_KEY` (required): your DIDWW API key
13
+ - `DIDWW_API_KEY` (required): your DIDWW API key. `webhook.rb` runs offline and does not need it.
14
+ - `DIDWW_README_PRODUCTION_API_KEY` (optional for `test_readme.rb`): a production API key for the README's production configuration, which then runs read-only (a read token, the balance, the countries and one price lookup); without it that check is skipped.
15
+ - `DIDWW_README_PROXY_URL` (optional for `test_readme.rb`): an HTTP(S) proxy the README's proxy snippets are run through; without it they are skipped. The README's Rails webhook controller runs when `actionpack` is in the bundle.
14
16
 
15
17
  ## Install
16
18
 
19
+ From the repository root:
20
+
17
21
  ```bash
18
- cd examples && bundle install
22
+ bundle install
19
23
  ```
20
24
 
21
25
  ## Run an example
22
26
 
27
+ From the repository root:
28
+
23
29
  ```bash
24
30
  DIDWW_API_KEY=your_api_key ruby examples/orders_nanpa.rb
25
31
  ```
26
32
 
27
- ## Available examples
28
-
29
- ### Core Resources
30
- | Script | Description |
31
- |---|---|
32
- | [`balance.rb`](balance.rb) | Fetches and prints current account balance and credit. |
33
- | [`countries.rb`](countries.rb) | Lists countries, demonstrates filtering, and fetches one country by ID. |
34
- | [`regions.rb`](regions.rb) | Lists regions with filters/includes and fetches a specific region. |
35
- | [`did_groups.rb`](did_groups.rb) | Fetches DID groups with included SKUs and shows group details. |
36
- | [`dids.rb`](dids.rb) | Updates DID routing/capacity by assigning trunk and capacity pool. |
37
- | [`did_history.rb`](did_history.rb) | Lists DID ownership history (last 90 days, 2026-04-16). |
38
- | [`exports.rb`](exports.rb) | Creates and lists CDR exports, with 2026-04-16 external_reference_id. |
39
-
40
- ### Voice In (Inbound)
41
- | Script | Description |
42
- |---|---|
43
- | [`voice_in_trunks.rb`](voice_in_trunks.rb) | Lists voice in trunks and their configurations. |
44
- | [`voice_in_trunk_sip_registration.rb`](voice_in_trunk_sip_registration.rb) | End-to-end SIP registration flow: create with `enabled_sip_registration: true`, rename, disable by setting `host`, re-enable by toggling the flag. The SDK keeps the dependent fields (`host`, `port`, `use_did_in_ruri`) aligned with the server's validation rules automatically. |
45
- | [`voice_in_trunk_groups.rb`](voice_in_trunk_groups.rb) | CRUD for trunk groups with trunk relationships. |
33
+ ### Pass an argument
46
34
 
47
- ### Voice Out (Outbound)
48
- | Script | Description |
49
- |---|---|
50
- | [`voice_out_trunks.rb`](voice_out_trunks.rb) | CRUD for voice out trunks (requires account config). |
35
+ `upload_file.rb` takes an optional file (default `examples/sample.pdf`), `prices_lookup.rb` an optional number and `prices_download.rb` an optional directory:
51
36
 
52
- ### Capacity Management
53
- | Script | Description |
54
- |---|---|
55
- | [`capacity_pools.rb`](capacity_pools.rb) | Lists capacity pools with included shared capacity groups. |
56
- | [`shared_capacity_groups.rb`](shared_capacity_groups.rb) | Creates a shared capacity group in a capacity pool. |
37
+ ```bash
38
+ DIDWW_API_KEY=your_api_key ruby examples/upload_file.rb path/to/passport.pdf
39
+ DIDWW_API_KEY=your_api_key ruby examples/prices_lookup.rb 18005550123
40
+ ```
57
41
 
58
- ### Orders - Basic
59
- | Script | Description |
60
- |---|---|
61
- | [`orders.rb`](orders.rb) | Lists orders and creates/cancels a DID order using live SKU lookup. |
62
- | [`orders_nanpa.rb`](orders_nanpa.rb) | Orders a DID number by NPA/NXX prefix. |
63
- | [`orders_by_sku.rb`](orders_by_sku.rb) | Creates a DID order by SKU resolved from DID groups. |
64
- | [`orders_capacity.rb`](orders_capacity.rb) | Purchases capacity by creating a capacity order item. |
42
+ ## Available examples
65
43
 
66
- ### Orders - Advanced
67
44
  | Script | Description |
68
45
  |---|---|
69
- | [`orders_available_dids.rb`](orders_available_dids.rb) | Orders an available DID using included DID group SKU. |
46
+ | [`balance.rb`](balance.rb) | Fetches and prints current account balance and credit. |
47
+ | [`countries.rb`](countries.rb) | Lists countries, filters them by name, and fetches one country by ID. |
48
+ | [`regions.rb`](regions.rb) | Lists the regions of a country with the included country and fetches one region. |
49
+ | [`did_groups.rb`](did_groups.rb) | Lists DID groups with included SKUs and shows group details. |
50
+ | [`did_history.rb`](did_history.rb) | Lists DID ownership history events (last 90 days), filtered by action, number and date. |
51
+ | [`dids.rb`](dids.rb) | Lists DIDs and updates the first one: assigns a SIP trunk, a capacity pool, a capacity limit and a description. |
52
+ | [`did_trunk_assignment.rb`](did_trunk_assignment.rb) | Assigns a DID to a trunk, then to a trunk group (the trunk is cleared: they are exclusive), then restores the DID's routing and deletes the created trunk and group. |
53
+ | [`did_sms_routing.rb`](did_sms_routing.rb) | Routes a DID's inbound SMS to an SMS trunk, then to an SMS trunk group (exclusive assignment), and restores the DID's SMS routing. |
54
+ | [`did_reservations.rb`](did_reservations.rb) | Reserves an available DID, lists and finds reservations, and deletes the reservation. |
55
+ | [`capacity_pools.rb`](capacity_pools.rb) | Lists capacity pools with included shared capacity groups and qty-based pricings, and finds one pool. |
56
+ | [`shared_capacity_groups.rb`](shared_capacity_groups.rb) | Creates a shared capacity group in a capacity pool, lists groups, updates the group and deletes it. |
57
+ | [`orders.rb`](orders.rb) | Lists recent orders, orders a DID by SKU and cancels (deletes) that order. |
58
+ | [`orders_sku.rb`](orders_sku.rb) | Orders DIDs by SKU and quantity (one `did_order_items` item with `sku_id` and `qty`). |
59
+ | [`orders_available_dids.rb`](orders_available_dids.rb) | Orders a specific available DID using the SKU of its included DID group. |
70
60
  | [`orders_reservation_dids.rb`](orders_reservation_dids.rb) | Reserves a DID and then places an order from that reservation. |
71
- | [`orders_all_item_types.rb`](orders_all_item_types.rb) | Creates a DID order with all item types: by SKU, available DID, and reservation. |
72
-
73
- ### DID Management
74
- | Script | Description |
75
- |---|---|
76
- | [`did_reservations.rb`](did_reservations.rb) | Lists DID reservations and available DIDs. |
77
- | [`did_trunk_assignment.rb`](did_trunk_assignment.rb) | Demonstrates exclusive trunk/trunk group assignment on DIDs. |
78
-
79
- ### Compliance & Verification
80
- | Script | Description |
81
- |---|---|
82
- | [`identities_and_proofs.rb`](identities_and_proofs.rb) | Creates identities, addresses, and demonstrates proof workflow (2026-04-16 birth_country). |
83
- | [`address_verifications.rb`](address_verifications.rb) | Lists address verifications with 2026-04-16 reject_comment / external_reference_id. |
84
-
85
- ### Emergency Services (2026-04-16)
86
- | Script | Description |
87
- |---|---|
88
- | [`emergency_requirements.rb`](emergency_requirements.rb) | Lists emergency service requirements per country/did_group_type. |
89
- | [`emergency_calling_services.rb`](emergency_calling_services.rb) | Lists and cancels customer emergency calling services. |
90
- | [`emergency_verifications.rb`](emergency_verifications.rb) | Lists and creates emergency verifications. |
61
+ | [`orders_nanpa.rb`](orders_nanpa.rb) | Orders a DID number by NPA/NXX prefix. |
62
+ | [`orders_capacity.rb`](orders_capacity.rb) | Buys capacity channels with a capacity order item. |
63
+ | [`orders_all_item_types.rb`](orders_all_item_types.rb) | Places one order with the three DID item variants: by SKU and quantity, an available DID, and a reserved DID. |
64
+ | [`orders_emergency.rb`](orders_emergency.rb) | Reads server-created emergency orders among the recent orders and follows an emergency calling service to its order. |
65
+ | [`trunks.rb`](trunks.rb) | Lists voice IN trunks with their configurations and finds one, creates a SIP trunk and a PSTN trunk, updates both and deletes both. |
66
+ | [`voice_in_trunk_groups.rb`](voice_in_trunk_groups.rb) | Creates two trunks and a trunk group with them, lists groups with their trunks, renames the group, and deletes the group and the trunks. |
67
+ | [`voice_in_trunk_sip_registration.rb`](voice_in_trunk_sip_registration.rb) | End-to-end SIP registration flow: create with `enabled_sip_registration: true`, rename, disable by setting `host`, re-enable by toggling the flag. The SDK keeps the dependent fields (`host`, `port`, `use_did_in_ruri`) aligned with the server's validation rules automatically. |
68
+ | [`voice_out_trunks.rb`](voice_out_trunks.rb) | Lists, creates, updates and deletes voice out trunks (requires account configuration). |
69
+ | [`sms_trunks.rb`](sms_trunks.rb) | Lists SMS trunks, creates an HTTP IN trunk, updates its configuration and deletes it; shows how to rotate generated credentials. |
70
+ | [`sms_trunk_groups.rb`](sms_trunk_groups.rb) | Creates two inbound SMS trunks, groups them by priority, lists groups and deletes the group with its trunks. |
71
+ | [`sender_id_verifications.rb`](sender_id_verifications.rb) | Lists Sender ID verifications with their SMS trunks, renames an active one and restores its name. |
72
+ | [`identity_address_proofs.rb`](identity_address_proofs.rb) | Creates an identity and an address, uploads an encrypted file, creates proofs for both, prints the verified flags, and deletes the address and the identity. |
73
+ | [`address_verifications.rb`](address_verifications.rb) | Lists address verifications with reject_comment / external_reference_id. |
74
+ | [`upload_file.rb`](upload_file.rb) | Encrypts a file with the DIDWW public keys and uploads it; prints the encrypted file ID. |
75
+ | [`exports.rb`](exports.rb) | Creates and lists CDR exports, with external_reference_id. |
76
+ | [`exports_sms.rb`](exports_sms.rb) | Creates SMS-In and SMS-Out exports with their filters and reads a completed one. |
77
+ | [`emergency_requirements.rb`](emergency_requirements.rb) | Lists emergency service requirements per country/number_type. |
91
78
  | [`emergency_requirement_validations.rb`](emergency_requirement_validations.rb) | Pre-validates an emergency order triple (requirement + address + identity). |
92
- | [`orders_emergency.rb`](orders_emergency.rb) | Inspects server-created Emergency orders and `emergency_order_items`. |
79
+ | [`emergency_verifications.rb`](emergency_verifications.rb) | Lists emergency verifications and shows how to create one. |
80
+ | [`emergency_calling_services.rb`](emergency_calling_services.rb) | Lists customer emergency calling services and shows how to cancel one. |
93
81
  | [`emergency_scenario.rb`](emergency_scenario.rb) | End-to-end: find DID → check requirements → validate → create verification → get service. |
82
+ | [`prices_lookup.rb`](prices_lookup.rb) | Looks up Voice IN, Voice OUT, SMS OUT (A2P, P2P, OTP) and SMS IN prices for a number. |
83
+ | [`prices_download.rb`](prices_download.rb) | Downloads the gzipped Voice IN price file, re-checks it with If-Modified-Since and reads a few rows. |
84
+ | [`includes.rb`](includes.rb) | Reads regions, DID groups, available DIDs (nested include) and DIDs with included relationships, and shows how an included and a not-included relationship are read. |
85
+ | [`webhook.rb`](webhook.rb) | Signs a sample callback the way DIDWW does and validates it, and a tampered copy, with `DIDWW::Callback::RequestValidator`. Runs offline. |
86
+ | [`test_readme.rb`](test_readme.rb) | Runs the code snippets of the gem's README against the sandbox, one check per snippet, and cleans up; prints `Results: N passed, M failed` and exits 1 when a check fails. |
94
87
 
95
88
  ## Troubleshooting
96
89
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- # Lists capacity pools with included shared capacity groups.
2
+ # Lists capacity pools with included shared capacity groups and qty-based
3
+ # pricings, and finds one pool by ID.
3
4
  #
4
5
  # Usage: DIDWW_API_KEY=your_api_key ruby examples/capacity_pools.rb
5
6
 
@@ -11,11 +12,11 @@ DIDWW::Client.configure do |client|
11
12
  client.api_mode = :sandbox
12
13
  end
13
14
 
14
- # List capacity pools with included shared capacity groups
15
+ # List capacity pools with included shared capacity groups and qty-based pricings
15
16
  puts '=== Capacity Pools ==='
16
17
  capacity_pools = DIDWW::Client.capacity_pools
17
- .includes(:shared_capacity_groups)
18
- .all
18
+ .includes(:shared_capacity_groups, :qty_based_pricings)
19
+ .all
19
20
 
20
21
  puts "Found #{capacity_pools.size} capacity pools"
21
22
 
@@ -23,13 +24,30 @@ capacity_pools.each do |pool|
23
24
  puts "\nCapacity Pool: #{pool.name}"
24
25
  puts " Total channels: #{pool.total_channels_count}"
25
26
  puts " Assigned channels: #{pool.assigned_channels_count}"
26
- puts " Monthly price: #{pool.monthly_price}"
27
- puts " Metered rate: #{pool.metered_rate}"
27
+ puts " Renew date: #{pool.renew_date}"
28
+ puts " Monthly price: #{pool.monthly_price&.to_s('F')}"
29
+ puts " Metered rate: #{pool.metered_rate&.to_s('F')}"
28
30
 
29
- if pool.shared_capacity_groups && !pool.shared_capacity_groups.empty?
30
- puts ' Shared Capacity Groups:'
31
- pool.shared_capacity_groups.each do |group|
32
- puts " - #{group.name} (#{group.shared_channels_count} channels)"
31
+ groups = pool.shared_capacity_groups || []
32
+ unless groups.empty?
33
+ puts " Shared Capacity Groups (#{groups.size}):"
34
+ groups.each do |group|
35
+ puts " - #{group.name} shared=#{group.shared_channels_count} metered=#{group.metered_channels_count}"
33
36
  end
34
37
  end
38
+
39
+ pricings = pool.qty_based_pricings || []
40
+ unless pricings.empty?
41
+ puts " Qty-based pricings (#{pricings.size}):"
42
+ pricings.each do |pricing|
43
+ puts " - qty=#{pricing.qty} setup=#{pricing.setup_price&.to_s('F')} monthly=#{pricing.monthly_price&.to_s('F')}"
44
+ end
45
+ end
46
+ end
47
+
48
+ # Find a specific capacity pool
49
+ unless capacity_pools.empty?
50
+ puts "\n=== Specific Capacity Pool ==="
51
+ pool = DIDWW::Client.capacity_pools.find(capacity_pools.first.id).first
52
+ puts "Found: #{pool.name} (#{pool.id}), minimum qty per order: #{pool.minimum_qty_per_order}"
35
53
  end
@@ -27,7 +27,7 @@ filtered.each do |country|
27
27
  end
28
28
 
29
29
  # Find a specific country
30
- if !filtered.empty?
30
+ unless filtered.empty?
31
31
  puts "\n=== Specific Country ==="
32
32
  country = DIDWW::Client.countries.find(filtered.first.id).first
33
33
  puts "Found: #{country.name}"
@@ -37,7 +37,7 @@ did_groups.first(3).each do |did_group|
37
37
  end
38
38
 
39
39
  # Find a specific DID group
40
- if !did_groups.empty?
40
+ unless did_groups.empty?
41
41
  puts "\n=== Specific DID Group ==="
42
42
  did_group = DIDWW::Client.did_groups
43
43
  .includes(:stock_keeping_units)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- # Lists DID reservations and available DIDs.
2
+ # DID reservations: reserves an available DID, lists and finds reservations,
3
+ # and deletes the reservation, also when a step fails.
3
4
  #
4
5
  # Usage: DIDWW_API_KEY=your_api_key ruby examples/did_reservations.rb
5
6
 
@@ -11,45 +12,42 @@ DIDWW::Client.configure do |client|
11
12
  client.api_mode = :sandbox
12
13
  end
13
14
 
14
- # List DID reservations
15
- puts '=== Existing DID Reservations ==='
16
- reservations = DIDWW::Client.did_reservations
17
- .includes(:available_did)
15
+ # Get an available DID to reserve
16
+ puts '=== Finding Available DID ==='
17
+ available_did = DIDWW::Client.available_dids
18
+ .includes('did_group.stock_keeping_units')
19
+ .page(1).per(1)
18
20
  .all
21
+ .first
22
+ abort 'No available DIDs found' unless available_did
23
+ puts "Reserving DID: #{available_did.number}"
24
+ puts " Group: #{available_did.did_group.area_name} (prefix #{available_did.did_group.prefix})" if available_did.did_group
19
25
 
20
- puts "Found #{reservations.size} DID reservations"
21
- reservations.first(10).each do |reservation|
22
- did_number = reservation.available_did ? reservation.available_did.number : 'unknown'
23
- puts "#{reservation.id}"
24
- puts " DID: #{did_number}"
25
- puts " Expires: #{reservation.expire_at}"
26
- puts " Created: #{reservation.created_at}"
27
- puts ''
28
- end
29
-
30
- # List available DIDs
31
- puts "\n=== Available DIDs ==="
32
- available_dids = DIDWW::Client.available_dids
33
- .includes(:did_group)
34
- .all
26
+ # Create a reservation
27
+ puts "\n=== Creating Reservation ==="
28
+ reservation = DIDWW::Client.did_reservations.new(description: 'Ruby SDK example reservation')
29
+ reservation.available_did = available_did
30
+ abort "Error creating reservation: #{reservation.errors.full_messages}" unless reservation.save
31
+ puts "Created reservation: #{reservation.id}"
32
+ puts " Description: #{reservation.description}"
33
+ puts " Expires at: #{reservation.expires_at}"
35
34
 
36
- puts "Found #{available_dids.size} available DIDs"
37
- available_dids.first(10).each do |available_did|
38
- puts "#{available_did.number}"
39
- if available_did.did_group
40
- puts " Group: #{available_did.did_group.area_name}"
41
- puts " Prefix: #{available_did.did_group.prefix}"
35
+ begin
36
+ # List reservations with the included available DID
37
+ puts "\n=== All Reservations ==="
38
+ reservations = DIDWW::Client.did_reservations
39
+ .includes(:available_did)
40
+ .all
41
+ puts "Found #{reservations.size} reservations"
42
+ reservations.each do |r|
43
+ puts " #{r.id} - #{r.available_did&.number || 'unknown'} (expires #{r.expires_at})"
42
44
  end
43
- puts ''
44
- end
45
45
 
46
- # Find a specific reservation if available
47
- if !reservations.empty?
48
- puts "\n=== Specific Reservation Details ==="
49
- specific_reservation = DIDWW::Client.did_reservations
50
- .find(reservations.first.id)
51
- .first
52
- puts "Reservation: #{specific_reservation.id}"
53
- puts " Expires at: #{specific_reservation.expire_at}"
54
- puts " Created at: #{specific_reservation.created_at}"
46
+ # Find by ID
47
+ puts "\n=== Specific Reservation ==="
48
+ found = DIDWW::Client.did_reservations.find(reservation.id).first
49
+ puts "Found reservation: #{found.id}, created at #{found.created_at}"
50
+ ensure
51
+ puts "\n=== Deleting Reservation ==="
52
+ puts reservation.destroy ? 'Deleted reservation' : "Error deleting reservation: #{reservation.errors.full_messages}"
55
53
  end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+ # Routes a DID's inbound SMS to an SMS trunk, then to an SMS trunk group.
3
+ # The two are exclusive: assigning one sends the other as null in the same
4
+ # PATCH, just like voice_in_trunk and voice_in_trunk_group. At the end the
5
+ # DID's original SMS routing is restored, also when a step fails.
6
+ #
7
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/did_sms_routing.rb
8
+
9
+ require 'bundler/setup'
10
+ require 'didww'
11
+
12
+ DIDWW::Client.configure do |client|
13
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
14
+ client.api_mode = :sandbox
15
+ end
16
+
17
+ def print_sms_routing(did_id)
18
+ result = DIDWW::Client.dids
19
+ .includes(:sms_trunk, :sms_trunk_group)
20
+ .find(did_id)
21
+ .first
22
+ puts " sms_trunk = #{result.sms_trunk&.id || 'null'}"
23
+ puts " sms_trunk_group = #{result.sms_trunk_group&.id || 'null'}"
24
+ end
25
+
26
+ # Sends a PATCH with only the relationships set in the block
27
+ def update_did(did_id)
28
+ did = DIDWW::Resource::Did.load(id: did_id)
29
+ yield did
30
+ raise "Error updating DID: #{did.errors.full_messages}" unless did.save
31
+ end
32
+
33
+ puts '=== Finding DID ==='
34
+ did = DIDWW::Client.dids
35
+ .includes(:sms_trunk, :sms_trunk_group)
36
+ .page(1).per(1)
37
+ .all
38
+ .first
39
+ abort 'No DIDs found. Please order a DID first.' unless did
40
+ puts "Using DID: #{did.number} (#{did.id})"
41
+
42
+ puts "\n=== Finding inbound SMS trunk ==="
43
+ trunk = DIDWW::Client.sms_trunks.all.find(&:allow_in)
44
+ abort 'No inbound SMS trunk found. Run examples/sms_trunks.rb or create one first.' unless trunk
45
+ puts "Selected SMS trunk: #{trunk.name} (#{trunk.id})"
46
+
47
+ puts "\n=== Finding SMS trunk group ==="
48
+ group = DIDWW::Client.sms_trunk_groups.page(1).per(1).all.first
49
+ puts group ? "Selected SMS trunk group: #{group.name} (#{group.id})" : 'No SMS trunk group found; step 2 is skipped.'
50
+
51
+ # Remember the current routing to put it back at the end
52
+ original_trunk = did.sms_trunk
53
+ original_group = did.sms_trunk_group
54
+ puts "\nCurrent SMS routing:"
55
+ print_sms_routing(did.id)
56
+
57
+ did_changed = false
58
+ begin
59
+ # 1. Assign the SMS trunk (sends sms_trunk_group as null)
60
+ puts "\n=== 1. Assigning SMS trunk to DID ==="
61
+ did_changed = true
62
+ update_did(did.id) { |d| d.sms_trunk = trunk }
63
+ print_sms_routing(did.id)
64
+
65
+ puts "\n=== DIDs routed to #{trunk.name} ==="
66
+ DIDWW::Client.dids.where('sms_trunk.id': trunk.id).all.each { |d| puts " #{d.number}" }
67
+
68
+ # 2. Assign the SMS trunk group (sends sms_trunk as null)
69
+ if group
70
+ puts "\n=== 2. Assigning SMS trunk group to DID (clears the SMS trunk) ==="
71
+ update_did(did.id) { |d| d.sms_trunk_group = group }
72
+ print_sms_routing(did.id)
73
+ end
74
+ ensure
75
+ if did_changed
76
+ # 3. Restore the original routing. nil unassigns only that relationship,
77
+ # so both are set to unroute the DID's inbound SMS.
78
+ puts "\n=== 3. Restoring the DID's original SMS routing ==="
79
+ update_did(did.id) do |d|
80
+ if original_trunk
81
+ d.sms_trunk = original_trunk
82
+ elsif original_group
83
+ d.sms_trunk_group = original_group
84
+ else
85
+ d.sms_trunk = nil
86
+ d.sms_trunk_group = nil
87
+ end
88
+ end
89
+ print_sms_routing(did.id)
90
+ end
91
+ end