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
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
- # Creates a DID order with all three item types (using unified DidOrderItem):
3
- # 1. DidOrderItem - order by SKU and quantity (random DID)
4
- # 2. AvailableDidOrderItem - order a specific available DID (via DidOrderItem + available_did_id)
5
- # 3. ReservationDidOrderItem - order a previously reserved DID (via DidOrderItem + did_reservation_id)
2
+ # Creates ONE order with the three DID order item variants, then fetches the
3
+ # ordered DIDs:
4
+ # 1. by SKU and quantity - DidOrderItem(sku_id, qty): DIDWW picks the number
5
+ # 2. a specific available DID - DidOrderItem(available_did_id, sku_id)
6
+ # 3. a previously reserved DID - DidOrderItem(did_reservation_id, sku_id)
6
7
  #
7
- # Then fetches the ordered DIDs.
8
+ # All three are did_order_items on the wire, so they fit one order. Capacity
9
+ # items (capacity_order_items) cannot share an order with DID items: the API
10
+ # answers "items - should have same type". Buy capacity in an order of its own
11
+ # (see orders_capacity.rb).
8
12
  #
9
13
  # Usage: DIDWW_API_KEY=your_api_key ruby examples/orders_all_item_types.rb
10
14
 
@@ -16,138 +20,72 @@ DIDWW::Client.configure do |client|
16
20
  client.api_mode = :sandbox
17
21
  end
18
22
 
23
+ # The first SKU of the available DID's included DID group
24
+ def sku_of(available_did)
25
+ sku = available_did.did_group&.stock_keeping_units&.first
26
+ abort "No stock_keeping_units for available DID #{available_did.id}" unless sku
27
+ sku
28
+ end
29
+
19
30
  # Find available DIDs with their DID group and SKUs
20
31
  puts '=== Finding Available DIDs ==='
21
32
  available_dids = DIDWW::Client.available_dids
22
- .includes('did_group.stock_keeping_units')
23
- .all
24
-
25
- if available_dids.size < 2
26
- puts 'Need at least 2 available DIDs for this example'
27
- exit 1
28
- end
29
-
30
- available_did1 = available_dids[0]
31
- available_did2 = available_dids[1]
32
-
33
- puts "Available DID 1: #{available_did1.number}"
34
- puts "Available DID 2: #{available_did2.number}"
35
-
36
- # Helper to get SKU from available DID
37
- def get_sku(available_did)
38
- if available_did.did_group.nil? || available_did.did_group.stock_keeping_units.nil? || available_did.did_group.stock_keeping_units.empty?
39
- raise "No stock_keeping_units for available DID #{available_did.id}"
40
- end
41
- available_did.did_group.stock_keeping_units.first
42
- end
43
-
44
- sku1 = get_sku(available_did1)
45
- sku2 = get_sku(available_did2)
46
-
47
- puts "SKU 1: #{sku1.id}"
48
- puts "SKU 2: #{sku2.id}"
49
-
50
- # Get a SKU for the DidOrderItem (by quantity) from a different DID group
33
+ .includes('did_group.stock_keeping_units')
34
+ .all
35
+ abort 'Need at least 2 available DIDs for this example' if available_dids.size < 2
36
+
37
+ available_did = available_dids[0]
38
+ reserved_did = available_dids[1]
39
+ # Resolved before the reservation, so a missing SKU leaves nothing reserved
40
+ available_sku = sku_of(available_did)
41
+ reserved_sku = sku_of(reserved_did)
42
+ puts "Available DID 1: #{available_did.number} (SKU #{available_sku.id}) - ordered directly"
43
+ puts "Available DID 2: #{reserved_did.number} (SKU #{reserved_sku.id}) - reserved first"
44
+
45
+ # A SKU for the item by quantity, from a DID group
51
46
  puts "\n=== Finding SKU for quantity order ==="
