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 telnyx
bash
gem install telnyx

Setup

配置

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
client
is already initialized as shown above.
ruby
require "telnyx"

client = Telnyx::Client.new(
  api_key: ENV["TELNYX_API_KEY"], # 这是默认配置,可以省略
)
以下所有示例均默认
client
已按照上述方式完成初始化。

Error 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
end
Common error codes:
401
invalid API key,
403
insufficient permissions,
404
resource not found,
422
validation error (check field formats),
429
rate limited (retry with exponential backoff).
所有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
常见错误码:
401
无效的API密钥,
403
权限不足,
404
资源未找到,
422
校验错误(请检查字段格式),
429
触发速率限制(请使用指数退避策略重试)。

Get Bucket SSL Certificate

获取存储桶SSL证书

Returns the stored certificate detail of a bucket, if applicable.
GET /storage/buckets/{bucketName}/ssl_certificate
ruby
ssl_certificate = client.storage.buckets.ssl_certificate.retrieve("")

puts(ssl_certificate)
Returns:
created_at
(date-time),
id
(string),
issued_by
(object),
issued_to
(object),
valid_from
(date-time),
valid_to
(date-time)
返回存储桶的已存储证书详情(如适用)。
GET /storage/buckets/{bucketName}/ssl_certificate
ruby
ssl_certificate = client.storage.buckets.ssl_certificate.retrieve("")

puts(ssl_certificate)
返回参数:
created_at
(日期时间)、
id
(字符串)、
issued_by
(对象)、
issued_to
(对象)、
valid_from
(生效时间)、
valid_to
(失效时间)

Add 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_certificate
ruby
ssl_certificate = client.storage.buckets.ssl_certificate.create("")

puts(ssl_certificate)
Returns:
created_at
(date-time),
id
(string),
issued_by
(object),
issued_to
(object),
valid_from
(date-time),
valid_to
(date-time)
上传SSL证书及其对应的密钥,以便你可以将Telnyx存储用作CDN。
PUT /storage/buckets/{bucketName}/ssl_certificate
ruby
ssl_certificate = client.storage.buckets.ssl_certificate.create("")

puts(ssl_certificate)
返回参数:
created_at
(日期时间)、
id
(字符串)、
issued_by
(对象)、
issued_to
(对象)、
valid_from
(生效时间)、
valid_to
(失效时间)

Remove SSL Certificate

移除SSL证书

Deletes an SSL certificate and its matching secret.
DELETE /storage/buckets/{bucketName}/ssl_certificate
ruby
ssl_certificate = client.storage.buckets.ssl_certificate.delete("")

puts(ssl_certificate)
Returns:
created_at
(date-time),
id
(string),
issued_by
(object),
issued_to
(object),
valid_from
(date-time),
valid_to
(date-time)
删除SSL证书及其对应的密钥。
DELETE /storage/buckets/{bucketName}/ssl_certificate
ruby
ssl_certificate = client.storage.buckets.ssl_certificate.delete("")

puts(ssl_certificate)
返回参数:
created_at
(日期时间)、
id
(字符串)、
issued_by
(对象)、
issued_to
(对象)、
valid_from
(生效时间)、
valid_to
(失效时间)

Get 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/api
ruby
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:
categories
(array[object]),
timestamp
(date-time),
total
(object)
返回指定时间段内存储桶的API使用详情,按方法类别分组。
GET /storage/buckets/{bucketName}/usage/api
ruby
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)
返回参数:
categories
(对象数组)、
timestamp
(日期时间)、
total
(对象)

Get Bucket Usage

获取存储桶使用情况

Returns the amount of storage space and number of files a bucket takes up.
GET /storage/buckets/{bucketName}/usage/storage
ruby
response = client.storage.buckets.usage.get_bucket_usage("")

puts(response)
Returns:
num_objects
(integer),
size
(integer),
size_kb
(integer),
timestamp
(date-time)
返回存储桶占用的存储空间大小以及文件数量。
GET /storage/buckets/{bucketName}/usage/storage
ruby
response = client.storage.buckets.usage.get_bucket_usage("")

puts(response)
返回参数:
num_objects
(整数)、
size
(整数)、
size_kb
(整数)、
timestamp
(日期时间)

Create 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_url
Optional:
ttl
(integer)
ruby
response = client.storage.buckets.create_presigned_url("", bucket_name: "")

puts(response)
Returns:
content
(object)
返回带时效的身份认证URL,可用于下载(GET)或上传(PUT)对象,功能等同于AWS S3的“预签名”URL。请注意Telnyx的身份认证逻辑与AWS S3不同,绝对不要使用AWS s3api CLI或SDK的presign方法生成预签名URL。
POST /storage/buckets/{bucketName}/{objectName}/presigned_url
可选参数:
ttl
(整数)
ruby
response = client.storage.buckets.create_presigned_url("", bucket_name: "")

puts(response)
返回参数:
content
(对象)