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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +8 -6
- data/.rubocop.yml +0 -110
- data/CHANGELOG.md +61 -0
- data/FILTERS.md +36 -12
- data/Gemfile +0 -2
- data/README.md +427 -56
- 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 +2 -1
- 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 +62 -24
- 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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# CRUD for SMS trunks: lists trunks, creates an HTTP IN trunk, updates its
|
|
3
|
+
# configuration, and deletes it.
|
|
4
|
+
#
|
|
5
|
+
# Configuration types (DIDWW::ComplexObject::SmsTrunkConfiguration):
|
|
6
|
+
# * sms_to_email, http_in — DIDWW delivers inbound messages by email or HTTP
|
|
7
|
+
# * http_out, smpp_esme — you connect to DIDWW; DIDWW generates the
|
|
8
|
+
# credentials, which are read-only
|
|
9
|
+
# * smpp_smsc — DIDWW binds to your SMSC
|
|
10
|
+
# The read-only allow_in / allow_out tell which directions a trunk handles.
|
|
11
|
+
#
|
|
12
|
+
# Usage: DIDWW_API_KEY=your_api_key ruby examples/sms_trunks.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
|
+
configurations = DIDWW::ComplexObject::SmsTrunkConfiguration
|
|
24
|
+
|
|
25
|
+
puts '=== Existing SMS Trunks ==='
|
|
26
|
+
trunks = DIDWW::Client.sms_trunks
|
|
27
|
+
.includes(:sms_trunk_group)
|
|
28
|
+
.all
|
|
29
|
+
|
|
30
|
+
puts "Found #{trunks.size} SMS trunks"
|
|
31
|
+
trunks.first(10).each do |trunk|
|
|
32
|
+
puts "#{trunk.name} [#{trunk.configuration&.type}]"
|
|
33
|
+
puts " ID: #{trunk.id}"
|
|
34
|
+
puts " Inbound: #{trunk.allow_in}, outbound: #{trunk.allow_out}"
|
|
35
|
+
puts " Group: #{trunk.sms_trunk_group.name}" if trunk.sms_trunk_group
|
|
36
|
+
puts " Submit URL: #{trunk.host}" if trunk.host
|
|
37
|
+
puts ''
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
puts "\n=== Creating HTTP IN Trunk ==="
|
|
41
|
+
suffix = SecureRandom.hex(4)
|
|
42
|
+
trunk = DIDWW::Client.sms_trunks.new(
|
|
43
|
+
name: "Ruby HTTP IN #{suffix}",
|
|
44
|
+
external_reference_id: "ruby-sms-#{suffix}",
|
|
45
|
+
configuration: configurations::HttpIn.new(
|
|
46
|
+
url: 'https://example.com/sms',
|
|
47
|
+
http_method: configurations::HttpIn::HTTP_METHOD_POST,
|
|
48
|
+
body_type: configurations::HttpIn::BODY_TYPE_JSON,
|
|
49
|
+
# Placeholders: {SMS_TEXT}, {SMS_TEXT_BASE64_ENCODED}, {SMS_SRC_ADDR}, {SMS_DST_ADDR}, {SMS_TIME}
|
|
50
|
+
body: '{"text":"{SMS_TEXT}","from":"{SMS_SRC_ADDR}","to":"{SMS_DST_ADDR}"}',
|
|
51
|
+
validate_https_certificate: true
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
unless trunk.save
|
|
56
|
+
abort "Error creating SMS trunk: #{trunk.errors.full_messages}"
|
|
57
|
+
end
|
|
58
|
+
puts "Created SMS trunk: #{trunk.id} - #{trunk.name}"
|
|
59
|
+
puts " Configuration: #{trunk.configuration.type} -> #{trunk.configuration.url}"
|
|
60
|
+
|
|
61
|
+
begin
|
|
62
|
+
# The configuration type cannot change; members left out keep their values.
|
|
63
|
+
puts "\n=== Updating HTTP IN Trunk ==="
|
|
64
|
+
trunk.name = "Ruby HTTP IN #{suffix} (v2)"
|
|
65
|
+
trunk.configuration = configurations::HttpIn.new(url: 'https://example.com/sms/v2')
|
|
66
|
+
if trunk.save
|
|
67
|
+
puts "Updated: #{trunk.name} -> #{trunk.configuration.url}"
|
|
68
|
+
else
|
|
69
|
+
puts "Error updating SMS trunk: #{trunk.errors.full_messages}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# The generated credentials of http_out and smpp_esme trunks are rotated with
|
|
73
|
+
# regenerate_credentials and read back from the trunk:
|
|
74
|
+
#
|
|
75
|
+
# esme = DIDWW::Client.sms_trunks.find('smpp-esme-trunk-uuid').first
|
|
76
|
+
# esme.regenerate_credentials
|
|
77
|
+
# esme = DIDWW::Client.sms_trunks.find(esme.id).first
|
|
78
|
+
# puts esme.configuration.system_id
|
|
79
|
+
ensure
|
|
80
|
+
puts "\n=== Deleting SMS Trunk ==="
|
|
81
|
+
puts trunk.destroy ? 'SMS trunk deleted' : "Error deleting SMS trunk: #{trunk.errors.full_messages}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
puts "\nConfiguration types: #{configurations::TYPES.join(', ')}"
|