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.
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 +65 -0
  5. data/FILTERS.md +36 -12
  6. data/Gemfile +0 -2
  7. data/README.md +431 -58
  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 +7 -5
  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 +63 -25
  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
@@ -0,0 +1,215 @@
1
+ # frozen_string_literal: true
2
+ require 'digest'
3
+ require 'json'
4
+ require 'active_support/notifications'
5
+ require 'didww/errors'
6
+ require 'didww/http'
7
+ require 'didww/auth/token'
8
+
9
+ module DIDWW
10
+ module Auth
11
+ class TokenProvider
12
+ CACHE_KEY_PREFIX = 'didww:token:v1:'
13
+ NOTIFICATION = 'mint_token.didww'
14
+ BACKOFF_BASE = 0.5
15
+ BACKOFF_CAP = 8
16
+ MAX_ATTEMPTS = 4
17
+ # The longest lifetime the token service grants: the fewer mints, the better.
18
+ REQUESTED_LIFETIME = 3600
19
+ RETRY_SPREAD_RATIO = 0.2
20
+ MIN_RETRY_SPREAD = 1
21
+ TIMEOUT = 10
22
+ TRANSPORT_ERRORS = [
23
+ Faraday::ConnectionFailed,
24
+ Faraday::TimeoutError
25
+ ].freeze
26
+
27
+ def initialize(sleeper: ->(seconds) { sleep(seconds) }, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) })
28
+ @sleeper = sleeper
29
+ @clock = clock
30
+ @lock = Mutex.new
31
+ @key_locks = {}
32
+ @blocked_until = {}
33
+ @failures = {}
34
+ end
35
+
36
+ # @param audience [String] production hostname of the service called
37
+ # @return [DIDWW::Auth::Token]
38
+ # @raise [DIDWW::Auth::Error]
39
+ def token_for(audience)
40
+ key = cache_key(audience)
41
+ cached_token(key) || begin
42
+ failure_seen = last_failure(key)
43
+ key_lock(key).synchronize { cached_token(key) || raise_failure_since!(key, failure_seen) || mint!(key, audience) }
44
+ end
45
+ end
46
+
47
+ # Evicts the cached token only while it is still the one that was refused,
48
+ # so a token another thread has just minted survives.
49
+ def invalidate(audience, access_token)
50
+ key = cache_key(audience)
51
+ key_lock(key).synchronize { store.delete(key) if cached_token(key)&.access_token == access_token }
52
+ end
53
+
54
+ private
55
+
56
+ def store
57
+ DIDWW::Client.token_store
58
+ end
59
+
60
+ def logger
61
+ DIDWW::Client.logger
62
+ end
63
+
64
+ def cache_key(audience)
65
+ parts = [
66
+ DIDWW::Client.auth_base_url,
67
+ api_key_digest,
68
+ audience,
69
+ DIDWW::Client.api_version,
70
+ DIDWW::Client.scope || '-'
71
+ ]
72
+ CACHE_KEY_PREFIX + Digest::SHA256.hexdigest(parts.join("\n"))
73
+ end
74
+
75
+ def rate_limit_key
76
+ [DIDWW::Client.auth_base_url, api_key_digest].join("\n")
77
+ end
78
+
79
+ def api_key_digest
80
+ Digest::SHA256.hexdigest(DIDWW::Client.api_key.to_s)
81
+ end
82
+
83
+ def key_lock(key)
84
+ @lock.synchronize { @key_locks[key] ||= Mutex.new }
85
+ end
86
+
87
+ def cached_token(key)
88
+ data = store.read(key)
89
+ Token.from_h(data) if data
90
+ end
91
+
92
+ def last_failure(key)
93
+ @lock.synchronize { @failures[key] }
94
+ end
95
+
96
+ # Callers queued behind a mint that failed raise its error instead of repeating the retries.
97
+ def raise_failure_since!(key, failure_seen)
98
+ failure = last_failure(key)
99
+ raise failure if failure && !failure.equal?(failure_seen)
100
+ end
101
+
102
+ def mint!(key, audience)
103
+ raise_if_rate_limited!
104
+ token = request_token!(token_request(audience))
105
+ store.write(key, token.to_h, expires_in: token.expires_in)
106
+ token
107
+ rescue ServerError, ConnectionError => e
108
+ @lock.synchronize { @failures[key] = e }
109
+ raise
110
+ end
111
+
112
+ def request_token!(request)
113
+ ActiveSupport::Notifications.instrument(NOTIFICATION, aud: request[:aud], scope_requested: request[:scope]) do |payload|
114
+ token_from!(post_token!(request)).tap do |token|
115
+ verify_grant!(token, request)
116
+ payload.merge!(aud: token.aud, scope_granted: token.scope, api_version: token.api_version, expires_in: token.expires_in)
117
+ end
118
+ end
119
+ end
120
+
121
+ def token_request(audience)
122
+ request = { aud: [audience], api_version: DIDWW::Client.api_version }
123
+ request[:scope] = DIDWW::Client.scope.to_s if DIDWW::Client.scope
124
+ request[:expires_in] = REQUESTED_LIFETIME
125
+ request
126
+ end
127
+
128
+ def raise_if_rate_limited!
129
+ blocked_until = @lock.synchronize { @blocked_until[rate_limit_key] }
130
+ remaining = blocked_until && blocked_until - @clock.call
131
+ if remaining&.positive?
132
+ raise RateLimited.new(status: 429, error: 'rate_limit_exceeded', retry_after: remaining.ceil)
133
+ end
134
+ end
135
+
136
+ def post_token!(request, attempt = 1)
137
+ response = auth_connection.post('token', JSON.generate(request), token_headers)
138
+ return response if response.status < 500 || attempt == MAX_ATTEMPTS
139
+
140
+ backoff!(attempt)
141
+ post_token!(request, attempt + 1)
142
+ rescue Faraday::SSLError => e
143
+ raise ConnectionError.new(e.message)
144
+ rescue *TRANSPORT_ERRORS => e
145
+ raise ConnectionError.new(e.message) if attempt == MAX_ATTEMPTS
146
+
147
+ backoff!(attempt)
148
+ post_token!(request, attempt + 1)
149
+ end
150
+
151
+ def auth_connection
152
+ DIDWW::Http.connection(DIDWW::Client.auth_base_url, timeout: TIMEOUT)
153
+ end
154
+
155
+ def token_headers
156
+ {
157
+ 'Content-Type' => 'application/json',
158
+ 'Accept' => 'application/json',
159
+ 'Api-Key' => DIDWW::Client.api_key.to_s
160
+ }
161
+ end
162
+
163
+ def backoff!(attempt)
164
+ @sleeper.call(rand * [BACKOFF_CAP, BACKOFF_BASE * (2**attempt)].min)
165
+ end
166
+
167
+ # Spreads the next mints of processes that got the same Retry-After.
168
+ def retry_window(retry_after)
169
+ retry_after + (rand * [MIN_RETRY_SPREAD, RETRY_SPREAD_RATIO * retry_after].max)
170
+ end
171
+
172
+ def token_from!(response)
173
+ body = parse_body(response.body)
174
+ error_fields = { status: response.status, error: body['error'], error_description: body['error_description'] }
175
+ case response.status
176
+ when 200
177
+ Token.from_h(body.merge('minted_at' => Time.now.to_i))
178
+ when 400
179
+ raise InvalidRequest.new(**error_fields)
180
+ when 401
181
+ raise InvalidClient.new(**error_fields)
182
+ when 429
183
+ retry_after = [response.headers['Retry-After'].to_i, 1].max
184
+ @lock.synchronize { @blocked_until[rate_limit_key] = @clock.call + retry_window(retry_after) }
185
+ raise RateLimited.new(**error_fields, retry_after: retry_after)
186
+ when 500..599
187
+ raise ServerError.new(**error_fields)
188
+ else
189
+ raise Error.new(**error_fields)
190
+ end
191
+ end
192
+
193
+ def parse_body(body)
194
+ parsed = JSON.parse(body.to_s)
195
+ parsed.is_a?(Hash) ? parsed : {}
196
+ rescue JSON::ParserError
197
+ {}
198
+ end
199
+
200
+ def verify_grant!(token, request)
201
+ audience = request[:aud].first
202
+ if token.access_token.blank? || !token.aud.include?(audience)
203
+ raise InvalidGrant.new("Token service granted audience #{token.aud.inspect}, requested #{audience}", status: 200)
204
+ end
205
+
206
+ if request[:scope] && token.scope != request[:scope]
207
+ logger&.warn("DIDWW token scope mismatch: requested #{request[:scope]}, granted #{token.scope}")
208
+ end
209
+ if token.api_version != request[:api_version]
210
+ logger&.warn("DIDWW token api_version mismatch: requested #{request[:api_version]}, granted #{token.api_version}")
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'didww/http'
3
+
2
4
  module DIDWW
