didww-v3 5.1.0 → 5.2.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +64 -7
  3. data/examples/README.md +86 -0
  4. data/examples/balance.rb +17 -0
  5. data/examples/capacity_pools.rb +35 -0
  6. data/examples/countries.rb +34 -0
  7. data/examples/did_groups.rb +45 -0
  8. data/examples/did_reservations.rb +55 -0
  9. data/examples/did_trunk_assignment.rb +107 -0
  10. data/examples/dids.rb +62 -0
  11. data/examples/exports.rb +44 -0
  12. data/examples/identities_and_proofs.rb +62 -0
  13. data/examples/orders.rb +60 -0
  14. data/examples/orders_all_item_types.rb +153 -0
  15. data/examples/orders_available_dids.rb +63 -0
  16. data/examples/orders_by_sku.rb +53 -0
  17. data/examples/orders_capacity.rb +44 -0
  18. data/examples/orders_nanpa.rb +44 -0
  19. data/examples/orders_reservation_dids.rb +71 -0
  20. data/examples/regions.rb +45 -0
  21. data/examples/shared_capacity_groups.rb +51 -0
  22. data/examples/voice_in_trunk_groups.rb +51 -0
  23. data/examples/voice_in_trunks.rb +43 -0
  24. data/examples/voice_out_trunks.rb +68 -0
  25. data/lib/didww/base_middleware.rb +12 -6
  26. data/lib/didww/callback/request_validator.rb +5 -12
  27. data/lib/didww/client.rb +34 -114
  28. data/lib/didww/jsonapi_middleware.rb +5 -14
  29. data/lib/didww/resource/address.rb +2 -2
  30. data/lib/didww/resource/address_verification.rb +17 -14
  31. data/lib/didww/resource/concerns/has_status_helpers.rb +17 -0
  32. data/lib/didww/resource/did_group.rb +1 -0
  33. data/lib/didww/resource/encrypted_file.rb +2 -2
  34. data/lib/didww/resource/export.rb +8 -4
  35. data/lib/didww/resource/identity.rb +7 -2
  36. data/lib/didww/resource/order.rb +5 -11
  37. data/lib/didww/resource/permanent_supporting_document.rb +2 -2
  38. data/lib/didww/resource/proof.rb +5 -5
  39. data/lib/didww/resource/region.rb +4 -0
  40. data/lib/didww/resource/requirement.rb +2 -2
  41. data/lib/didww/resource/supporting_document_template.rb +4 -0
  42. data/lib/didww/version.rb +1 -1
  43. metadata +25 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39b910fbb0b5dc4425cf053fd6cacef936c7c46510f8586d33784cccad18a95e
4
- data.tar.gz: 1dae18d3341a93e2a2b4c74d81e224e0402a8c7020bda0053fb685be5186abb2
3
+ metadata.gz: df4c6143fca0f8b1f6c6d5c4e43fc89a71a4a9fcc5b63b3b63c3bb9ab03ce102
4
+ data.tar.gz: dd9ad527373290850d9555f1117aa097aa534497668115fdcbb9dd2f2323f783
5
5
  SHA512:
6
- metadata.gz: eba0ac2332cf5f0f4c1f65155c0714d9ce35f0a96227024d2b3a21ab650c44587c789035cfb3dd995d797a08573e821eb1301e00732f91cdb3732175c163177c
7
- data.tar.gz: a1ebd2311fa0b1f190d068a210ccfe583b74e3b6ec83c7ad368f2f2eb69d2bdf7d40b8ad5ddb98ab2828b2061ce20a77a67db2406b9c30e5ed4f417d20454259
6
+ metadata.gz: 32dc4dc452c8ef98f1855ec47aee83cd7959f9abc3c3ade68489610d71600a8bcf1e232cb4a4e3a76ffae9a5b68adb19d133b8788d6d4ba7711dff36141c96b4
7
+ data.tar.gz: e759ef5119ea80accac264b297e4730f9391e774adc47d7dca853b0c9d79f6c1d2af4a61562e849af04c4a4ba476213a18696a9e88c7f8ee92b811c68059a09e
data/README.md CHANGED
@@ -51,17 +51,17 @@ Or install it yourself as:
51
51
  ```ruby
52
52
  require 'didww'
53
53
 
54
- client = DIDWW::Client.configure do |config|
54
+ DIDWW::Client.configure do |config|
55
55
  config.api_key = 'YOUR_API_KEY'
56
56
  config.api_mode = :sandbox
57
57
  end
58
58
 
59
59
  # Check balance
60
- balance = client.balance
60
+ balance = DIDWW::Client.balance
61
61
  puts "Balance: #{balance.total_balance}"
62
62
 
63
63
  # List DID groups with stock keeping units
64
- did_groups = client.did_groups.all(
64
+ did_groups = DIDWW::Client.did_groups.all(
65
65
  include: 'stock_keeping_units',
66
66
  filter: { area_name: 'Acapulco' }
67
67
  )
@@ -69,14 +69,10 @@ did_groups = client.did_groups.all(
69
69
  puts "DID groups: #{did_groups.count}"
70
70
  ```
