telnyx-storage-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- 基于Telnyx OpenAPI规范自动生成,请勿编辑。 -->
Telnyx Storage - Ruby
Telnyx Storage - 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 "Network error — check connectivity and retry"
rescue Telnyx::Errors::RateLimitError
# 429: 触发速率限制 — 等待后使用指数退避策略重试
sleep(1) # 可查看Retry-After响应头获取准确的等待时长
rescue Telnyx::Errors::APIStatusError => e
puts "API error #{e.status}: #{e.message}"
if e.status == 422
puts "校验错误 — 检查必填字段和格式是否正确"
end
end常见错误码: 无效的API密钥, 权限不足, 资源未找到, 校验错误(请检查字段格式), 触发速率限制(请使用指数退避策略重试)。
401403404422429Get Bucket SSL Certificate
获取存储桶SSL证书
Returns the stored certificate detail of a bucket, if applicable.
GET /storage/buckets/{bucketName}/ssl_certificateruby
ssl_certificate = client.storage.buckets.ssl_certificate.retrieve("")
puts(ssl_certificate)Returns: (date-time), (string), (object), (object), (date-time), (date-time)
created_atidissued_byissued_tovalid_fromvalid_to返回存储桶的已存储证书详情(如适用)。
GET /storage/buckets/{bucketName}/ssl_certificateruby
ssl_certificate = client.storage.buckets.ssl_certificate.retrieve("")
puts(ssl_certificate)返回参数:(日期时间)、(字符串)、(对象)、(对象)、(生效时间)、(失效时间)
created_atidissued_byissued_tovalid_fromvalid_toAdd SSL Certificate
添加SSL证书
Uploads an SSL certificate and its matching secret so that you can use Telnyx's storage as your CDN.
PUT /storage/buckets/{bucketName}/ssl_certificateruby
ssl_certificate = client.storage.buckets.ssl_certificate.create("")
puts(ssl_certificate)Returns: (date-time), (string), (object), (object), (date-time), (date-time)
created_atidissued_byissued_tovalid_fromvalid_to上传SSL证书及其对应的密钥,以便你可以将Telnyx存储用作CDN。
PUT /storage/buckets/{bucketName}/ssl_certificateruby
ssl_certificate = client.storage.buckets.ssl_certificate.create("")
puts(ssl_certificate)返回参数:(日期时间)、(字符串)、(对象)、(对象)、(生效时间)、(失效时间)
created_atidissued_byissued_tovalid_fromvalid_toRemove SSL Certificate
移除SSL证书
Deletes an SSL certificate and its matching secret.
DELETE /storage/buckets/{bucketName}/ssl_certificateruby
ssl_certificate = client.storage.buckets.ssl_certificate.delete("")
puts(ssl_certificate)Returns: (date-time), (string), (object), (object), (date-time), (date-time)
created_atidissued_byissued_tovalid_fromvalid_to删除SSL证书及其对应的密钥。
DELETE /storage/buckets/{bucketName}/ssl_certificateruby
ssl_certificate = client.storage.buckets.ssl_certificate.delete("")
puts(ssl_certificate)返回参数:(日期时间)、(字符串)、(对象)、(对象)、(生效时间)、(失效时间)
created_atidissued_byissued_tovalid_fromvalid_toGet API Usage
获取API使用情况
Returns the detail on API usage on a bucket of a particular time period, group by method category.
GET /storage/buckets/{bucketName}/usage/apiruby
response = client.storage.buckets.usage.get_api_usage(
"",
filter: {end_time: "2019-12-27T18:11:19.117Z", start_time: "2019-12-27T18:11:19.117Z"}
)
puts(response)Returns: (array[object]), (date-time), (object)
categoriestimestamptotal返回指定时间段内存储桶的API使用详情,按方法类别分组。
GET /storage/buckets/{bucketName}/usage/apiruby
response = client.storage.buckets.usage.get_api_usage(
"",
filter: {end_time: "2019-12-27T18:11:19.117Z", start_time: "2019-12-27T18:11:19.117Z"}
)
puts(response)返回参数:(对象数组)、(日期时间)、(对象)
categoriestimestamptotalGet Bucket Usage
获取存储桶使用情况
Returns the amount of storage space and number of files a bucket takes up.
GET /storage/buckets/{bucketName}/usage/storageruby
response = client.storage.buckets.usage.get_bucket_usage("")
puts(response)Returns: (integer), (integer), (integer), (date-time)
num_objectssizesize_kbtimestamp返回存储桶占用的存储空间大小以及文件数量。
GET /storage/buckets/{bucketName}/usage/storageruby
response = client.storage.buckets.usage.get_bucket_usage("")
puts(response)返回参数:(整数)、(整数)、(整数)、(日期时间)
num_objectssizesize_kbtimestampCreate Presigned Object URL
生成对象预签名URL
Returns a timed and authenticated URL to download (GET) or upload (PUT) an object. This is the equivalent to AWS S3’s “presigned” URL. Please note that Telnyx performs authentication differently from AWS S3 and you MUST NOT use the presign method of AWS s3api CLI or SDK to generate the presigned URL.
POST /storage/buckets/{bucketName}/{objectName}/presigned_urlOptional: (integer)
ttlruby
response = client.storage.buckets.create_presigned_url("", bucket_name: "")
puts(response)Returns: (object)
content返回带时效的身份认证URL,可用于下载(GET)或上传(PUT)对象,功能等同于AWS S3的“预签名”URL。请注意Telnyx的身份认证逻辑与AWS S3不同,绝对不要使用AWS s3api CLI或SDK的presign方法生成预签名URL。
POST /storage/buckets/{bucketName}/{objectName}/presigned_url可选参数:(整数)
ttlruby
response = client.storage.buckets.create_presigned_url("", bucket_name: "")
puts(response)返回参数:(对象)
content