3
5
  # :nodoc:
4
6
  class BaseMiddleware < Faraday::Middleware
@@ -6,21 +8,18 @@ module DIDWW
6
8
  request_env[:request_headers].merge!(request_headers(request_env))
7
9
  request_env.url.host = URI(DIDWW::Client.api_base_url).host
8
10
 
9
- @app.call(request_env).on_complete do |response_env|
11
+ @app.call(request_env).on_complete do |_response_env|
10
12
  # do something with the response
11
- # response_env[:response_headers].merge!(...)
13
+ # _response_env[:response_headers].merge!(...)
12
14
  end
13
15
  end
14
16
 
15
17
  private
16
18
 
17
- def request_headers(request_env)
18
- headers = {
19
- 'User-Agent' => "didww-v3 Ruby gem v#{VERSION}",
19
+ def request_headers(_request_env)
20
+ {
21
+ 'User-Agent' => DIDWW::Http::USER_AGENT,
20
22
  }
21
- headers['Api-Key'] = DIDWW::Client.api_key unless request_env.url.path&.end_with?('/public_keys')
22
- headers['x-didww-api-version'] = DIDWW::Client.api_version unless DIDWW::Client.api_version.blank?
23
- headers
24
23
  end
25
24
  end
26
25
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
  require 'openssl'
3
+ require 'uri'
3
4
 
4
5
  module DIDWW
5
6
  module Callback
6
7
  # @example
7
- # validator = DIDWW::Callback::RequestValidator.new(api_key)
8
+ # validator = DIDWW::Callback::RequestValidator.new(callback_secret)
8
9
  # uri = request.original_url
9
10
  # if request.post?
10
11
  # # Collect all parameters passed from DIDWW.
@@ -20,8 +21,9 @@ module DIDWW
20
21
  DIGEST_ALGO = 'SHA1'
21
22
  HEADER = 'X-DIDWW-Signature'
22
23
 
23
- def initialize(api_key)
24
- @api_key = api_key
24
+ # @param callback_secret [String] the callback secret enabled in the DIDWW User Panel.
25
+ def initialize(callback_secret)
26
+ @callback_secret = callback_secret
25
27
  end
26
28
 
27
29
  # @param url [String]
@@ -29,7 +31,7 @@ module DIDWW
29
31
  # @param signature [String]
30
32
  # @return [Boolean] whether signature valid or not.
31
33
  def validate(url, payload, signature)
32
- return false if signature.blank?
34
+ return false if signature.nil? || signature.empty?
33
35
 
34
36
  OpenSSL.secure_compare(signature, valid_signature(url, payload))
35
37
  end
@@ -41,7 +43,7 @@ module DIDWW
41
43
  # @return [String] generated signature in URL safe format.
42
44
  def valid_signature(url, payload)
43
45
  data = normalize_url(url) + normalize_payload(payload)
44
- OpenSSL::HMAC.hexdigest(DIGEST_ALGO, @api_key, data)
46
+ OpenSSL::HMAC.hexdigest(DIGEST_ALGO, @callback_secret, data)
45
47
  end
46
48
 
47
49
  # @param payload [Hash,Array]
data/lib/didww/client.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
+ require 'logger'
2
3
  require 'active_support/core_ext/module/attribute_accessors'
3
4
  require 'active_support/core_ext/object/blank'
4
5
  require 'json_api_client'
5
6
 
7
+ require 'didww/version'
6
8
  require 'didww/resource/base'
9
+ require 'didww/auth/memory_store'
10
+ require 'didww/auth/token_provider'
7
11
 
8
12
  module DIDWW
9
13
  module Client
@@ -11,17 +15,59 @@ module DIDWW
11
15
  sandbox: 'https://sandbox-api.didww.com/v3/'.freeze,
12
16
  production: 'https://api.didww.com/v3/'.freeze
13
17
  }.freeze