52
- did_groups = DIDWW::Client.did_groups
53
- .includes(:stock_keeping_units)
54
- .all
55
-
56
- sku_for_qty = nil
57
- did_groups.each do |dg|
58
- if !dg.stock_keeping_units.nil? && !dg.stock_keeping_units.empty?
59
- sku_for_qty = dg.stock_keeping_units.first
60
- puts "SKU for qty order: #{sku_for_qty.id}"
61
- break
62
- end
63
- end
64
-
65
- if sku_for_qty.nil?
66
- puts 'No DID group with stock_keeping_units found'
67
- exit 1
68
- end
47
+ group_with_skus = DIDWW::Client.did_groups
48
+ .where(is_available: true) # numbers in stock
49
+ .includes(:stock_keeping_units)
50
+ .all
51
+ .find { |did_group| did_group.stock_keeping_units&.any? }
52
+ abort 'No DID group with stock_keeping_units found' unless group_with_skus
53
+ sku_for_qty = group_with_skus.stock_keeping_units.first
54
+ puts "SKU for qty order: #{sku_for_qty.id}"
69
55
 
70
56
  # Reserve the second available DID
71
57
  puts "\n=== Reserving DID ==="
72
- reservation = DIDWW::Client.did_reservations.new
73
- reservation.available_did = available_did2
74
-
75
- if !reservation.save
76
- puts "Error creating reservation: #{reservation.errors.full_messages}"
77
- exit 1
78
- end
79
-
58
+ reservation = DIDWW::Client.did_reservations.new(description: 'Reserved for all-item-types example')
59
+ reservation.available_did = reserved_did
60
+ abort "Error creating reservation: #{reservation.errors.full_messages}" unless reservation.save
80
61
  puts "Reservation: #{reservation.id}"
81
62
 
82
- # Build order with all three item types
63
+ # One order, three items
83
64
  puts "\n=== Creating Order with All Item Types ==="
