Skip to content
Merged
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": "7ded7de29f4cc0dc9da18042fca6afd5c9557bfc",
"originGitCommit": "07aa3f26c82243b36a5ec94f7072130c7298d977",
"originGitCommitIsDirty": false,
"invokedBy": "ci",
"requestedVersion": "3.0.0.alpha.16",
"requestedVersion": "3.0.0.alpha.17",
"ciProvider": "github"
}
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.16",
"sdkVersion": "3.0.0.alpha.16",
"canonicalVersion": "3.0.0-next.17",
"sdkVersion": "3.0.0.alpha.17",
"source": {
"repository": "embedpdf/embed-pdf-viewer",
"openapi": "cloudpdf/contract/openapi.json",
"openapiSha256": "06543c26918bd79d426bf242c5a3091cdb7d298d3ac3296addabee2be80edb15",
"gitCommit": "7ded7de29f4cc0dc9da18042fca6afd5c9557bfc",
"openapiSha256": "8fa53cef2776eb0de9ec50c263aa547b309a04d1a2ecb6ee54b6338d6698dc00",
"gitCommit": "07aa3f26c82243b36a5ec94f7072130c7298d977",
"gitCommitIsDirty": false
},
"fern": {
Expand Down
55 changes: 55 additions & 0 deletions lib/CloudPDF/doc/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,61 @@ def download(request_options: {}, **params)
raise error_class.new(response.body, code: code)
end

# The link opens the layer as it is when created: once the layer changes, it answers 404, so create it right
# before handing it over. It downloads that one file and nothing else, and a password-protected document is
# checked when the link is created. Deployments that verify tokens with their own keys (JWKS) mint links on their
# backend: a doc token with `layer_name`, a `download: { docVersion, mode: "incremental" }` claim and a short
# `exp`, passed as `link` on the versioned download URL.
#
# @param request_options [Hash]
# @param params [CloudPDF::Doc::Types::DocDownloadLinkRequest]
# @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] :doc_id
# @option params [String] :layer_name
# @option params [String, nil] :document_password
#
# @example
# client.doc.download_link(
# doc_id: "docId",
# layer_name: "layerName"
# )
#
# @return [CloudPDF::Types::DocDownloadLink200Response]
def download_link(request_options: {}, **params)
params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
request_data = CloudPDF::Doc::Types::DocDownloadLinkRequest.new(params).to_h
non_body_param_names = %w[docId layerName X-Document-Password]
body = request_data.except(*non_body_param_names)

headers = {}
headers["X-Document-Password"] = params[:document_password] if params[:document_password]

request = CloudPDF::Internal::JSON::Request.new(
base_url: request_options[:base_url],
method: "POST",
path: "v1/docs/#{URI.encode_uri_component(params[:doc_id].to_s)}/layers/#{URI.encode_uri_component(params[:layer_name].to_s)}/download-link",
headers: headers,
body: body,
request_options: request_options
)
begin
response = @client.send(request)
rescue Net::HTTPRequestTimeout
raise CloudPDF::Errors::TimeoutError
end
code = response.code.to_i
if code.between?(200, 299)
(response.body.to_s.empty? ? nil : CloudPDF::Types::DocDownloadLink200Response.load(response.body))
else
error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
raise error_class.new(response.body, code: code)
end
end

# @param request_options [Hash]
# @param params [Hash]
# @option request_options [String] :base_url
Expand Down
17 changes: 17 additions & 0 deletions lib/CloudPDF/doc/types/doc_download_link_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module CloudPDF
module Doc
module Types
class DocDownloadLinkRequest < Internal::Types::Model
field :doc_id, -> { String }, optional: false, nullable: false, api_name: "docId"

field :layer_name, -> { String }, optional: false, nullable: false, api_name: "layerName"

field :document_password, -> { String }, optional: true, nullable: false, api_name: "X-Document-Password"

field :expires_in, -> { Integer }, optional: true, nullable: false, api_name: "expiresIn"
end
end
end
end
5 changes: 5 additions & 0 deletions lib/CloudPDF/documents/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def init(request_options: {}, **params)
raise error_class.new(response.body, code: code)
end
end

# @return [CloudPDF::Layers::Client]
def layers
@layers ||= CloudPDF::Documents::Layers::Client.new(client: @client)
end
end
end
end
103 changes: 103 additions & 0 deletions lib/CloudPDF/documents/layers/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# frozen_string_literal: true

module CloudPDF
module Documents
module Layers
class Client
# @param client [CloudPDF::Internal::Http::RawClient]
#
# @return [void]
def initialize(client:)
@client = client
end

# @param request_options [Hash]
# @param params [Hash]
# @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 [Integer, nil] :limit
# @option params [String, nil] :cursor
# @option params [String, nil] :share_id
#
# @example
# client.documents.layers.list(
# tenant_id: "tenantId",
# id: "id"
# )
#
# @return [CloudPDF::Types::DocumentsLayersList200Response]
def list(request_options: {}, **params)
params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
query_params = {}
query_params["limit"] = params[:limit] if params.key?(:limit)
query_params["cursor"] = params[:cursor] if params.key?(:cursor)
query_params["shareId"] = params[:share_id] if params.key?(:share_id)

request = CloudPDF::Internal::JSON::Request.new(
base_url: request_options[:base_url],
method: "GET",
path: "v1/tenants/#{URI.encode_uri_component(params[:tenant_id].to_s)}/documents/#{URI.encode_uri_component(params[:id].to_s)}/layers",
query: query_params,
request_options: request_options
)
begin
response = @client.send(request)
rescue Net::HTTPRequestTimeout
raise CloudPDF::Errors::TimeoutError
end
code = response.code.to_i
if code.between?(200, 299)
(response.body.to_s.empty? ? nil : CloudPDF::Types::DocumentsLayersList200Response.load(response.body))
else
error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
raise error_class.new(response.body, code: code)
end
end

# @param request_options [Hash]
# @param params [Hash]
# @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 [String] :layer_name
#
# @example
# client.documents.layers.delete(
# tenant_id: "tenantId",
# id: "id",
# layer_name: "layerName"
# )
#
# @return [untyped]
def delete(request_options: {}, **params)
params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
request = CloudPDF::Internal::JSON::Request.new(
base_url: request_options[:base_url],
method: "DELETE",
path: "v1/tenants/#{URI.encode_uri_component(params[:tenant_id].to_s)}/documents/#{URI.encode_uri_component(params[:id].to_s)}/layers/#{URI.encode_uri_component(params[:layer_name].to_s)}",
request_options: request_options
)
begin
response = @client.send(request)
rescue Net::HTTPRequestTimeout
raise CloudPDF::Errors::TimeoutError
end
code = response.code.to_i
return if code.between?(200, 299)

error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
raise error_class.new(response.body, code: code)
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/CloudPDF/documents/layers/types/delete_layers_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

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

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

field :layer_name, -> { String }, optional: false, nullable: false, api_name: "layerName"
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/CloudPDF/documents/layers/types/list_layers_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

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

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

field :limit, -> { Integer }, optional: true, nullable: false

field :cursor, -> { String }, optional: true, nullable: false

field :share_id, -> { String }, optional: true, nullable: false, api_name: "shareId"
end
end
end
end
end
57 changes: 56 additions & 1 deletion lib/CloudPDF/shares/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def initialize(client:)

# Unauthenticated, but requires a browser Origin header, checked against the grant allowlist. Unknown, revoked,
# and disabled tokens are indistinguishable (404). Passphrase-protected grants return 422 SharePasswordRequired
# until `password` is supplied. Mounted only when the deployment can sign (HS256 mode).
# until `password` is supplied. A link that asks its visitors who they are on open returns 422
# VisitorIdentityRequired until the required answers are given; `error.details` carries `fields` (what the link
# asks), `missing`, `invalid`, `purpose` and `privacyUrl`. A link that asks before the first change issues the
# session at once with `visitor.identityRequest`, and writes answer 403 VisitorIdentityRequired with the same
# details until the visitor exchanges again with their answers. Answers that can not be taken answer 422 on any
# link. Mounted only when the deployment can sign (HS256 mode).
#
# @param request_options [Hash]
# @param params [CloudPDF::Shares::Types::SharesExchangeRequest]
Expand Down Expand Up @@ -60,6 +65,7 @@ def exchange(request_options: {}, **params)
# @option params [Integer, nil] :limit
# @option params [String, nil] :cursor
# @option params [String, nil] :doc_id
# @option params [Boolean, nil] :archived
#
# @example
# client.shares.list(tenant_id: "tenantId")
Expand All @@ -71,6 +77,7 @@ def list(request_options: {}, **params)
query_params["limit"] = params[:limit] if params.key?(:limit)
query_params["cursor"] = params[:cursor] if params.key?(:cursor)
query_params["docId"] = params[:doc_id] if params.key?(:doc_id)
query_params["archived"] = params[:archived] if params.key?(:archived)

request = CloudPDF::Internal::JSON::Request.new(
base_url: request_options[:base_url],
Expand Down Expand Up @@ -259,6 +266,54 @@ def update(request_options: {}, **params)
raise error_class.new(response.body, code: code)
end
end

# Archiving is final: an archived link never exchanges again, and to share again you create a new link. Pausing
# (`disabled`) is the reversible stop. An archived link no longer counts as using its shared layer, so that layer
# can be deleted.
#
# @param request_options [Hash]
# @param params [Hash]
# @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] :share_id
#
# @example
# client.shares.archive(
# tenant_id: "tenantId",
# share_id: "shareId"
# )
#
# @return [CloudPDF::Types::SharesArchive200Response]
def archive(request_options: {}, **params)
params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
request = CloudPDF::Internal::JSON::Request.new(
base_url: request_options[:base_url],
method: "POST",
path: "v1/tenants/#{URI.encode_uri_component(params[:tenant_id].to_s)}/shares/#{URI.encode_uri_component(params[:share_id].to_s)}/archive",
request_options: request_options
)
begin
response = @client.send(request)
rescue Net::HTTPRequestTimeout
raise CloudPDF::Errors::TimeoutError
end
code = response.code.to_i
if code.between?(200, 299)
(response.body.to_s.empty? ? nil : CloudPDF::Types::SharesArchive200Response.load(response.body))
else
error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
raise error_class.new(response.body, code: code)
end
end

# @return [CloudPDF::Visitors::Client]
def visitors
@visitors ||= CloudPDF::Shares::Visitors::Client.new(client: @client)
end
end
end
end
13 changes: 13 additions & 0 deletions lib/CloudPDF/shares/types/archive_shares_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

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

field :share_id, -> { String }, optional: false, nullable: false, api_name: "shareId"
end
end
end
end
2 changes: 2 additions & 0 deletions lib/CloudPDF/shares/types/list_shares_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ListSharesRequest < Internal::Types::Model
field :cursor, -> { String }, optional: true, nullable: false

field :doc_id, -> { String }, optional: true, nullable: false, api_name: "docId"

field :archived, -> { Internal::Types::Boolean }, optional: true, nullable: false
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/CloudPDF/shares/types/shares_create_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ class SharesCreateRequest < Internal::Types::Model

field :doc_id, -> { String }, optional: false, nullable: false, api_name: "docId"

field :layer_mode, -> { CloudPDF::Shares::Types::SharesCreateRequestLayerMode }, optional: true, nullable: false, api_name: "layerMode"

field :layer_name, -> { String }, optional: true, nullable: false, api_name: "layerName"

field :keep_visitor_layers, -> { Internal::Types::Boolean }, optional: true, nullable: false, api_name: "keepVisitorLayers"

field :visitor_idle_seconds, -> { Integer }, optional: true, nullable: false, api_name: "visitorIdleSeconds"

field :visitor_identity, -> { CloudPDF::Shares::Types::SharesCreateRequestVisitorIdentity }, optional: true, nullable: false, api_name: "visitorIdentity"

field :scope, -> { Internal::Types::Array[String] }, optional: false, nullable: false

field :origins, -> { Internal::Types::Array[String] }, optional: true, nullable: false
Expand Down
Loading
Loading