18
+ AUTH_URLS = {
19
+ sandbox: 'https://auth-sandbox.didww.com'.freeze,
20
+ production: 'https://auth.didww.com'.freeze
21
+ }.freeze
22
+ PRICES_URLS = {
23
+ voice_in: {
24
+ sandbox: 'https://api-vin-sandbox.didww.com/v3/'.freeze,
25
+ production: 'https://api-vin.didww.com/v3/'.freeze
26
+ }.freeze,
27
+ voice_out: {
28
+ sandbox: 'https://api-vout-sandbox.didww.com/v3/'.freeze,
29
+ production: 'https://api-vout.didww.com/v3/'.freeze
30
+ }.freeze,
31
+ sms: {
32
+ sandbox: 'https://api-sms-sandbox.didww.com/v3/'.freeze,
33
+ production: 'https://api-sms.didww.com/v3/'.freeze
34
+ }.freeze
35
+ }.freeze
36
+ PRICES_URL_ENV = {
37
+ voice_in: 'DIDWW_API_VIN_URL',
38
+ voice_out: 'DIDWW_API_VOUT_URL',
39
+ sms: 'DIDWW_API_SMS_URL'
40
+ }.freeze
41
+ # Token audiences are production hostnames in every environment.
42
+ API_AUDIENCE = 'api.didww.com'
43
+ PRICES_AUDIENCES = {
44
+ voice_in: 'api-vin.didww.com',
45
+ voice_out: 'api-vout.didww.com',
46
+ sms: 'api-sms.didww.com'
47
+ }.freeze
48
+ SCOPES = %i[read full].freeze
14
49
  DEFAULT_MODE = :sandbox