71
71
 
72
- For more examples visit [examples](examples/).
73
-
74
72
  For details on obtaining your API key please visit https://doc.didww.com/api3/configuration.html
75
73
 
76
74
  ## Examples
77
75
 
78
- - Source code: [examples/](examples/)
79
- - How to run: [examples/README.md](examples/README.md)
80
76
  - Rails integration sample: https://github.com/didww/didww-v3-rails-sample
81
77
 
82
78
  ## Configuration
@@ -168,6 +164,7 @@ trunk = DIDWW::Client.voice_in_trunks.new(
168
164
  name: 'My SIP Trunk',
169
165
  configuration: {
170
166
  type: 'sip_configurations',
167
+ username: '{DID}',
171
168
  host: 'sip.example.com',
172
169
  port: 5060
173
170
  }
@@ -192,10 +189,70 @@ order = DIDWW::Client.orders.new(
192
189
  order.save
193
190
  ```
194
191
 
192
+ ## Date and Datetime Fields
193
+
194
+ The SDK distinguishes between date-only and datetime fields:
195
+
196
+ - **Datetime fields** — deserialized as `Time`:
197
+ - All `created_at` fields — present on most resources (`EncryptedFile` has no `created_at`)
198
+ - Expiry fields: `Did#expires_at`, `DidReservation#expire_at`, `Proof#expires_at`, `EncryptedFile#expire_at`
199
+ - **Date-only fields** — deserialized as `Date`:
200
+ - `Identity#birth_date`
201
+ - **Date-only fields kept as strings** (`CapacityPool#renew_date`) remain as `String`.
202
+
203
+ ```ruby
204
+ did = DIDWW::Client.dids.find("uuid").first
205
+ puts did.created_at # => 2024-01-15 10:00:00 UTC (Time)
206
+ puts did.expires_at # => nil or 2025-01-15 10:00:00 UTC (Time)
207
+
208
+ identity = DIDWW::Client.identities.find("uuid").first
209
+ puts identity.birth_date # => 1990-05-20 (Date)
210
+ ```
211
+
195
212
  ## Resource Relationships
196
213
 
197
214
  See [docs/resource_relationships.md](docs/resource_relationships.md) for a Mermaid ER diagram showing all `has_one`, `has_many`, and `belongs_to` relationships between resources.
198
215
 
216
+ ## Webhook Signature Validation
217
+
218
+ Validate incoming webhook callbacks from DIDWW using HMAC-SHA1 signature verification.
219
+
220
+ ```ruby
221
+ require 'didww/callback/request_validator'
222
+
223
+ validator = DIDWW::Callback::RequestValidator.new("YOUR_API_KEY")
224
+
225
+ # In your webhook handler:
226
+ valid = validator.validate(
227
+ request_url, # full original URL
228
+ payload_params, # Hash of payload key-value pairs
229
+ signature # value of X-DIDWW-Signature header
230
+ )
231
+ ```
232
+
233
+ The signature header name is available as the constant `DIDWW::Callback::RequestValidator::HEADER`.
234
+
235
+ ### Rails Example
236
+
237
+ ```ruby
238
+ class WebhooksController < ApplicationController
239
+ skip_before_action :verify_authenticity_token
240
+
241
+ def create
242
+ validator = DIDWW::Callback::RequestValidator.new("YOUR_API_KEY")
243
+ signature = request.headers[DIDWW::Callback::RequestValidator::HEADER]
244
+ params_hash = request.POST
245
+
246
+ if validator.validate(request.original_url, params_hash, signature)
247
+ # Process the webhook
248
+ head :ok
249
+ else
250
+ head :forbidden
251
+ end
252
+ end
253
+ end
254
+ ```
255
+
199
256
  ## Development
200
257
 
201
258
  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.
@@ -0,0 +1,86 @@
1
+ # Examples
2
+
3
+ All examples read the API key from the `DIDWW_API_KEY` environment variable.
4
+
5
+ ## Prerequisites
6
+
7
+ - Ruby 3.3+
8
+ - Bundler
9
+ - DIDWW API key for sandbox account
10
+
11
+ ## Environment variables
12
+
13
+ - `DIDWW_API_KEY` (required): your DIDWW API key
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ cd examples && bundle install
19
+ ```
20
+
21
+ ## Run an example
22
+
23
+ ```bash
24
+ DIDWW_API_KEY=your_api_key ruby examples/orders_nanpa.rb
25
+ ```
26
+
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
+ | [`exports.rb`](exports.rb) | Lists CDR exports and their details. |
38
+
39
+ ### Voice In (Inbound)
40
+ | Script | Description |
41
+ |---|---|
42
+ | [`voice_in_trunks.rb`](voice_in_trunks.rb) | Lists voice in trunks and their configurations. |
43
+ | [`voice_in_trunk_groups.rb`](voice_in_trunk_groups.rb) | CRUD for trunk groups with trunk relationships. |
44
+
45
+ ### Voice Out (Outbound)
46
+ | Script | Description |
47
+ |---|---|
48
+ | [`voice_out_trunks.rb`](voice_out_trunks.rb) | CRUD for voice out trunks (requires account config). |
49
+
50
+ ### Capacity Management
51
+ | Script | Description |
52
+ |---|---|
53
+ | [`capacity_pools.rb`](capacity_pools.rb) | Lists capacity pools with included shared capacity groups. |
54
+ | [`shared_capacity_groups.rb`](shared_capacity_groups.rb) | Creates a shared capacity group in a capacity pool. |
55
+
56
+ ### Orders - Basic
57
+ | Script | Description |
58
+ |---|---|
59
+ | [`orders.rb`](orders.rb) | Lists orders and creates/cancels a DID order using live SKU lookup. |
60
+ | [`orders_nanpa.rb`](orders_nanpa.rb) | Orders a DID number by NPA/NXX prefix. |
61
+ | [`orders_by_sku.rb`](orders_by_sku.rb) | Creates a DID order by SKU resolved from DID groups. |
62
+ | [`orders_capacity.rb`](orders_capacity.rb) | Purchases capacity by creating a capacity order item. |
63
+
64
+ ### Orders - Advanced
65
+ | Script | Description |
66
+ |---|---|
67
+ | [`orders_available_dids.rb`](orders_available_dids.rb) | Orders an available DID using included DID group SKU. |
68
+ | [`orders_reservation_dids.rb`](orders_reservation_dids.rb) | Reserves a DID and then places an order from that reservation. |
69
+ | [`orders_all_item_types.rb`](orders_all_item_types.rb) | Creates a DID order with all item types: by SKU, available DID, and reservation. |
70
+
71
+ ### DID Management
72
+ | Script | Description |
73
+ |---|---|
74
+ | [`did_reservations.rb`](did_reservations.rb) | Lists DID reservations and available DIDs. |
75
+ | [`did_trunk_assignment.rb`](did_trunk_assignment.rb) | Demonstrates exclusive trunk/trunk group assignment on DIDs. |
76
+
77
+ ### Compliance & Verification
78
+ | Script | Description |
79
+ |---|---|
80
+ | [`identities_and_proofs.rb`](identities_and_proofs.rb) | Creates identities, addresses, and demonstrates proof workflow. |
81
+
82
+ ## Troubleshooting
83
+
84
+ If `DIDWW_API_KEY` is missing, examples fail fast with:
85
+
86
+ `Please set DIDWW_API_KEY`
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ # Fetches and prints current account balance and credit.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/balance.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ balance = DIDWW::Client.balance
15
+ puts "Total Balance: #{balance.total_balance}"
16
+ puts "Balance: #{balance.balance}"
17
+ puts "Credit: #{balance.credit}"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ # Lists capacity pools with included shared capacity groups.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/capacity_pools.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List capacity pools with included shared capacity groups
15
+ puts '=== Capacity Pools ==='
16
+ capacity_pools = DIDWW::Client.capacity_pools
17
+ .includes(:shared_capacity_groups)
18
+ .all
19
+
20
+ puts "Found #{capacity_pools.size} capacity pools"
21
+
22
+ capacity_pools.each do |pool|
23
+ puts "\nCapacity Pool: #{pool.name}"
24
+ puts " Total channels: #{pool.total_channels_count}"
25
+ puts " Assigned channels: #{pool.assigned_channels_count}"
26
+ puts " Monthly price: #{pool.monthly_price}"
27
+ puts " Metered rate: #{pool.metered_rate}"
28
+
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)"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ # Lists countries, demonstrates filtering, and fetches one country by ID.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/countries.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List all countries
15
+ puts '=== All Countries ==='
16
+ countries = DIDWW::Client.countries.all
17
+ countries.first(5).each do |country|
18
+ puts "#{country.name} (+#{country.prefix}) [#{country.iso}]"
19
+ end
20
+
21
+ # Filter countries by name
22
+ puts "\n=== Filtered Countries (United States) ==="
23
+ filtered = DIDWW::Client.countries.where(name: 'United States').all
24
+ puts "Found: #{filtered.size} countries"
25
+ filtered.each do |country|
26
+ puts "#{country.name} (+#{country.prefix})"
27
+ end
28
+
29
+ # Find a specific country
30
+ if !filtered.empty?
31
+ puts "\n=== Specific Country ==="
32
+ country = DIDWW::Client.countries.find(filtered.first.id).first
33
+ puts "Found: #{country.name}"
34
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ # Fetches DID groups with included SKUs and shows group details.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/did_groups.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # Fetch DID groups with included stock_keeping_units
15
+ puts '=== DID Groups with SKUs ==='
16
+ did_groups = DIDWW::Client.did_groups
17
+ .includes(:stock_keeping_units)
18
+ .all
19
+
20
+ puts "Found #{did_groups.size} DID groups"
21
+
22
+ did_groups.first(3).each do |did_group|
23
+ puts "\nDID Group: #{did_group.id}"
24
+ puts " Area: #{did_group.area_name}"
25
+ puts " Prefix: #{did_group.prefix}"
26
+ puts " Metered: #{did_group.is_metered}"
27
+ puts " Features: #{did_group.features_human}"
28
+
29
+ if did_group.stock_keeping_units && !did_group.stock_keeping_units.empty?
30
+ puts ' SKUs:'
31
+ did_group.stock_keeping_units.each do |sku|
32
+ puts " - #{sku.id} (monthly: #{sku.monthly_price})"
33
+ end
34
+ end
35
+ end
36
+
37
+ # Find a specific DID group
38
+ if !did_groups.empty?
39
+ puts "\n=== Specific DID Group ==="
40
+ did_group = DIDWW::Client.did_groups
41
+ .includes(:stock_keeping_units)
42
+ .find(did_groups.first.id)
43
+ .first
44
+ puts "Found: #{did_group.area_name} (prefix: #{did_group.prefix})"
45
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ # Lists DID reservations and available DIDs.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/did_reservations.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List DID reservations
15
+ puts '=== Existing DID Reservations ==='
16
+ reservations = DIDWW::Client.did_reservations
17
+ .includes(:available_did)
18
+ .all
19
+
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
35
+
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}"
42
+ end
43
+ puts ''
44
+ end
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}"
55
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+ # Demonstrates exclusive trunk/trunk group assignment on DIDs.
3
+ # Assigning a trunk auto-nullifies the trunk group and vice versa.
4
+ #
5
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/did_trunk_assignment.rb
6
+
7
+ require 'bundler/setup'
8
+ require 'didww'
9
+
10
+ DIDWW::Client.configure do |client|
11
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
12
+ client.api_mode = :sandbox
13
+ end
14
+
15
+ # Get a DID to work with
16
+ puts '=== Finding DID ==='
17
+ dids = DIDWW::Client.dids
18
+ .includes(:voice_in_trunk, :voice_in_trunk_group)
19
+ .all
20
+
21
+ if dids.empty?
22
+ puts 'No DIDs found. Please order a DID first.'
23
+ exit 1
24
+ end
25
+
26
+ did = dids.first
27
+ puts "Using DID: #{did.number} (#{did.id})"
28
+
29
+ # Get a trunk
30
+ puts "\n=== Finding Trunk ==="
31
+ trunks = DIDWW::Client.voice_in_trunks.all
32
+
33
+ if trunks.empty?
34
+ puts 'No trunks found. Please create a trunk first.'
35
+ exit 1
36
+ end
37
+
38
+ trunk = trunks.first
39
+ puts "Selected trunk: #{trunk.name} (#{trunk.id})"
40
+
41
+ # Get a trunk group
42
+ puts "\n=== Finding Trunk Group ==="
43
+ trunk_groups = DIDWW::Client.voice_in_trunk_groups.all
44
+
45
+ if trunk_groups.empty?
46
+ puts 'No trunk groups found. Please create a trunk group first.'
47
+ exit 1
48
+ end
49
+
50
+ trunk_group = trunk_groups.first
51
+ puts "Selected trunk group: #{trunk_group.name} (#{trunk_group.id})"
52
+
53
+ def print_did_assignment(client, did_id)
54
+ result = client.dids
55
+ .includes(:voice_in_trunk, :voice_in_trunk_group)
56
+ .find(did_id)
57
+ .first
58
+ trunk = result.voice_in_trunk ? result.voice_in_trunk.id : 'null'
59
+ group = result.voice_in_trunk_group ? result.voice_in_trunk_group.id : 'null'
60
+ puts " trunk = #{trunk}"
61
+ puts " group = #{group}"
62
+ end
63
+
64
+ begin
65
+ # 1. Assign trunk to DID (auto-nullifies trunk group)
66
+ puts "\n=== 1. Assigning trunk to DID ==="
67
+ did.voice_in_trunk = trunk
68
+ if did.save
69
+ print_did_assignment(DIDWW::Client, did.id)
70
+ else
71
+ puts "Error assigning trunk: #{did.errors.full_messages}"
72
+ end
73
+
74
+ # 2. Assign trunk group to DID (auto-nullifies trunk)
75
+ puts "\n=== 2. Assigning trunk group to DID ==="
76
+ did_fresh = DIDWW::Client.dids.find(did.id).first
77
+ did_fresh.voice_in_trunk_group = trunk_group
78
+ if did_fresh.save
79
+ print_did_assignment(DIDWW::Client, did.id)
80
+ else
81
+ puts "Error assigning trunk group: #{did_fresh.errors.full_messages}"
82
+ end
83
+
84
+ # 3. Re-assign trunk (auto-nullifies trunk group again)
85
+ puts "\n=== 3. Re-assigning trunk ==="
86
+ did_fresh = DIDWW::Client.dids.find(did.id).first
87
+ did_fresh.voice_in_trunk = trunk
88
+ if did_fresh.save
89
+ print_did_assignment(DIDWW::Client, did.id)
90
+ else
91
+ puts "Error re-assigning trunk: #{did_fresh.errors.full_messages}"
92
+ end
93
+
94
+ # 4. Update description only (trunk stays assigned)
95
+ puts "\n=== 4. Updating description only (trunk stays) ==="
96
+ did_fresh = DIDWW::Client.dids.find(did.id).first
97
+ did_fresh.description = 'DID with trunk assigned'
98
+ if did_fresh.save
99
+ print_did_assignment(DIDWW::Client, did.id)
100
+ else
101
+ puts "Error updating description: #{did_fresh.errors.full_messages}"
102
+ end
103
+
104
+ puts "\nDemonstration complete!"
105
+ rescue StandardError => e
106
+ puts "Error: #{e.message}"
107
+ end
data/examples/dids.rb ADDED
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ # Updates DID routing/capacity by assigning trunk and capacity pool.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/dids.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # Get the last ordered DID
15
+ puts '=== Finding last ordered DID ==='
16
+ dids = DIDWW::Client.dids
17
+ .all
18
+
19
+ if dids.empty?
20
+ puts 'No DIDs found. Please order a DID first.'
21
+ exit 1
22
+ end
23
+
24
+ did = dids.first
25
+ puts "Selected DID: #{did.id}"
26
+
27
+ # Get last SIP trunk
28
+ puts "\n=== Finding SIP trunk ==="
29
+ trunks = DIDWW::Client.voice_in_trunks
30
+ .where('configuration.type': 'sip_configurations')
31
+ .all
32
+
33
+ if trunks.empty?
34
+ puts 'No SIP trunks found. Please create a SIP trunk first.'
35
+ exit 1
36
+ end
37
+
38
+ trunk = trunks.first
39
+ puts "Selected trunk: #{trunk.name}"
40
+
41
+ # Assign trunk to DID
42
+ puts "\n=== Assigning trunk to DID ==="
43
+ did.voice_in_trunk = trunk
44
+ updated_did = did.save
45
+ puts "Assigned trunk: #{did.voice_in_trunk.name if did.voice_in_trunk}"
46
+
47
+ # Assign capacity pool
48
+ puts "\n=== Assigning capacity pool ==="
49
+ capacity_pools = DIDWW::Client.capacity_pools.all
50
+
51
+ if !capacity_pools.empty?
52
+ pool = capacity_pools.first
53
+ did.capacity_pool = pool
54
+ did.capacity_limit = 5
55
+ did.description = 'Updated by Ruby example'
56
+ did.save
57
+ puts "DID #{did.id}"
58
+ puts " description: #{did.description}"
59
+ puts " capacity_limit: #{did.capacity_limit}"
60
+ else
61
+ puts 'No capacity pools found'
62
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ # Lists CDR exports and their details.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/exports.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List exports
15
+ puts '=== Existing Exports ==='
16
+ exports = DIDWW::Client.exports.all
17
+ puts "Found #{exports.size} exports"
18
+
19
+ exports.first(10).each do |export|
20
+ puts "Export: #{export.id}"
21
+ puts " Type: #{export.export_type}"
22
+ puts " Status: #{export.status}"
23
+ puts " Created: #{export.created_at}"
24
+ puts " URL: #{export.url}" if export.url
25
+ puts " Callback URL: #{export.callback_url}" if export.callback_url
26
+ puts ''
27
+ end
28
+
29
+ # Find a specific export if available
30
+ if !exports.empty?
31
+ puts "\n=== Specific Export Details ==="
32
+ specific_export = DIDWW::Client.exports
33
+ .find(exports.first.id)
34
+ .first
35
+ puts "Export: #{specific_export.id}"
36
+ puts " Type: #{specific_export.export_type}"
37
+ puts " Status: #{specific_export.status}"
38
+ puts " Created: #{specific_export.created_at}"
39
+ if specific_export.filters
40
+ puts ' Filters:'
41
+ puts " Year: #{specific_export.filters.year}"
42
+ puts " Month: #{specific_export.filters.month}"
43
+ end
44
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ # Lists identities, addresses, and proofs. Demonstrates compliance workflow.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/identities_and_proofs.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List identities
15
+ puts '=== Identities ==='
16
+ identities = DIDWW::Client.identities.all
17
+ puts "Found #{identities.size} identities"
18
+
19
+ identities.first(10).each do |identity|
20
+ puts "\nIdentity: #{identity.id}"
21
+ puts " Name: #{identity.first_name} #{identity.last_name}"
22
+ puts " Phone: #{identity.phone_number}"
23
+ puts " Type: #{identity.identity_type}"
24
+ puts " Verified: #{identity.verified}"
25
+ puts " Created: #{identity.created_at}"
26
+ end
27
+
28
+ # List addresses
29
+ puts "\n=== Addresses ==="
30
+ addresses = DIDWW::Client.addresses
31
+ .includes(:identity)
32
+ .all
33
+
34
+ puts "Found #{addresses.size} addresses"
35
+
36
+ addresses.first(10).each do |address|
37
+ puts "\nAddress: #{address.id}"
38
+ puts " Street: #{address.address}"
39
+ puts " City: #{address.city_name}"
40
+ puts " Postal Code: #{address.postal_code}"
41
+ puts " Verified: #{address.verified}"
42
+ if address.identity
43
+ puts " Identity: #{address.identity.first_name} #{address.identity.last_name}"
44
+ end
45
+ end
46
+
47
+ # List proof types
48
+ puts "\n=== Proof Types ==="
49
+ proof_types = DIDWW::Client.proof_types.all
50
+ puts "Found #{proof_types.size} proof types"
51
+
52
+ proof_types.first(10).each do |pt|
53
+ puts "#{pt.name} (#{pt.entity_type})"
54
+ end
55
+
56
+ puts "\n=== Identities and Proofs Workflow ==="
57
+ puts '1. Create an identity with personal information'
58
+ puts '2. Create an address linked to the identity'
59
+ puts '3. Encrypt and upload identity/address documents'
60
+ puts '4. Create proofs attached to identity/address with uploaded files'
61
+ puts '5. Monitor verification status'
62
+ puts "\nNote: Creating and uploading encrypted files requires additional SDK setup."