didww-v3 6.2.0 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +8 -6
- data/.rubocop.yml +0 -110
- data/CHANGELOG.md +65 -0
- data/FILTERS.md +36 -12
- data/Gemfile +0 -2
- data/README.md +431 -58
- data/didww-v3.gemspec +11 -8
- data/docs/resource_relationships.md +35 -15
- data/examples/README.md +54 -61
- data/examples/capacity_pools.rb +28 -10
- data/examples/countries.rb +1 -1
- data/examples/did_groups.rb +1 -1
- data/examples/did_reservations.rb +35 -37
- data/examples/did_sms_routing.rb +91 -0
- data/examples/did_trunk_assignment.rb +106 -80
- data/examples/emergency_calling_services.rb +3 -3
- data/examples/emergency_requirements.rb +3 -3
- data/examples/emergency_scenario.rb +11 -11
- data/examples/emergency_verifications.rb +7 -5
- data/examples/exports.rb +1 -1
- data/examples/exports_sms.rb +72 -0
- data/examples/identity_address_proofs.rb +118 -0
- data/examples/includes.rb +65 -0
- data/examples/orders.rb +8 -6
- data/examples/orders_all_item_types.rb +63 -125
- data/examples/orders_emergency.rb +3 -3
- data/examples/{orders_by_sku.rb → orders_sku.rb} +12 -10
- data/examples/prices_download.rb +45 -0
- data/examples/prices_lookup.rb +43 -0
- data/examples/regions.rb +1 -1
- data/examples/sample.pdf +14 -0
- data/examples/sender_id_verifications.rb +63 -0
- data/examples/shared_capacity_groups.rb +44 -35
- data/examples/sms_trunk_groups.rb +71 -0
- data/examples/sms_trunks.rb +84 -0
- data/examples/test_readme.rb +1216 -0
- data/examples/trunks.rb +115 -0
- data/examples/upload_file.rb +44 -0
- data/examples/voice_in_trunk_groups.rb +57 -33
- data/examples/voice_in_trunk_sip_registration.rb +4 -1
- data/examples/voice_out_trunks.rb +11 -1
- data/examples/webhook.rb +51 -0
- data/lib/didww/auth/bearer_middleware.rb +74 -0
- data/lib/didww/auth/memory_store.rb +40 -0
- data/lib/didww/auth/token.rb +45 -0
- data/lib/didww/auth/token_provider.rb +215 -0
- data/lib/didww/base_middleware.rb +7 -8
- data/lib/didww/callback/request_validator.rb +7 -5
- data/lib/didww/client.rb +122 -13
- data/lib/didww/complex_objects/authentication_methods/generic.rb +6 -0
- data/lib/didww/complex_objects/configurations/base.rb +0 -18
- data/lib/didww/complex_objects/configurations/pstn_configuration.rb +0 -4
- data/lib/didww/complex_objects/configurations/sip_configuration.rb +86 -38
- data/lib/didww/complex_objects/emergency_order_item.rb +1 -1
- data/lib/didww/complex_objects/export_filters.rb +72 -6
- data/lib/didww/complex_objects/generic_order_item.rb +15 -0
- data/lib/didww/complex_objects/sms_trunk_configuration.rb +33 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/base.rb +26 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/generic.rb +32 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/http_in.rb +75 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/http_out.rb +35 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/smpp_esme.rb +37 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/smpp_smsc.rb +56 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/sms_to_email.rb +27 -0
- data/lib/didww/errors.rb +103 -0
- data/lib/didww/http.rb +34 -0
- data/lib/didww/prices/lookup_result.rb +37 -0
- data/lib/didww/prices/price.rb +56 -0
- data/lib/didww/prices/price_file.rb +51 -0
- data/lib/didww/prices/service.rb +248 -0
- data/lib/didww/prices/sms_in_price.rb +43 -0
- data/lib/didww/prices/sms_out_price.rb +52 -0
- data/lib/didww/prices/voice_in_price.rb +48 -0
- data/lib/didww/prices/voice_out_price.rb +88 -0
- data/lib/didww/prices.rb +82 -0
- data/lib/didww/resource/address_requirement.rb +13 -3
- data/lib/didww/resource/base.rb +5 -2
- data/lib/didww/resource/concerns/number_types.rb +24 -0
- data/lib/didww/resource/did.rb +42 -3
- data/lib/didww/resource/did_group.rb +12 -1
- data/lib/didww/resource/emergency_calling_service.rb +10 -5
- data/lib/didww/resource/emergency_requirement.rb +27 -14
- data/lib/didww/resource/encrypted_file.rb +19 -6
- data/lib/didww/resource/export.rb +59 -12
- data/lib/didww/resource/identity.rb +9 -4
- data/lib/didww/resource/order.rb +1 -0
- data/lib/didww/resource/proof_type.rb +1 -1
- data/lib/didww/resource/sender_id_verification.rb +114 -0
- data/lib/didww/resource/sms_trunk.rb +76 -0
- data/lib/didww/resource/sms_trunk_group.rb +31 -0
- data/lib/didww/resource/sms_trunk_regenerate_credential.rb +16 -0
- data/lib/didww/resource/voice_in_trunk.rb +24 -1
- data/lib/didww/resource/voice_out_trunk.rb +72 -0
- data/lib/didww/types/ip_addresses.rb +1 -1
- data/lib/didww/types/strings.rb +1 -1
- data/lib/didww/types.rb +3 -1
- data/lib/didww/version.rb +1 -1
- data/lib/didww.rb +7 -0
- metadata +63 -25
- data/examples/identities_and_proofs.rb +0 -67
- data/examples/voice_in_trunks.rb +0 -108
- data/lib/didww/resource/did_group_type.rb +0 -10
- data/lib/didww/resource/exclusive_relationship.rb +0 -54
- data/lib/didww/resource/pop.rb +0 -10
|
@@ -1,107 +1,133 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# Demonstrates exclusive trunk/trunk group assignment on DIDs.
|
|
3
|
-
# Assigning a trunk auto-nullifies the trunk group and vice versa
|
|
3
|
+
# Assigning a trunk auto-nullifies the trunk group and vice versa: the SDK sends
|
|
4
|
+
# the other relationship as null in the same PATCH.
|
|
5
|
+
# At the end the DID's original voice routing and description are restored and
|
|
6
|
+
# the created trunk and trunk group are deleted, also when a step fails.
|
|
4
7
|
#
|
|
5
8
|
# Usage: DIDWW_API_KEY=your_api_key ruby examples/did_trunk_assignment.rb
|
|
6
9
|
|
|
7
10
|
require 'bundler/setup'
|
|
8
11
|
require 'didww'
|
|
12
|
+
require 'securerandom'
|
|
9
13
|
|
|
10
14
|
DIDWW::Client.configure do |client|
|
|
11
15
|
client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
|
|
12
16
|
client.api_mode = :sandbox
|
|
13
17
|
end
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
19
|
+
def print_did_assignment(did_id)
|
|
20
|
+
result = DIDWW::Client.dids
|
|
21
|
+
.includes(:voice_in_trunk, :voice_in_trunk_group)
|
|
22
|
+
.find(did_id)
|
|
23
|
+
.first
|
|
24
|
+
puts " trunk = #{result.voice_in_trunk&.id || 'null'}"
|
|
25
|
+
puts " group = #{result.voice_in_trunk_group&.id || 'null'}"
|
|
36
26
|
end
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
28
|
+
# Sends a PATCH with only the attributes and relationships set in the block
|
|
29
|
+
def update_did(did_id)
|
|
30
|
+
did = DIDWW::Resource::Did.load(id: did_id)
|
|
31
|
+
yield did
|
|
32
|
+
raise "Error updating DID: #{did.errors.full_messages}" unless did.save
|
|
48
33
|
end
|
|
49
34
|
|
|
50
|
-
|
|
51
|
-
puts
|
|
35
|
+
# Get a DID
|
|
36
|
+
puts '=== Finding DID ==='
|
|
37
|
+
did = DIDWW::Client.dids
|
|
38
|
+
.includes(:voice_in_trunk, :voice_in_trunk_group)
|
|
39
|
+
.page(1).per(1)
|
|
40
|
+
.all
|
|
41
|
+
.first
|
|
42
|
+
abort 'No DIDs found. Please order a DID first.' unless did
|
|
43
|
+
puts "Using DID: #{did.number} (#{did.id})"
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
45
|
+
# Remember the current routing and description to put them back at the end
|
|
46
|
+
original_trunk = did.voice_in_trunk
|
|
47
|
+
original_group = did.voice_in_trunk_group
|
|
48
|
+
original_description = did.description
|
|
49
|
+
puts "Current routing: trunk=#{original_trunk&.id || 'null'} group=#{original_group&.id || 'null'}"
|
|
63
50
|
|
|
51
|
+
suffix = SecureRandom.hex(4)
|
|
52
|
+
trunk = nil
|
|
53
|
+
trunk_group = nil
|
|
54
|
+
did_changed = false
|
|
64
55
|
begin
|
|
56
|
+
# Create a trunk
|
|
57
|
+
trunk = DIDWW::Client.voice_in_trunks.new(
|
|
58
|
+
name: "Assignment Trunk #{suffix}",
|
|
59
|
+
pop: DIDWW::Resource::VoiceInTrunk::POP_FRA, # optional; leave it nil to let DIDWW choose
|
|
60
|
+
configuration: DIDWW::ComplexObject::SipConfiguration.new(
|
|
61
|
+
host: 'sip.example.com',
|
|
62
|
+
port: 5060,
|
|
63
|
+
codecs: [
|
|
64
|
+
DIDWW::ComplexObject::SipConfiguration::CODEC_PCMU,
|
|
65
|
+
DIDWW::ComplexObject::SipConfiguration::CODEC_PCMA
|
|
66
|
+
],
|
|
67
|
+
transport_protocol_id: 1 # UDP
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
raise "Error creating trunk: #{trunk.errors.full_messages}" unless trunk.save
|
|
71
|
+
puts "Created trunk: #{trunk.id}"
|
|
72
|
+
|
|
73
|
+
# Create a trunk group
|
|
74
|
+
trunk_group = DIDWW::Client.voice_in_trunk_groups.new(name: "Assignment Group #{suffix}", capacity_limit: 10)
|
|
75
|
+
raise "Error creating trunk group: #{trunk_group.errors.full_messages}" unless trunk_group.save
|
|
76
|
+
puts "Created trunk group: #{trunk_group.id}"
|
|
77
|
+
|
|
65
78
|
# 1. Assign trunk to DID (auto-nullifies trunk group)
|
|
66
|
-
|
|
67
|
-
did.voice_in_trunk = trunk
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
else
|
|
71
|
-
puts "Error assigning trunk: #{did.errors.full_messages}"
|
|
72
|
-
end
|
|
79
|
+
did_changed = true
|
|
80
|
+
update_did(did.id) { |d| d.voice_in_trunk = trunk }
|
|
81
|
+
puts "\n1. Assigned trunk:"
|
|
82
|
+
print_did_assignment(did.id)
|
|
73
83
|
|
|
74
84
|
# 2. Assign trunk group to DID (auto-nullifies trunk)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
85
|
+
update_did(did.id) { |d| d.voice_in_trunk_group = trunk_group }
|
|
86
|
+
puts "\n2. Assigned trunk group (the trunk is cleared):"
|
|
87
|
+
print_did_assignment(did.id)
|
|
83
88
|
|
|
84
89
|
# 3. Re-assign trunk (auto-nullifies trunk group again)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
update_did(did.id) { |d| d.voice_in_trunk = trunk }
|
|
91
|
+
puts "\n3. Re-assigned trunk:"
|
|
92
|
+
print_did_assignment(did.id)
|
|
93
|
+
|
|
94
|
+
# 4. Update the description only: only changed fields are sent, so the trunk stays
|
|
95
|
+
update_did(did.id) { |d| d.description = 'DID with trunk assigned' }
|
|
96
|
+
puts "\n4. Updated description only (trunk stays):"
|
|
97
|
+
print_did_assignment(did.id)
|
|
98
|
+
ensure
|
|
99
|
+
begin
|
|
100
|
+
# Restore the DID first, so the created trunk and group are no longer in use
|
|
101
|
+
if did_changed
|
|
102
|
+
update_did(did.id) do |d|
|
|
103
|
+
if original_trunk
|
|
104
|
+
d.voice_in_trunk = original_trunk
|
|
105
|
+
elsif original_group
|
|
106
|
+
d.voice_in_trunk_group = original_group
|
|
107
|
+
else
|
|
108
|
+
# nil unassigns only that relationship, so both are set
|
|
109
|
+
d.voice_in_trunk = nil
|
|
110
|
+
d.voice_in_trunk_group = nil
|
|
111
|
+
end
|
|
112
|
+
d.description = original_description
|
|
113
|
+
end
|
|
114
|
+
puts "\nRestored the DID's original routing:"
|
|
115
|
+
begin
|
|
116
|
+
print_did_assignment(did.id)
|
|
117
|
+
rescue StandardError => e
|
|
118
|
+
puts " (could not read the routing back: #{e.message})"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
ensure
|
|
122
|
+
# Deleted also when the restore fails
|
|
123
|
+
{ 'trunk' => trunk, 'trunk group' => trunk_group }.each do |label, resource|
|
|
124
|
+
next unless resource&.persisted?
|
|
125
|
+
|
|
126
|
+
if resource.destroy
|
|
127
|
+
puts "Deleted #{label} #{resource.id}"
|
|
128
|
+
else
|
|
129
|
+
puts "Error deleting #{label} #{resource.id}: #{resource.errors.full_messages}"
|
|
130
|
+
end
|
|
131
|
+
end
|
|
92
132
|
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
133
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Lists and cancels customer Emergency Calling Services (2026-04-16).
|
|
3
3
|
#
|
|
4
4
|
# An EmergencyCallingService represents a customer's 911/112 subscription
|
|
5
|
-
# attached to one or more DIDs. It ties an address, identity,
|
|
5
|
+
# attached to one or more DIDs. It ties an address, identity, number type
|
|
6
6
|
# and country together with a pricing snapshot (meta.setup_price, meta.monthly_price).
|
|
7
7
|
#
|
|
8
8
|
# Supported operations: index, show, destroy (cancel).
|
|
@@ -19,7 +19,7 @@ end
|
|
|
19
19
|
|
|
20
20
|
puts '=== Emergency Calling Services ==='
|
|
21
21
|
services = DIDWW::Client.emergency_calling_services
|
|
22
|
-
.includes(:country, :
|
|
22
|
+
.includes(:country, :dids)
|
|
23
23
|
.all
|
|
24
24
|
puts "Found #{services.size} emergency calling services"
|
|
25
25
|
|
|
@@ -29,7 +29,7 @@ services.first(5).each do |svc|
|
|
|
29
29
|
puts " Reference: #{svc.reference}"
|
|
30
30
|
puts " Status: #{svc.status}"
|
|
31
31
|
puts " Country: #{svc.country&.name}"
|
|
32
|
-
puts "
|
|
32
|
+
puts " Number type: #{svc.number_type}"
|
|
33
33
|
puts " Activated: #{svc.activated_at}"
|
|
34
34
|
puts " Canceled: #{svc.canceled_at}" if svc.canceled_at
|
|
35
35
|
puts " Renews: #{svc.renew_date}" if svc.renew_date
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# Lists emergency service requirements for a country/
|
|
2
|
+
# Lists emergency service requirements for a country/number_type.
|
|
3
3
|
#
|
|
4
4
|
# Emergency requirements describe what address precision, identity type,
|
|
5
5
|
# and supporting fields an end-customer must provide to enable 911/112
|
|
@@ -18,14 +18,14 @@ end
|
|
|
18
18
|
|
|
19
19
|
puts '=== Emergency Requirements ==='
|
|
20
20
|
requirements = DIDWW::Client.emergency_requirements
|
|
21
|
-
.includes(:country
|
|
21
|
+
.includes(:country)
|
|
22
22
|
.all
|
|
23
23
|
puts "Found #{requirements.size} emergency requirements"
|
|
24
24
|
|
|
25
25
|
requirements.first(5).each do |req|
|
|
26
26
|
puts "\nRequirement: #{req.id}"
|
|
27
27
|
puts " Country: #{req.country&.name}"
|
|
28
|
-
puts "
|
|
28
|
+
puts " Number type: #{req.number_type}"
|
|
29
29
|
puts " Identity type required: #{req.identity_type}"
|
|
30
30
|
puts " Address area level: #{req.address_area_level}"
|
|
31
31
|
puts " Address mandatory fields: #{req.address_mandatory_fields&.join(', ')}"
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Calling Service:
|
|
6
6
|
#
|
|
7
7
|
# 1. Find a DID with the emergency feature that is not yet emergency-enabled.
|
|
8
|
-
# 2. Look up emergency requirements for that DID's country +
|
|
8
|
+
# 2. Look up emergency requirements for that DID's country + number_type.
|
|
9
9
|
# 3. Find an existing identity on the account.
|
|
10
10
|
# 4. Find an existing address for that identity.
|
|
11
11
|
# 5. Validate the (emergency_requirement, address, identity) triple.
|
|
@@ -56,8 +56,8 @@ abort "Failed to order DID: #{order.errors.full_messages}" unless order.save
|
|
|
56
56
|
|
|
57
57
|
puts " Order: #{order.id} — #{order.status}"
|
|
58
58
|
|
|
59
|
-
# Wait for order to complete
|
|
60
|
-
|
|
59
|
+
# Wait up to 120 s for the order to complete
|
|
60
|
+
24.times do
|
|
61
61
|
break if order.status == 'completed'
|
|
62
62
|
sleep 5
|
|
63
63
|
order = DIDWW::Client.orders.find(order.id).first
|
|
@@ -69,7 +69,7 @@ puts ' Order completed'
|
|
|
69
69
|
puts "\n=== Step 1: Find the newly ordered DID ==="
|
|
70
70
|
dids = DIDWW::Client.dids
|
|
71
71
|
.where('did_group.features': 'emergency', emergency_enabled: false)
|
|
72
|
-
.includes(:did_group, 'did_group.country',
|
|
72
|
+
.includes(:did_group, 'did_group.country', :emergency_calling_service)
|
|
73
73
|
.order('-created_at')
|
|
74
74
|
.page(1).per(10)
|
|
75
75
|
.all
|
|
@@ -80,21 +80,21 @@ abort 'No available DID without an existing Emergency Calling Service.' unless d
|
|
|
80
80
|
|
|
81
81
|
did_group = did.did_group
|
|
82
82
|
country = did_group.country
|
|
83
|
-
|
|
83
|
+
number_type = did_group.number_type
|
|
84
84
|
|
|
85
85
|
puts " DID: #{did.number} (#{did.id})"
|
|
86
86
|
puts " DID Group: #{did_group.id}"
|
|
87
87
|
puts " Country: #{country&.name} (#{country&.id})"
|
|
88
|
-
puts "
|
|
88
|
+
puts " Number type: #{number_type}"
|
|
89
89
|
|
|
90
90
|
# === Step 2: Get emergency requirements ===
|
|
91
|
-
puts "\n=== Step 2: Get emergency requirements for country +
|
|
91
|
+
puts "\n=== Step 2: Get emergency requirements for country + number_type ==="
|
|
92
92
|
requirements = DIDWW::Client.emergency_requirements
|
|
93
|
-
.where('country.id': country.id,
|
|
93
|
+
.where('country.id': country.id, number_type: number_type)
|
|
94
94
|
.all
|
|
95
95
|
|
|
96
96
|
requirement = requirements.first
|
|
97
|
-
abort "No emergency requirements found for country #{country.name} / #{
|
|
97
|
+
abort "No emergency requirements found for country #{country.name} / #{number_type}." unless requirement
|
|
98
98
|
|
|
99
99
|
puts " Emergency Requirement: #{requirement.id}"
|
|
100
100
|
puts " Identity type: #{requirement.identity_type}"
|
|
@@ -182,7 +182,7 @@ ecs = fetched.emergency_calling_service
|
|
|
182
182
|
if ecs
|
|
183
183
|
# Re-fetch with includes for full details
|
|
184
184
|
service = DIDWW::Client.emergency_calling_services
|
|
185
|
-
.includes(:country, :
|
|
185
|
+
.includes(:country, :dids)
|
|
186
186
|
.find(ecs.id)
|
|
187
187
|
.first
|
|
188
188
|
|
|
@@ -191,7 +191,7 @@ if ecs
|
|
|
191
191
|
puts " Reference: #{service.reference}"
|
|
192
192
|
puts " Status: #{service.status}"
|
|
193
193
|
puts " Country: #{service.country&.name}"
|
|
194
|
-
puts "
|
|
194
|
+
puts " Number type: #{service.number_type}"
|
|
195
195
|
puts " Attached DIDs: #{service.dids.map(&:number).join(', ')}" if service.dids&.any?
|
|
196
196
|
if service.meta
|
|
197
197
|
puts " Setup price: #{service.meta[:setup_price]}" if service.meta[:setup_price]
|
|
@@ -50,11 +50,13 @@ puts "Found #{approved.size} approved verifications"
|
|
|
50
50
|
#
|
|
51
51
|
# suffix = SecureRandom.hex(4)
|
|
52
52
|
# verification = DIDWW::Client.emergency_verifications.new(
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
# DIDWW::Resource::
|
|
56
|
-
#
|
|
57
|
-
#
|
|
53
|
+
# external_reference_id: "ruby-ev-#{suffix}",
|
|
54
|
+
# relationships: {
|
|
55
|
+
# address: DIDWW::Resource::Address.load(id: '<address-uuid>'),
|
|
56
|
+
# emergency_calling_service:
|
|
57
|
+
# DIDWW::Resource::EmergencyCallingService.load(id: '<ecs-uuid>'),
|
|
58
|
+
# dids: [DIDWW::Resource::Did.load(id: '<did-uuid>')]
|
|
59
|
+
# }
|
|
58
60
|
# )
|
|
59
61
|
#
|
|
60
62
|
# if verification.save
|
data/examples/exports.rb
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Creates SMS exports (sms_in / sms_out) for yesterday and downloads the
|
|
3
|
+
# first completed one.
|
|
4
|
+
#
|
|
5
|
+
# Filters on SMS exports:
|
|
6
|
+
# * from, to (required) — "YYYY-MM-DD HH:MM:SS" UTC; from inclusive, to exclusive
|
|
7
|
+
# * source_address_eq / _cont, destination_address_eq / _cont, status, sms_id
|
|
8
|
+
# * sms_trunk_id — one id or an array, sent as sms_trunk.id
|
|
9
|
+
# * sms_in only: trunk_type, one or more of ExportFilters::TRUNK_TYPES
|
|
10
|
+
# * sms_out only: service_type (one of ExportFilters::SERVICE_TYPES), sender_id_verification_id
|
|
11
|
+
#
|
|
12
|
+
# Usage: DIDWW_API_KEY=your_api_key ruby examples/exports_sms.rb
|
|
13
|
+
|
|
14
|
+
require 'bundler/setup'
|
|
15
|
+
require 'didww'
|
|
16
|
+
require 'securerandom'
|
|
17
|
+
|
|
18
|
+
DIDWW::Client.configure do |client|
|
|
19
|
+
client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
|
|
20
|
+
client.api_mode = :sandbox
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
today = Date.today
|
|
24
|
+
yesterday = today - 1
|
|
25
|
+
suffix = SecureRandom.hex(4)
|
|
26
|
+
|
|
27
|
+
puts '=== Creating SMS-Out Export (A2P, yesterday) ==='
|
|
28
|
+
sms_out_export = DIDWW::Client.exports.new(
|
|
29
|
+
export_type: DIDWW::Resource::Export::EXPORT_TYPE_SMS_OUT,
|
|
30
|
+
filters: DIDWW::ComplexObject::ExportFilters.new(
|
|
31
|
+
from: "#{yesterday} 00:00:00",
|
|
32
|
+
to: "#{today} 00:00:00",
|
|
33
|
+
service_type: DIDWW::ComplexObject::ExportFilters::SERVICE_TYPE_A2P
|
|
34
|
+
),
|
|
35
|
+
external_reference_id: "ruby-sms-out-#{suffix}"
|
|
36
|
+
)
|
|
37
|
+
if sms_out_export.save
|
|
38
|
+
puts "Created SMS-Out export: #{sms_out_export.id} (status: #{sms_out_export.status})"
|
|
39
|
+
else
|
|
40
|
+
puts "Error creating SMS-Out export: #{sms_out_export.errors.full_messages}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
puts "\n=== Creating SMS-In Export (HTTP IN and email trunks, yesterday) ==="
|
|
44
|
+
sms_in_export = DIDWW::Client.exports.new(
|
|
45
|
+
export_type: DIDWW::Resource::Export::EXPORT_TYPE_SMS_IN,
|
|
46
|
+
filters: DIDWW::ComplexObject::ExportFilters.new(
|
|
47
|
+
from: "#{yesterday} 00:00:00",
|
|
48
|
+
to: "#{today} 00:00:00",
|
|
49
|
+
trunk_type: [
|
|
50
|
+
DIDWW::ComplexObject::ExportFilters::TRUNK_TYPE_HTTP_IN,
|
|
51
|
+
DIDWW::ComplexObject::ExportFilters::TRUNK_TYPE_SMS_TO_EMAIL
|
|
52
|
+
]
|
|
53
|
+
),
|
|
54
|
+
external_reference_id: "ruby-sms-in-#{suffix}"
|
|
55
|
+
)
|
|
56
|
+
if sms_in_export.save
|
|
57
|
+
puts "Created SMS-In export: #{sms_in_export.id} (status: #{sms_in_export.status})"
|
|
58
|
+
else
|
|
59
|
+
puts "Error creating SMS-In export: #{sms_in_export.errors.full_messages}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
puts "\n=== Completed SMS-Out exports ==="
|
|
63
|
+
completed = DIDWW::Client.exports
|
|
64
|
+
.where(export_type: DIDWW::Resource::Export::EXPORT_TYPE_SMS_OUT, status: DIDWW::Resource::Export::STATUS_COMPLETED)
|
|
65
|
+
.all
|
|
66
|
+
puts "Found #{completed.size} completed SMS-Out exports"
|
|
67
|
+
|
|
68
|
+
if (export = completed.first)
|
|
69
|
+
csv = export.csv
|
|
70
|
+
header = csv.gets
|
|
71
|
+
puts "Export #{export.id} (#{export.export_type}) columns: #{header}"
|
|
72
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Creates an identity and an address, encrypts and uploads a file, attaches a
|
|
3
|
+
# proof to the identity and one to the address, prints their verified flags,
|
|
4
|
+
# and deletes the address and the identity.
|
|
5
|
+
#
|
|
6
|
+
# 1. Create a personal identity with a country and a birth country (2026-04-16)
|
|
7
|
+
# 2. Create an address linked to the identity
|
|
8
|
+
# 3. Pick a proof type for each: entity_type "personal" and "address"
|
|
9
|
+
# 4. Encrypt sample.pdf and upload it twice, one file per proof
|
|
10
|
+
# 5. Create the proofs; DIDWW reviews them and sets verified later
|
|
11
|
+
# 6. Clean up, also when a step fails
|
|
12
|
+
#
|
|
13
|
+
# Usage: DIDWW_API_KEY=your_api_key ruby examples/identity_address_proofs.rb
|
|
14
|
+
|
|
15
|
+
require 'bundler/setup'
|
|
16
|
+
require 'didww'
|
|
17
|
+
require 'stringio'
|
|
18
|
+
|
|
19
|
+
DIDWW::Client.configure do |client|
|
|
20
|
+
client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
|
|
21
|
+
client.api_mode = :sandbox
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Encrypts content and uploads it; returns the encrypted file ID
|
|
25
|
+
def upload_encrypted(enc, content, name)
|
|
26
|
+
DIDWW::Resource::EncryptedFile.upload(
|
|
27
|
+
encryption_fingerprint: enc.encryption_fingerprint,
|
|
28
|
+
file: Faraday::Multipart::FilePart.new(StringIO.new(enc.encrypt(content)), 'application/octet-stream', "#{name}.enc"),
|
|
29
|
+
description: name
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# entity is the identity or the address the proof is for
|
|
34
|
+
def create_proof(label, entity, proof_type, file_id)
|
|
35
|
+
proof = DIDWW::Client.proofs.new
|
|
36
|
+
proof.entity = entity
|
|
37
|
+
proof.proof_type = proof_type
|
|
38
|
+
proof.files = [DIDWW::Resource::EncryptedFile.load(id: file_id)]
|
|
39
|
+
abort "Error creating #{label} proof: #{proof.errors.full_messages}" unless proof.save
|
|
40
|
+
puts "Created #{label} proof: #{proof.id} (type=#{proof_type.name})"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
country = DIDWW::Client.countries.where(iso: 'US').all.first
|
|
44
|
+
abort 'Country US not found' unless country
|
|
45
|
+
puts "Using country: #{country.name} (#{country.id})"
|
|
46
|
+
|
|
47
|
+
identity = nil
|
|
48
|
+
address = nil
|
|
49
|
+
file_ids = []
|
|
50
|
+
begin
|
|
51
|
+
puts "\n=== Creating Identity ==="
|
|
52
|
+
identity = DIDWW::Client.identities.new(
|
|
53
|
+
identity_type: DIDWW::Resource::Identity::IDENTITY_TYPE_PERSONAL,
|
|
54
|
+
first_name: 'John',
|
|
55
|
+
last_name: 'Doe',
|
|
56
|
+
phone_number: '12125551234'
|
|
57
|
+
)
|
|
58
|
+
identity.country = country
|
|
59
|
+
identity.birth_country = country # 2026-04-16
|
|
60
|
+
abort "Error creating identity: #{identity.errors.full_messages}" unless identity.save
|
|
61
|
+
puts "Created identity: #{identity.id} (#{identity.first_name} #{identity.last_name})"
|
|
62
|
+
|
|
63
|
+
puts "\n=== Creating Address ==="
|
|
64
|
+
address = DIDWW::Client.addresses.new(
|
|
65
|
+
city_name: 'New York',
|
|
66
|
+
postal_code: '10001',
|
|
67
|
+
address: '123 Main St'
|
|
68
|
+
)
|
|
69
|
+
address.identity = identity
|
|
70
|
+
address.country = country
|
|
71
|
+
abort "Error creating address: #{address.errors.full_messages}" unless address.save
|
|
72
|
+
puts "Created address: #{address.id} (#{address.address})"
|
|
73
|
+
|
|
74
|
+
puts "\n=== Proof Types ==="
|
|
75
|
+
proof_types = DIDWW::Client.proof_types.all
|
|
76
|
+
identity_proof_type = proof_types.find { |pt| pt.entity_type == DIDWW::Resource::Identity::IDENTITY_TYPE_PERSONAL }
|
|
77
|
+
address_proof_type = proof_types.find { |pt| pt.entity_type == 'address' }
|
|
78
|
+
abort 'No proof type for personal identities' unless identity_proof_type
|
|
79
|
+
abort 'No proof type for addresses' unless address_proof_type
|
|
80
|
+
puts "Identity proof type: #{identity_proof_type.name} (#{identity_proof_type.id})"
|
|
81
|
+
puts "Address proof type: #{address_proof_type.name} (#{address_proof_type.id})"
|
|
82
|
+
|
|
83
|
+
puts "\n=== Encrypting and Uploading Files ==="
|
|
84
|
+
content = File.binread(File.join(__dir__, 'sample.pdf'))
|
|
85
|
+
enc = DIDWW::Encrypt.new # fetches the public keys
|
|
86
|
+
file_ids << upload_encrypted(enc, content, 'identity_proof.pdf')
|
|
87
|
+
file_ids << upload_encrypted(enc, content, 'address_proof.pdf')
|
|
88
|
+
puts "Uploaded encrypted files: #{file_ids.join(', ')}"
|
|
89
|
+
|
|
90
|
+
puts "\n=== Creating Proofs ==="
|
|
91
|
+
create_proof('identity', identity, identity_proof_type, file_ids[0])
|
|
92
|
+
create_proof('address', address, address_proof_type, file_ids[1])
|
|
93
|
+
|
|
94
|
+
puts "\n=== Verified Flags ==="
|
|
95
|
+
puts "Identity #{identity.id}: verified=#{DIDWW::Client.identities.find(identity.id).first.verified}"
|
|
96
|
+
puts "Address #{address.id}: verified=#{DIDWW::Client.addresses.find(address.id).first.verified}"
|
|
97
|
+
ensure
|
|
98
|
+
puts "\n=== Cleaning Up ==="
|
|
99
|
+
{ 'address' => address, 'identity' => identity }.each do |label, resource|
|
|
100
|
+
next unless resource&.persisted?
|
|
101
|
+
|
|
102
|
+
if resource.destroy
|
|
103
|
+
puts "Deleted #{label}: #{resource.id}"
|
|
104
|
+
else
|
|
105
|
+
puts "Error deleting #{label} #{resource.id}: #{resource.errors.full_messages}"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
file_ids.each do |file_id|
|
|
109
|
+
file = DIDWW::Resource::EncryptedFile.load(id: file_id)
|
|
110
|
+
if file.destroy
|
|
111
|
+
puts "Deleted encrypted file: #{file_id}"
|
|
112
|
+
else
|
|
113
|
+
puts "Error deleting encrypted file #{file_id}: #{file.errors.full_messages}"
|
|
114
|
+
end
|
|
115
|
+
rescue JsonApiClient::Errors::NotFound
|
|
116
|
+
puts "Encrypted file #{file_id} was removed with its proof"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Reads resources with included relationships (JSON:API `include`):
|
|
3
|
+
# regions with their country, DID groups with their SKUs, available DIDs with
|
|
4
|
+
# a nested include, DIDs with their voice trunk. Then shows how the SDK exposes
|
|
5
|
+
# an included relationship and a not-included one.
|
|
6
|
+
#
|
|
7
|
+
# * Included: the response carries `data` for the relationship and the record
|
|
8
|
+
# in `included`; the reader returns that record without another request.
|
|
9
|
+
# An empty to-one relationship reads as nil.
|
|
10
|
+
# * Not included: the response carries only `links`; the reader GETs the
|
|
11
|
+
# relationship's `related` link, one request per record. Include what you read.
|
|
12
|
+
#
|
|
13
|
+
# Usage: DIDWW_API_KEY=your_api_key ruby examples/includes.rb
|
|
14
|
+
|
|
15
|
+
require 'bundler/setup'
|
|
16
|
+
require 'didww'
|
|
17
|
+
|
|
18
|
+
DIDWW::Client.configure do |client|
|
|
19
|
+
client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
|
|
20
|
+
client.api_mode = :sandbox
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Regions with included country
|
|
24
|
+
puts '=== Regions with country ==='
|
|
25
|
+
regions = DIDWW::Client.regions.includes(:country).page(1).per(3).all
|
|
26
|
+
regions.each do |region|
|
|
27
|
+
puts " #{region.name} (#{region.iso}) - country: #{region.country&.name}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# DID groups with included stock keeping units (to-many)
|
|
31
|
+
puts "\n=== DID groups with SKUs ==="
|
|
32
|
+
did_groups = DIDWW::Client.did_groups.includes(:stock_keeping_units).page(1).per(3).all
|
|
33
|
+
did_groups.each do |group|
|
|
34
|
+
skus = group.stock_keeping_units || []
|
|
35
|
+
puts " #{group.prefix} #{group.area_name} - #{skus.size} SKU(s)"
|
|
36
|
+
skus.each { |sku| puts " $#{sku.monthly_price&.to_s('F')}/mo, #{sku.channels_included_count} channels" }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Available DIDs with a nested include: did_group and the group's SKUs
|
|
40
|
+
puts "\n=== Available DIDs with did_group.stock_keeping_units ==="
|
|
41
|
+
available_dids = DIDWW::Client.available_dids.includes('did_group.stock_keeping_units').page(1).per(3).all
|
|
42
|
+
available_dids.each do |available_did|
|
|
43
|
+
group = available_did.did_group
|
|
44
|
+
skus = group&.stock_keeping_units || []
|
|
45
|
+
puts " #{available_did.number} - group: #{group&.prefix} #{group&.area_name}, #{skus.size} SKU(s)"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# DIDs with included voice trunk; a DID without one reads nil
|
|
49
|
+
puts "\n=== DIDs with voice_in_trunk ==="
|
|
50
|
+
dids = DIDWW::Client.dids.includes(:voice_in_trunk).page(1).per(3).all
|
|
51
|
+
dids.each do |did|
|
|
52
|
+
puts " #{did.number} - trunk: #{did.voice_in_trunk&.name || '(none)'}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Included vs not included
|
|
56
|
+
puts "\n=== Included vs not included ==="
|
|
57
|
+
included = DIDWW::Client.regions.includes(:country).page(1).per(1).all.first
|
|
58
|
+
plain = DIDWW::Client.regions.page(1).per(1).all.first
|
|
59
|
+
if included && plain
|
|
60
|
+
# The raw relationship object of the response
|
|
61
|
+
puts " included: relationships.country has #{included.relationships.country.keys.sort.join(', ')}"
|
|
62
|
+
puts " not included: relationships.country has #{plain.relationships.country.keys.sort.join(', ')}"
|
|
63
|
+
puts " included: region.country = #{included.country&.name} (from the included data, no request)"
|
|
64
|
+
puts " not included: region.country = #{plain.country&.name} (GET #{plain.relationships.country.dig('links', 'related')})"
|
|
65
|
+
end
|
data/examples/orders.rb
CHANGED
|
@@ -26,16 +26,18 @@ end
|
|
|
26
26
|
|
|
27
27
|
# Create an order with DID order items
|
|
28
28
|
puts "\n=== Creating DID Order ==="
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
# A DID group with numbers in stock, so that the order can be filled
|
|
30
|
+
did_group = DIDWW::Client.did_groups
|
|
31
|
+
.where(is_available: true)
|
|
32
|
+
.includes(:stock_keeping_units)
|
|
33
|
+
.all
|
|
34
|
+
.find { |group| group.stock_keeping_units&.any? }
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
puts 'No DID group with stock_keeping_units found'
|
|
36
|
+
unless did_group
|
|
37
|
+
puts 'No available DID group with stock_keeping_units found'
|
|
35
38
|
exit 1
|
|
36
39
|
end
|
|
37
40
|
|
|
38
|
-
did_group = did_groups.first
|
|
39
41
|
sku = did_group.stock_keeping_units.first
|
|
40
42
|
|
|
41
43
|
did_item = DIDWW::ComplexObject::DidOrderItem.new(
|