telnyx-seti-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- 基于Telnyx OpenAPI规范自动生成,请勿编辑。 -->
Telnyx Seti - Ruby
Telnyx Seti - Ruby
Installation
安装
bash
gem install telnyxbash
gem install telnyxSetup
配置
ruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted
)All examples below assume is already initialized as shown above.
clientruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # 这是默认配置,可以省略
)以下所有示例都假设已按照上述方式完成初始化。
clientError Handling
错误处理
All API calls can fail with network errors, rate limits (429), validation errors (422),
or authentication errors (401). Always handle errors in production code:
ruby
begin
result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello")
rescue Telnyx::Errors::APIConnectionError
puts "Network error — check connectivity and retry"
rescue Telnyx::Errors::RateLimitError
# 429: rate limited — wait and retry with exponential backoff
sleep(1) # Check Retry-After header for actual delay
rescue Telnyx::Errors::APIStatusError => e
puts "API error #{e.status}: #{e.message}"
if e.status == 422
puts "Validation error — check required fields and formats"
end
endCommon error codes: invalid API key, insufficient permissions,
resource not found, validation error (check field formats),
rate limited (retry with exponential backoff).
401403404422429所有API调用都可能因网络错误、速率限制(429)、验证错误(422)或认证错误(401)而失败。在生产环境代码中请务必做好错误处理:
ruby
begin
result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello")
rescue Telnyx::Errors::APIConnectionError
puts "网络错误 — 检查网络连接后重试"
rescue Telnyx::Errors::RateLimitError
# 429: 触发速率限制 — 等待后使用指数退避策略重试
sleep(1) # 可查看Retry-After响应头获取准确的等待时长
rescue Telnyx::Errors::APIStatusError => e
puts "API错误 #{e.status}: #{e.message}"
if e.status == 422
puts "验证错误 — 检查必填字段和格式是否正确"
end
end常见错误码: API密钥无效, 权限不足, 资源不存在, 验证错误(请检查字段格式), 触发速率限制(请使用指数退避策略重试)。
401403404422429Get Enum
获取枚举值
GET /10dlc/enum/{endpoint}ruby
response = client.messaging_10dlc.get_enum(:mno)
puts(response)GET /10dlc/enum/{endpoint}ruby
response = client.messaging_10dlc.get_enum(:mno)
puts(response)Retrieve Black Box Test Results
获取黑盒测试结果
Returns the results of the various black box tests
GET /seti/black_box_test_resultsruby
response = client.seti.retrieve_black_box_test_results
puts(response)Returns: (array[object]), (string), (string)
black_box_testsproductrecord_type返回各类黑盒测试的结果
GET /seti/black_box_test_resultsruby
response = client.seti.retrieve_black_box_test_results
puts(response)返回值:(对象数组)、(字符串)、(字符串)
black_box_testsproductrecord_type