Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"generatorConfig": {
"moduleName": "CloudPDF"
},
"originGitCommit": "a0adb9e77ef16feaef2358d71b247b4f5a98fd23",
"originGitCommit": "33003769980b6b0155f602109c8e34cc0a2b432d",
"originGitCommitIsDirty": false,
"invokedBy": "ci",
"requestedVersion": "3.0.0.alpha.1",
"requestedVersion": "3.0.0.alpha.4",
"ciProvider": "github"
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require "cloudpdf"

client = CloudPDF::Client.new(token: "<token>")

client.tenants.create(id: "id")
client.shares.exchange(share_token: "shareToken")
```

## Environments
Expand Down Expand Up @@ -58,7 +58,7 @@ client = CloudPDF::Client.new(
)

begin
result = client.tenants.create
result = client.shares.exchange
rescue CloudPDF::Errors::TimeoutError
puts "API didn't respond before our timeout elapsed"
rescue CloudPDF::Errors::ServiceUnavailableError
Expand Down Expand Up @@ -108,7 +108,7 @@ The SDK defaults to a 60 second timeout. Use the `timeout` option to configure t
```ruby
require "cloudpdf"

response = client.tenants.create(
response = client.shares.exchange(
...,
timeout: 30 # 30 second timeout
)
Expand All @@ -121,7 +121,7 @@ If you would like to send additional headers as part of the request, use the `ad
```ruby
require "cloudpdf"

response = client.tenants.create(
response = client.shares.exchange(
...,
request_options: {
additional_headers: {
Expand All @@ -138,7 +138,7 @@ If you would like to send additional query parameters as part of the request, us
```ruby
require "cloudpdf"

response = client.tenants.create(
response = client.shares.exchange(
...,
request_options: {
additional_query_parameters: {
Expand Down
8 changes: 4 additions & 4 deletions cloudpdf-generation.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"language": "ruby",
"canonicalVersion": "3.0.0-next.1",
"sdkVersion": "3.0.0.alpha.1",
"canonicalVersion": "3.0.0-next.4",
"sdkVersion": "3.0.0.alpha.4",
"source": {
"repository": "embedpdf/embed-pdf-viewer",
"openapi": "cloudpdf/contract/openapi.json",
"openapiSha256": "6858ce7912e9063d8fb171ade95fc473db01c5971a3af241a612dda79cc05100",
"gitCommit": "a0adb9e77ef16feaef2358d71b247b4f5a98fd23",
"openapiSha256": "901c23684e7c9e33b5248942779b13537764a1d9065db815dd8aedb592c5ec59",
"gitCommit": "33003769980b6b0155f602109c8e34cc0a2b432d",
"gitCommitIsDirty": false
},
"fern": {
Expand Down
5 changes: 5 additions & 0 deletions lib/CloudPDF/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def doc
@doc ||= CloudPDF::Doc::Client.new(client: @raw_client)
end

# @return [CloudPDF::Shares::Client]
def shares
@shares ||= CloudPDF::Shares::Client.new(client: @raw_client)
end

# @return [CloudPDF::Tenants::Client]
def tenants
@tenants ||= CloudPDF::Tenants::Client.new(client: @raw_client)
Expand Down
29 changes: 23 additions & 6 deletions lib/CloudPDF/documents/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,40 @@ def thumbnail(request_options: {}, **params)
raise error_class.new(response.body, code: code)
end

# This bounded origin-mediated fallback must only be used after documents.init returns upload.kind=proxy. Auto
# mode prefers a presigned object-store PUT whenever available.
#
# @param request_options [Hash]
# @param params [Hash]
# @param params [void]
# @option request_options [String] :base_url
# @option request_options [Hash{String => Object}] :additional_headers
# @option request_options [Hash{String => Object}] :additional_query_parameters
# @option request_options [Hash{String => Object}] :additional_body_parameters
# @option request_options [Integer] :timeout_in_seconds
# @option params [String] :tenant_id
# @option params [String] :id
# @option params [#read] :file
#
# @return [CloudPDF::Types::DocumentsUploadDirect200Response]
def upload_direct(request_options: {}, **params)
# @example
# client.documents.upload_proxy(
# tenant_id: "tenantId",
# id: "id",
# file: File.open("document.pdf", "rb")
# )
#
# @return [CloudPDF::Types::DocumentsUploadProxy200Response]
def upload_proxy(request_options: {}, **params)
params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
request = CloudPDF::Internal::JSON::Request.new(
body = Internal::Multipart::FormData.new

raise ArgumentError, "file is required" unless params[:file]
body.add_file(name: "file", file: params[:file], content_type: "application/pdf")

request = CloudPDF::Internal::Multipart::Request.new(
base_url: request_options[:base_url],
method: "POST",
path: "v1/tenants/#{URI.encode_uri_component(params[:tenant_id].to_s)}/documents/#{URI.encode_uri_component(params[:id].to_s)}/upload-direct",
path: "v1/tenants/#{URI.encode_uri_component(params[:tenant_id].to_s)}/documents/#{URI.encode_uri_component(params[:id].to_s)}/upload-proxy",
body: body,
request_options: request_options
)
begin
Expand All @@ -275,7 +292,7 @@ def upload_direct(request_options: {}, **params)
end
code = response.code.to_i
if code.between?(200, 299)
CloudPDF::Types::DocumentsUploadDirect200Response.load(response.body)
CloudPDF::Types::DocumentsUploadProxy200Response.load(response.body)
else
error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
raise error_class.new(response.body, code: code)
Expand Down
2 changes: 2 additions & 0 deletions lib/CloudPDF/documents/types/documents_init_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class DocumentsInitRequest < Internal::Types::Model
field :doc_id, -> { String }, optional: true, nullable: false, api_name: "docId"

field :upload_ttl_sec, -> { Integer }, optional: true, nullable: false, api_name: "uploadTtlSec"

field :upload_preference, -> { CloudPDF::Documents::Types::DocumentsInitRequestUploadPreference }, optional: true, nullable: false, api_name: "uploadPreference"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module CloudPDF
module Documents
module Types
module DocumentsInitRequestUploadPreference
extend CloudPDF::Internal::Types::Enum

AUTO = "auto"
PRESIGNED = "presigned"
PROXY = "proxy"
end
end
end
end
15 changes: 15 additions & 0 deletions lib/CloudPDF/documents/types/upload_proxy_documents_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module CloudPDF
module Documents
module Types
class UploadProxyDocumentsRequest < Internal::Types::Model
field :tenant_id, -> { String }, optional: false, nullable: false, api_name: "tenantId"

field :id, -> { String }, optional: false, nullable: false

field :file, -> { Object }, optional: false, nullable: false
end
end
end
end
Loading
Loading