15
- DEFAULT_API_VERSION = '2026-04-16'
50
+ DEFAULT_API_VERSION = '2026-11-19'
51
+ API_VERSION_FORMAT = /\A\d{4}-\d{2}-\d{2}\z/
52
+ API_VERSION_OVERRIDE_KEY = :didww_api_version
16
53
 
17
- mattr_accessor :api_key, :api_mode, :http_verbose, :api_version, :_customize_conn_block
54
+ mattr_accessor :api_key, :api_mode, :http_verbose, :api_version, :scope, :token_store, :token_provider, :logger,
55
+ :_customize_conn_block, :_customize_faraday_block
18
56
  self.api_version = DEFAULT_API_VERSION
57
+ self.token_store = Auth::MemoryStore.new
58
+ self.token_provider = Auth::TokenProvider.new
59
+ self.logger = Logger.new($stderr, level: :warn)
19
60
 
20
61
  class << self
21
62
  def customize_connection(&block)
22
63
  self._customize_conn_block = block
23
64
  end
24
65
 
66
+ # Applied to the token, prices, export download and file upload connections.
67
+ def customize_faraday(&block)
68
+ self._customize_faraday_block = block
69
+ end
70
+
25
71
  def configure
26
72
  yield self if block_given?
27
73
  connect!
@@ -38,21 +84,51 @@ module DIDWW
38
84
  end
39
85
 
40
86
  def api_version
41
- @@api_version
87
+ Thread.current[API_VERSION_OVERRIDE_KEY] || @@api_version # NOSONAR
42
88
  end
43
89
 
90
+ def api_version=(value)
91
+ @@api_version = validate_api_version!(value)
92
+ end
93
+
94
+ # The override is visible only to the calling thread.
44
95
  def with_api_version(api_version)
45
- old_api_version = self.api_version
46
- self.api_version = api_version
96
+ previous_api_version = Thread.current[API_VERSION_OVERRIDE_KEY] # NOSONAR
97
+ Thread.current[API_VERSION_OVERRIDE_KEY] = validate_api_version!(api_version) # NOSONAR
47
98
  yield