84
-
85
- # 1. DidOrderItem - order by SKU and quantity (random DID)
86
- item_by_sku = DIDWW::ComplexObject::DidOrderItem.new(
87
- sku_id: sku_for_qty.id,
88
- qty: 1
89
- )
90
-
91
- # 2. AvailableDidOrderItem - order a specific available DID (use DidOrderItem with available_did_id)
92
- item_by_available = DIDWW::ComplexObject::DidOrderItem.new(
93
- available_did_id: available_did1.id,
94
- sku_id: sku1.id
95
- )
96
-
97
- # 3. ReservationDidOrderItem - order a previously reserved DID (use DidOrderItem with did_reservation_id)
98
- item_by_reservation = DIDWW::ComplexObject::DidOrderItem.new(
99
- did_reservation_id: reservation.id,
100
- sku_id: sku2.id
65
+ order = DIDWW::Client.orders.new(
66
+ items: [
67
+ DIDWW::ComplexObject::DidOrderItem.new(sku_id: sku_for_qty.id, qty: 1),
68
+ DIDWW::ComplexObject::DidOrderItem.new(available_did_id: available_did.id, sku_id: available_sku.id),
69
+ DIDWW::ComplexObject::DidOrderItem.new(did_reservation_id: reservation.id, sku_id: reserved_sku.id)
70
+ ]
101
71
  )
102
-
103
- # Note: Each order must contain items of the SAME type only
104
- # So we create separate orders for each item type combination
105
-
106
- orders_created = []
107
-
108
- # Order 1: By SKU
109
- order1 = DIDWW::Client.orders.new(items: [item_by_sku])
110
- if order1.save
111
- puts "\n✓ Order by SKU: #{order1.id}"
112
- puts " Amount: #{order1.amount}, Status: #{order1.status}"
113
- orders_created << order1
114
- else
115
- puts "\n✗ Error: #{order1.errors.full_messages}"
116
- end
117
-
118
- # Order 2: By Available DID
119
- order2 = DIDWW::Client.orders.new(items: [item_by_available])
120
- if order2.save
121
- puts "✓ Order by Available DID: #{order2.id}"
122
- puts " Amount: #{order2.amount}, Status: #{order2.status}"
123
- orders_created << order2
124
- else
125
- puts "✗ Error: #{order2.errors.full_messages}"
126
- end
127
-
128
- # Order 3: By Reservation
129
- order3 = DIDWW::Client.orders.new(items: [item_by_reservation])
130
- if order3.save
131
- puts "✓ Order by Reservation: #{order3.id}"
132
- puts " Amount: #{order3.amount}, Status: #{order3.status}"
133
- orders_created << order3
134
- else
135
- puts "✗ Error: #{order3.errors.full_messages}"
72
+ unless order.save
73
+ # The order did not take the reserved DID, so release it
74
+ puts "Error deleting reservation #{reservation.id}: #{reservation.errors.full_messages}" unless reservation.destroy
75
+ abort "Error creating order: #{order.errors.full_messages}"
136
76
  end
137
77
 
138
- # Fetch DIDs from all orders
139
- puts "\n=== DIDs Ordered ==="
140
- total_dids = 0
141
- orders_created.each_with_index do |order, idx|
142
- dids = DIDWW::Client.dids.where('order.id': order.id).all
143
- puts "Order #{idx + 1} (#{order.id}): #{dids.size} DID(s)"
144
- dids.each { |did| puts " - #{did.number}" }
145
- total_dids += dids.size
78
+ puts "Order ID: #{order.id}"
79
+ puts " Amount: #{order.amount&.to_s('F')}"
80
+ puts " Status: #{order.status}"
81
+ puts " Created at: #{order.created_at}"
82
+ puts " Reference: #{order.reference}"
83
+ puts " Items: #{order.items.size}"
84
+ order.items.each_with_index do |item, i|
85
+ puts " Item #{i + 1}: type=#{item.type} qty=#{item.qty} sku=#{item.sku_id}"
146
86
  end
147
87
 
148
- puts "\n=== Summary ==="
149
- puts '✓ All three order item types demonstrated:'
150
- puts ' 1. DidOrderItem(sku_id, qty) - order by SKU'
151
- puts ' 2. DidOrderItem(available_did_id, sku_id) - order available DID'
152
- puts ' 3. DidOrderItem(did_reservation_id, sku_id) - order reserved DID'
153
- puts "Total DIDs ordered: #{total_dids}"
88
+ # Fetch the DIDs that belong to this order
89
+ dids = DIDWW::Client.dids.where('order.id': order.id).all
90
+ puts "\n=== DIDs in order (#{dids.size}) ==="
91
+ dids.each { |did| puts " #{did.id} | #{did.number} | capacity_limit=#{did.capacity_limit}" }
@@ -19,10 +19,10 @@ DIDWW::Client.configure do |client|
19
19
  client.api_mode = :sandbox
20
20
  end
21
21
 
22
- puts '=== All Orders (last 20, filtering for Emergency) ==='
23
- orders = DIDWW::Client.orders.order('-created_at').all
22
+ puts '=== Recent Orders (last 50, filtering for Emergency) ==='
23
+ orders = DIDWW::Client.orders.order('-created_at').page(1).per(50).all
24
24
  emergency_orders = orders.select do |o|
25
- o.items&.any? { |i| (i.respond_to?(:type) ? i.type : i['type']) == 'emergency_order_items' }
25
+ o.items&.any? { |i| i.is_a?(DIDWW::ComplexObject::EmergencyOrderItem) }
26
26
  end
27
27
  puts "Found #{emergency_orders.size} emergency orders out of #{orders.size} total"
28
28
 
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
- # Creates a DID order by SKU resolved from DID groups.
2
+ # Creates a DID order by SKU and quantity: one did_order_items item with
3
+ # sku_id + qty, the SKU resolved from DID groups. DIDWW picks the numbers.
3
4
  #
4
- # Usage: DIDWW_API_KEY=your_api_key ruby examples/orders_by_sku.rb
5
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/orders_sku.rb
5
6
 
6
7
  require 'bundler/setup'
7
8
  require 'didww'
@@ -11,18 +12,19 @@ DIDWW::Client.configure do |client|
11
12
  client.api_mode = :sandbox
12
13
  end
13
14
 
14
- # Get DID group with SKUs
15
+ # Get a DID group with numbers in stock and SKUs
15
16
  puts '=== Finding DID Group with SKUs ==='
16
- did_groups = DIDWW::Client.did_groups
17
- .includes(:stock_keeping_units)
18
- .all
19
-
20
- if did_groups.empty? || did_groups.first.stock_keeping_units.nil? || did_groups.first.stock_keeping_units.empty?
21
- puts 'No DID group with stock_keeping_units found'
17
+ did_group = DIDWW::Client.did_groups
18
+ .where(is_available: true)
19
+ .includes(:stock_keeping_units)
20
+ .all
21
+ .find { |group| group.stock_keeping_units&.any? }
22
+
23
+ unless did_group
24
+ puts 'No available DID group with stock_keeping_units found'
22
25
  exit 1
23
26
  end
24
27
 
25
- did_group = did_groups.first
26
28
  sku = did_group.stock_keeping_units.first
27
29
 
28
30
  puts "Selected DID Group: #{did_group.id}"
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ # Downloads the Voice IN price file, checks it again with If-Modified-Since,
3
+ # and reads a few rows.
4
+ #
5
+ # The file is written exactly as served, still gzipped, and dated with the
6
+ # response's Last-Modified. fetch(path) sends the modification time of the file
7
+ # at path as If-Modified-Since, so while the price file is unchanged the second
8
+ # call, and any later run against the same file, is answered 304 and keeps it.
9
+ #
10
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/prices_download.rb [dir]
11
+
12
+ require 'bundler/setup'
13
+ require 'didww'
14
+ require 'tmpdir'
15
+
16
+ DIDWW::Client.configure do |client|
17
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
18
+ client.api_mode = :sandbox
19
+ end
20
+
21
+ prices = DIDWW::Client.voice_in_prices
22
+ path = File.join(ARGV.first || Dir.tmpdir, 'voice_in_prices.csv.gz')
23
+
24
+ begin
25
+ puts '=== HEAD ==='
26
+ status = prices.head
27
+ puts "Last-Modified: #{status.last_modified}, #{status.content_length} bytes, #{status.filename}"
28
+
29
+ puts "\n=== fetch #{path} ==="
30
+ file = prices.fetch(path)
31
+ puts file.modified? ? "Downloaded #{file.bytes_written} bytes" : 'Not modified, file kept'
32
+
33
+ puts "\n=== fetch again ==="
34
+ file = prices.fetch(path)
35
+ puts file.modified? ? "Downloaded #{file.bytes_written} bytes" : 'Not modified, file kept'
36
+
37
+ puts "\n=== First rows ==="
38
+ DIDWW::Prices.each_row(path).first(5).each do |row|
39
+ puts " #{row['Country']} #{row['Destination']} #{row['Source type']}: #{row['Rate']}"
40
+ end
41
+ rescue DIDWW::Prices::PricePlanNotAssigned => e
42
+ puts "No Voice IN price plan on this account: #{e.message}"
43
+ rescue DIDWW::Prices::ServiceUnavailable => e
44
+ puts "The price file is not available yet, retry in #{e.retry_after.inspect} s: #{e.message}"
45
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ # Looks up Voice IN, Voice OUT, SMS OUT and SMS IN prices for one number.
3
+ #
4
+ # Prices are served by separate hosts (api-vin, api-vout and api-sms); the SDK
5
+ # mints a token for each of them on first use. The account needs a price plan
6
+ # of the service, otherwise DIDWW::Prices::PricePlanNotAssigned is raised.
7
+ #
8
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/prices_lookup.rb [number]
9
+
10
+ require 'bundler/setup'
11
+ require 'didww'
12
+
13
+ DIDWW::Client.configure do |client|
14
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
15
+ client.api_mode = :sandbox
16
+ client.scope = :read # a read token is enough for prices
17
+ end
18
+
19
+ number = ARGV.first || '18005550123'
20
+
21
+ def show(title)
22
+ puts "\n=== #{title} ==="
23
+ result = yield
24
+ puts "#{result.total_records} matching price(s)"
25
+ result.each { |price| puts " #{price.to_h.compact}" }
26
+ rescue DIDWW::Prices::PricePlanNotAssigned, DIDWW::Prices::PriceNotFound => e
27
+ puts " #{e.class.name.split('::').last}: #{e.message}"
28
+ end
29
+
30
+ show('Voice IN') { DIDWW::Client.voice_in_prices.lookup(number: number) }
31
+ show('Voice IN, calls from the US') { DIDWW::Client.voice_in_prices.lookup(number: number, src_country_iso: 'US') }
32
+ show('Voice OUT') { DIDWW::Client.voice_out_prices.lookup(number: number) }
33
+ show('SMS OUT A2P') { DIDWW::Client.sms_out_a2p_prices.lookup(dst_number: number) }
34
+ show('SMS OUT P2P, whole country') { DIDWW::Client.sms_out_p2p_prices.lookup(dst_country_iso: 'US') }
35
+ show('SMS OUT OTP') { DIDWW::Client.sms_out_otp_prices.lookup(dst_number: number, dst_country_iso: 'US') }
36
+ show('SMS IN') { DIDWW::Client.sms_in_prices.lookup(dst_number: number) }
37
+
38
+ # Filters are checked before any request is sent:
39
+ begin
40
+ DIDWW::Client.voice_out_prices.lookup(number: number, src_country_iso: 'US')
41
+ rescue ArgumentError => e
42
+ puts "\nRejected locally: #{e.message}"
43
+ end
data/examples/regions.rb CHANGED
@@ -35,7 +35,7 @@ regions.first(5).each do |region|
35
35
  end
36
36
 
37
37
  # Fetch a specific region
38
- if !regions.empty?
38
+ unless regions.empty?
39
39
  puts "\n=== Specific Region ==="
40
40
  region = DIDWW::Client.regions
41
41
  .includes(:country)
@@ -0,0 +1,14 @@
1
+ %PDF-1.0
2
+ 1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
3
+ 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj
4
+ 3 0 obj<</Type/Page/MediaBox[0 0 612 792]/Parent 2 0 R/Resources<<>>>>endobj
5
+ xref
6
+ 0 4
7
+ 0000000000 65535 f
8
+ 0000000009 00000 n
9
+ 0000000058 00000 n
10
+ 0000000115 00000 n
11
+ trailer<</Size 4/Root 1 0 R>>
12
+ startxref
13
+ 206
14
+ %%EOF
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+ # Lists Sender ID verifications with their SMS trunks, renames an active one
3
+ # and restores its original name, also when a step fails.
4
+ #
5
+ # A verification is created and reviewed outside the API; only its name and
6
+ # its SMS trunk can be changed, and a closed one cannot be changed at all.
7
+ # Only http_out, smpp_esme and smpp_smsc trunks are accepted as its SMS trunk.
8
+ #
9
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/sender_id_verifications.rb
10
+
11
+ require 'bundler/setup'
12
+ require 'didww'
13
+
14
+ DIDWW::Client.configure do |client|
15
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
16
+ client.api_mode = :sandbox
17
+ end
18
+
19
+ verification_class = DIDWW::Resource::SenderIdVerification
20
+
21
+ puts '=== Sender ID Verifications ==='
22
+ verifications = DIDWW::Client.sender_id_verifications.includes(:sms_trunk).all
23
+ verifications.each do |v|
24
+ routed_through = v.sms_trunk&.name || 'no SMS trunk'
25
+ puts "#{v.reference} #{v.name} (#{v.sender_type}, #{v.status}): #{Array(v.sender_ids).join(', ')} via #{routed_through}"
26
+ puts " changes required: #{Array(v.reject_reasons).join('; ')} #{v.reject_comment}" if v.changes_required?
27
+ # Prices are decimal strings; the renew date is "YYYY-MM-DD", nil once closed
28
+ meta = v.attributes[:meta] || {}
29
+ puts " setup price: #{meta[:setup_price]}, monthly price: #{meta[:monthly_price]}, renews: #{v.renew_date}"
30
+ end
31
+
32
+ verification = verifications.find(&:active?)
33
+ abort 'No active Sender ID verification' unless verification
34
+ original_name = verification.name
35
+
36
+ puts "\n=== Renaming #{verification.reference} ==="
37
+ begin
38
+ rename = verification_class.load(id: verification.id)
39
+ rename.name = "#{original_name} (renamed)"
40
+ abort "Error renaming the verification: #{rename.errors.full_messages}" unless rename.save
41
+ puts "Name: #{rename.name}"
42
+ ensure
43
+ restore = verification_class.load(id: verification.id)
44
+ restore.name = original_name
45
+ puts restore.save ? "Name restored: #{original_name}" : "Error restoring the name: #{restore.errors.full_messages}"
46
+ end
47
+
48
+ # Routing through an SMS trunk that sends messages works the same way; nil
49
+ # unassigns the trunk, which stops outbound messages until one is assigned again:
50
+ #
51
+ # route = DIDWW::Resource::SenderIdVerification.load(id: verification.id)
52
+ # route.sms_trunk = DIDWW::Resource::SmsTrunk.load(id: 'sending-sms-trunk-uuid')
53
+ # route.save
54
+
55
+ puts "\nActive verifications by SMS trunk:"
56
+ if verification.sms_trunk
57
+ DIDWW::Client.sender_id_verifications
58
+ .where(status: verification_class::STATUS_ACTIVE, 'sms_trunk.id': verification.sms_trunk.id)
59
+ .all
60
+ .each { |v| puts " #{v.reference} #{v.name} via #{verification.sms_trunk.name}" }
61
+ else
62
+ puts " #{verification.reference} has no SMS trunk"
63
+ end
@@ -1,52 +1,61 @@
1
1
  # frozen_string_literal: true
2
- # Lists shared capacity groups in capacity pools.
2
+ # Shared capacity groups: creates a group in a capacity pool, lists groups,
3
+ # updates the group and deletes it, also when a step fails.
4
+ #
5
+ # shared_channels_count is the number of the pool's channels shared among the
6
+ # group's DIDs; metered_channels_count caps the metered channels they may use.
3
7
  #
4
8
  # Usage: DIDWW_API_KEY=your_api_key ruby examples/shared_capacity_groups.rb
5
9
 
6
10
  require 'bundler/setup'
7
11
  require 'didww'
12
+ require 'securerandom'
8
13
 
9
14
  DIDWW::Client.configure do |client|
10
15
  client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
16
  client.api_mode = :sandbox
12
17
  end
13
18
 
14
- # List shared capacity groups
15
- puts '=== Existing Shared Capacity Groups ==='
16
- shared_groups = DIDWW::Client.shared_capacity_groups
17
- .includes(:capacity_pool)
18
- .all
19
+ suffix = SecureRandom.hex(4)
19
20
 
20
- puts "Found #{shared_groups.size} shared capacity groups"
21
+ # Get a capacity pool
22
+ pool = DIDWW::Client.capacity_pools.page(1).per(1).all.first
23
+ abort 'No capacity pools found' unless pool
24
+ puts "Using capacity pool: #{pool.name} (#{pool.total_channels_count} channels, #{pool.assigned_channels_count} assigned)"
21
25
 
22
- shared_groups.first(10).each do |group|
23
- puts "\nGroup: #{group.name}"
24
- puts " ID: #{group.id}"
25
- puts " Shared channels: #{group.shared_channels_count}"
26
- puts " Metered channels: #{group.metered_channels_count}"
27
- puts " External reference: #{group.external_reference_id}" if group.external_reference_id
28
- if group.capacity_pool
29
- puts " Capacity pool: #{group.capacity_pool.name}"
30
- end
31
- end
26
+ # Create a shared capacity group (2026-04-16 external_reference_id for customer tagging)
27
+ puts "\n=== Creating Shared Capacity Group ==="
28
+ group = DIDWW::Client.shared_capacity_groups.new(
29
+ name: "Ruby Channel Group #{suffix}",
30
+ shared_channels_count: 1,
31
+ metered_channels_count: 10,
32
+ external_reference_id: "ruby-scg-#{suffix}"
33
+ )
34
+ group.capacity_pool = pool
35
+ abort "Error creating shared capacity group: #{group.errors.full_messages}" unless group.save
36
+ puts "Created: #{group.id}"
37
+ puts " Name: #{group.name}"
38
+ puts " Shared: #{group.shared_channels_count}, metered: #{group.metered_channels_count}"
39
+ puts " External reference: #{group.external_reference_id}"
32
40
 
33
- # Get a specific capacity pool and show its shared capacity groups
34
- puts "\n=== Capacity Pool with Shared Groups ==="
35
- capacity_pools = DIDWW::Client.capacity_pools
36
- .includes(:shared_capacity_groups)
37
- .all
38
-
39
- if !capacity_pools.empty?
40
- pool = capacity_pools.first
41
- puts "Capacity Pool: #{pool.name}"
42
- if pool.shared_capacity_groups && !pool.shared_capacity_groups.empty?
43
- puts " Total channels: #{pool.total_channels_count}"
44
- puts " Assigned channels: #{pool.assigned_channels_count}"
45
- puts ' Shared Capacity Groups:'
46
- pool.shared_capacity_groups.each do |group|
47
- puts " - #{group.name} (#{group.shared_channels_count} shared, #{group.metered_channels_count} metered)"
48
- end
49
- else
50
- puts ' No shared capacity groups'
41
+ begin
42
+ # List shared capacity groups with their capacity pool
43
+ puts "\n=== Shared Capacity Groups ==="
44
+ groups = DIDWW::Client.shared_capacity_groups
45
+ .includes(:capacity_pool)
46
+ .all
47
+ puts "Found #{groups.size} shared capacity groups"
48
+ groups.each do |g|
49
+ puts " #{g.name} shared=#{g.shared_channels_count} metered=#{g.metered_channels_count} pool=#{g.capacity_pool&.name}"
51
50
  end
51
+
52
+ # Update: only the changed attributes are sent
53
+ puts "\n=== Updating Shared Capacity Group ==="
54
+ group.name = "Ruby Channel Group #{suffix} (v2)"
55
+ group.metered_channels_count = 5
56
+ abort "Error updating shared capacity group: #{group.errors.full_messages}" unless group.save
57
+ puts "Updated: #{group.name}, metered: #{group.metered_channels_count}"
58
+ ensure
59
+ puts "\n=== Deleting Shared Capacity Group ==="
60
+ puts group.destroy ? 'Deleted shared capacity group' : "Error deleting shared capacity group: #{group.errors.full_messages}"
52
61
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+ # CRUD for SMS trunk groups: creates two inbound trunks, puts them in a
3
+ # group, lists groups, and deletes the group.
4
+ #
5
+ # A group spreads a DID's inbound messages over its trunks by their
6
+ # priority (higher first). http_out trunks cannot join a group.
7
+ # Deleting a group also deletes the trunks in it.
8
+ #
9
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/sms_trunk_groups.rb
10
+
11
+ require 'bundler/setup'
12
+ require 'didww'
13
+ require 'securerandom'
14
+
15
+ DIDWW::Client.configure do |client|
16
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
17
+ client.api_mode = :sandbox
18
+ end
19
+
20
+ configurations = DIDWW::ComplexObject::SmsTrunkConfiguration
21
+ suffix = SecureRandom.hex(4)
22
+
23
+ puts '=== Creating SMS Trunks ==='
24
+ primary = DIDWW::Client.sms_trunks.new(
25
+ name: "Ruby primary #{suffix}",
26
+ priority: 200,
27
+ configuration: configurations::HttpIn.new(
28
+ url: 'https://example.com/sms',
29
+ http_method: configurations::HttpIn::HTTP_METHOD_GET,
30
+ query_parameters: { 'text' => '{SMS_TEXT}', 'from' => '{SMS_SRC_ADDR}' }
31
+ )
32
+ )
33
+ fallback = DIDWW::Client.sms_trunks.new(
34
+ name: "Ruby fallback #{suffix}",
35
+ priority: 100,
36
+ configuration: configurations::SmsToEmail.new(
37
+ send_to: 'sms@example.com',
38
+ subject: 'Inbound SMS',
39
+ message: 'You have a new message.'
40
+ )
41
+ )
42
+ [primary, fallback].each do |trunk|
43
+ abort "Error creating SMS trunk: #{trunk.errors.full_messages}" unless trunk.save
44
+ puts "Created SMS trunk: #{trunk.id} - #{trunk.name}"
45
+ end
46
+
47
+ puts "\n=== Creating SMS Trunk Group ==="
48
+ group = DIDWW::Client.sms_trunk_groups.new(
49
+ name: "Ruby SMS Group #{suffix}",
50
+ external_reference_id: "ruby-sms-group-#{suffix}"
51
+ )
52
+ group.relationships.sms_trunks = [primary, fallback]
53
+
54
+ if group.save
55
+ puts "Created SMS trunk group: #{group.id} - #{group.name} (#{group.sms_trunks_count} trunks)"
56
+ else
57
+ [primary, fallback].each(&:destroy)
58
+ abort "Error creating SMS trunk group: #{group.errors.full_messages}"
59
+ end
60
+
61
+ puts "\n=== Existing SMS Trunk Groups ==="
62
+ groups = DIDWW::Client.sms_trunk_groups
63
+ .includes(:sms_trunks)
64
+ .all
65
+ groups.first(5).each do |g|
66
+ names = g.sms_trunks ? g.sms_trunks.map(&:name).join(', ') : ''
67
+ puts "#{g.name} (#{g.sms_trunks_count} trunks) #{names}"
68
+ end
69
+
70
+ puts "\n=== Deleting SMS Trunk Group (and its trunks) ==="
71
+ puts group.destroy ? 'SMS trunk group deleted' : "Error deleting SMS trunk group: #{group.errors.full_messages}"