telnyx-webrtc-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
Telnyx Webrtc - Ruby
Telnyx Webrtc - 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密钥无效、 权限不足、 资源不存在、 校验错误(检查字段格式)、 触发速率限制(采用指数退避策略重试)。
401403404422429Important Notes
重要说明
- Pagination: Use for automatic iteration:
.auto_paging_each.page.auto_paging_each { |item| puts item.id }
- 分页: 使用实现自动迭代:
.auto_paging_each。page.auto_paging_each { |item| puts item.id }
List mobile push credentials
查询移动推送凭证列表
GET /mobile_push_credentialsruby
page = client.mobile_push_credentials.list
puts(page)Returns: (string), (string), (date-time), (string), (string), (object), (string), (string), (date-time)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atGET /mobile_push_credentialsruby
page = client.mobile_push_credentials.list
puts(page)返回字段: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (对象)、 (字符串)、 (字符串)、 (日期时间)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atCreates a new mobile push credential
创建新的移动推送凭证
POST /mobile_push_credentialstypecertificateprivate_keyaliasruby
push_credential_response = client.mobile_push_credentials.create(
create_mobile_push_credential_request: {
alias: "LucyIosCredential",
certificate: "-----BEGIN CERTIFICATE----- MIIGVDCCBTKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END CERTIFICATE-----",
private_key: "-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END RSA PRIVATE KEY-----",
type: :ios
}
)
puts(push_credential_response)Returns: (string), (string), (date-time), (string), (string), (object), (string), (string), (date-time)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atPOST /mobile_push_credentialstypecertificateprivate_keyaliasruby
push_credential_response = client.mobile_push_credentials.create(
create_mobile_push_credential_request: {
alias: "LucyIosCredential",
certificate: "-----BEGIN CERTIFICATE----- MIIGVDCCBTKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END CERTIFICATE-----",
private_key: "-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END RSA PRIVATE KEY-----",
type: :ios
}
)
puts(push_credential_response)返回字段: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (对象)、 (字符串)、 (字符串)、 (日期时间)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atRetrieves a mobile push credential
查询单个移动推送凭证
Retrieves mobile push credential based on the given
push_credential_idGET /mobile_push_credentials/{push_credential_id}ruby
push_credential_response = client.mobile_push_credentials.retrieve("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0")
puts(push_credential_response)Returns: (string), (string), (date-time), (string), (string), (object), (string), (string), (date-time)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_at根据提供的查询对应的移动推送凭证
push_credential_idGET /mobile_push_credentials/{push_credential_id}ruby
push_credential_response = client.mobile_push_credentials.retrieve("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0")
puts(push_credential_response)返回字段: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (对象)、 (字符串)、 (字符串)、 (日期时间)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atDeletes a mobile push credential
删除移动推送凭证
Deletes a mobile push credential based on the given
push_credential_idDELETE /mobile_push_credentials/{push_credential_id}ruby
result = client.mobile_push_credentials.delete("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0")
puts(result)根据提供的删除对应的移动推送凭证
push_credential_idDELETE /mobile_push_credentials/{push_credential_id}ruby
result = client.mobile_push_credentials.delete("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0")
puts(result)List all credentials
查询所有凭证
List all On-demand Credentials.
GET /telephony_credentialsruby
page = client.telephony_credentials.list
puts(page)Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id查询所有按需凭证。
GET /telephony_credentialsruby
page = client.telephony_credentials.list
puts(page)返回字段: (字符串)、 (布尔值)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idCreate a credential
创建凭证
Create a credential.
POST /telephony_credentialsconnection_idOptional: (string), (string), (string)
expires_atnametagruby
telephony_credential = client.telephony_credentials.create(connection_id: "1234567890")
puts(telephony_credential)Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id创建一个凭证。
POST /telephony_credentialsconnection_id可选参数: (字符串)、 (字符串)、 (字符串)
expires_atnametagruby
telephony_credential = client.telephony_credentials.create(connection_id: "1234567890")
puts(telephony_credential)返回字段: (字符串)、 (布尔值)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idGet a credential
查询单个凭证
Get the details of an existing On-demand Credential.
GET /telephony_credentials/{id}ruby
telephony_credential = client.telephony_credentials.retrieve("550e8400-e29b-41d4-a716-446655440000")
puts(telephony_credential)Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id查询现有按需凭证的详情。
GET /telephony_credentials/{id}ruby
telephony_credential = client.telephony_credentials.retrieve("550e8400-e29b-41d4-a716-446655440000")
puts(telephony_credential)返回字段: (字符串)、 (布尔值)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idUpdate a credential
更新凭证
Update an existing credential.
PATCH /telephony_credentials/{id}Optional: (string), (string), (string), (string)
connection_idexpires_atnametagruby
telephony_credential = client.telephony_credentials.update("550e8400-e29b-41d4-a716-446655440000")
puts(telephony_credential)Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id更新现有凭证。
PATCH /telephony_credentials/{id}可选参数: (字符串)、 (字符串)、 (字符串)、 (字符串)
connection_idexpires_atnametagruby
telephony_credential = client.telephony_credentials.update("550e8400-e29b-41d4-a716-446655440000")
puts(telephony_credential)返回字段: (字符串)、 (布尔值)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idDelete a credential
删除凭证
Delete an existing credential.
DELETE /telephony_credentials/{id}ruby
telephony_credential = client.telephony_credentials.delete("550e8400-e29b-41d4-a716-446655440000")
puts(telephony_credential)Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id删除现有凭证。
DELETE /telephony_credentials/{id}ruby
telephony_credential = client.telephony_credentials.delete("550e8400-e29b-41d4-a716-446655440000")
puts(telephony_credential)返回字段: (字符串)、 (布尔值)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id