48
99
  ensure
49
- self.api_version = old_api_version
100
+ Thread.current[API_VERSION_OVERRIDE_KEY] = previous_api_version # NOSONAR
101
+ end
102
+
103
+ def scope=(value)
104
+ unless value.nil? || SCOPES.include?(value)
105
+ raise ArgumentError.new("Scope should be nil or in #{SCOPES} (given '#{value}').")
106
+ end
107
+ @@scope = value
50
108
  end
51
109
 
52
110
  def api_base_url
53
111
  ENV['DIDWW_API_URL'].presence || BASE_URLS[api_mode]
54
112
  end
55
113
 
114
+ def auth_base_url
115
+ ENV['DIDWW_AUTH_URL'].presence || AUTH_URLS[api_mode]
116
+ end
117
+
118
+ # @param service [Symbol] :voice_in, :voice_out or :sms
119
+ def prices_base_url(service)
120
+ ENV[PRICES_URL_ENV.fetch(service)].presence || PRICES_URLS.fetch(service)[api_mode]
121
+ end
122
+
123
+ # @param service [Symbol] :voice_in, :voice_out or :sms
124
+ def prices_audience(service)
125
+ PRICES_AUDIENCES.fetch(service)
126
+ end
127
+
128
+ def http_verbose?
129
+ ENV['HTTP_VERBOSE'] == 'true' || http_verbose
130
+ end
131
+
56
132
  def balance
57
133
  Resource::Balance.all.first
58
134
  end
@@ -63,15 +139,16 @@ module DIDWW
63
139
  shared_capacity_groups: 'SharedCapacityGroup',
64
140
  cities: 'City',
65
141
  countries: 'Country',
66
- did_group_types: 'DidGroupType',
67
142
  did_groups: 'DidGroup',
68
143
  dids: 'Did',
69
144
  orders: 'Order',
70
- pops: 'Pop',
71
145
  regions: 'Region',
72
146
  voice_in_trunk_groups: 'VoiceInTrunkGroup',
73
147
  voice_in_trunks: 'VoiceInTrunk',
74
148
  voice_out_trunks: 'VoiceOutTrunk',
149
+ sms_trunks: 'SmsTrunk',
150
+ sms_trunk_groups: 'SmsTrunkGroup',
151
+ sender_id_verifications: 'SenderIdVerification',
75
152
  available_dids: 'AvailableDid',
76
153
  did_reservations: 'DidReservation',
77
154
  address_requirements: 'AddressRequirement',
@@ -98,6 +175,30 @@ module DIDWW
98
175
  define_method(name) { Resource.const_get(klass) }
99
176
  end
100
177
 
178
+ def voice_in_prices
179
+ DIDWW::Prices.voice_in
180
+ end
181
+
182
+ def voice_out_prices
183
+ DIDWW::Prices.voice_out
184
+ end
185
+
186
+ def sms_out_a2p_prices
187
+ DIDWW::Prices.sms_out_a2p
188
+ end
189
+
190
+ def sms_out_p2p_prices
191
+ DIDWW::Prices.sms_out_p2p
192
+ end
193
+
194
+ def sms_out_otp_prices
195
+ DIDWW::Prices.sms_out_otp
196
+ end
197
+
198
+ def sms_in_prices
199
+ DIDWW::Prices.sms_in
200
+ end
201
+
101
202
  def api_mode=(arg)
102
203
  unless BASE_URLS.keys.include?(arg)
103
204
  raise ArgumentError.new("Mode should be in #{BASE_URLS.keys} (given '#{arg}').")
@@ -107,8 +208,14 @@ module DIDWW
107
208
 
108
209
  private
109
210
 
110
- def http_verbose?
111
- ENV['HTTP_VERBOSE'] == 'true' || http_verbose
211
+ def validate_api_version!(value)
212
+ unless value.is_a?(String) && API_VERSION_FORMAT.match?(value)
213
+ raise ArgumentError.new("API version should be a date in YYYY-MM-DD format (given '#{value}').")
214
+ end
215
+ if value < DEFAULT_API_VERSION
216
+ raise ArgumentError.new("API version #{value} is not supported by didww-v3 #{VERSION}, which starts at #{DEFAULT_API_VERSION}; use didww-v3 6.x for earlier API versions.")
217
+ end
218
+ value
112
219
  end
113
220
 
114
221
  def connect!
@@ -116,6 +223,7 @@ module DIDWW
116
223
  DIDWW::Resource::Base.connection do |connection|
117
224
  connection.use Faraday::Response::Logger if http_verbose?
118
225
  connection.use DIDWW::JsonapiMiddleware
226
+ connection.use DIDWW::Auth::BearerMiddleware, audience: API_AUDIENCE
119
227
  _customize_conn_block.call(connection) if _customize_conn_block
120
228
  end
121
229
  JsonApiClient::Paginating::Paginator.page_param = 'number'
@@ -129,12 +237,9 @@ module DIDWW
129
237
  require 'didww/resource/shared_capacity_group'
130
238
  require 'didww/resource/city'
131
239
  require 'didww/resource/country'
132
- require 'didww/resource/did_group_type'
133
240
  require 'didww/resource/did_group'
134
- require 'didww/resource/exclusive_relationship'
135
241
  require 'didww/resource/did'
136
242
  require 'didww/resource/order'
137
- require 'didww/resource/pop'
138
243
  require 'didww/resource/qty_based_pricing'
139
244
  require 'didww/resource/region'
140
245
  require 'didww/resource/stock_keeping_unit'
@@ -156,6 +261,10 @@ module DIDWW
156
261
  require 'didww/resource/area'
157
262
  require 'didww/resource/voice_out_trunk'
158
263
  require 'didww/resource/voice_out_trunk_regenerate_credential'
264
+ require 'didww/resource/sms_trunk' # NOSONAR
265
+ require 'didww/resource/sms_trunk_group' # NOSONAR
266
+ require 'didww/resource/sms_trunk_regenerate_credential' # NOSONAR
267
+ require 'didww/resource/sender_id_verification' # NOSONAR
159
268
  require 'didww/resource/nanpa_prefix'
160
269
  require 'didww/resource/did_history' # NOSONAR
161
270
  require 'didww/resource/emergency_requirement' # NOSONAR
@@ -28,6 +28,12 @@ module DIDWW
28
28
  def as_json(*)
29
29
  { type: type, attributes: attributes.as_json }.with_indifferent_access
30
30
  end
31
+
32
+ # Every value is redacted: which attributes of an unknown type carry credentials is not known.
33
+ def inspect
34
+ formatted = attributes.map { |k, v| "#{k}=#{(v.nil? ? v : FILTERED).inspect}" }
35
+ "#<#{self.class.name} type=#{type.inspect} #{formatted.join(' ')}>"
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -79,22 +79,6 @@ module DIDWW
79
79
  1505 => 'Ringing timeout'
80
80
  }.freeze
81
81
 
82
- CODECS = {
83
- 6 => 'telephone-event',
84
- 7 => 'G723',
85
- 8 => 'G729',
86
- 9 => 'PCMU',
87
- 10 => 'PCMA',
88
- 12 => 'speex',
89
- 13 => 'GSM',
90
- 14 => 'G726-32',
91
- 15 => 'G721',
92
- 16 => 'G726-24',
93
- 17 => 'G726-40',
94
- 18 => 'G726-16',
95
- 19 => 'L16'
96
- }.freeze
97
-
98
82
  DEFAULT_REROUTING_DISCONNECT_CODE_IDS = [
99
83
  56,
100
84
  58,
@@ -143,8 +127,6 @@ module DIDWW
143
127
  1505
144
128
  ].freeze
145
129
 
146
- DEFAULT_CODEC_IDS = [9, 10, 8, 7, 6].freeze
147
-
148
130
  DID_PLACEHOLDER = '{DID}'
149
131
  end
150
132
  end
@@ -7,10 +7,6 @@ module DIDWW
7
7
  # Type: String
8
8
  # Nullable: No
9
9
  # Description: Phone number
10
-
11
- DEFAULTS = {}.freeze
12
-
13
- RECOMMENDED = {}.freeze
14
10
  end
15
11
  end
16
12
  end