Class: CloudPDF::Shares::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/CloudPDF/shares/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/CloudPDF/shares/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ CloudPDF::Types::SharesCreate200Response

The returned share id IS the public share token. Mounted only when the deployment can sign (HS256 mode) — exchange mints session JWTs, so grants exist only where minting does.

Examples:

client.shares.create(
  tenant_id: "tenantId",
  doc_id: "docId",
  scope: ["scope"]
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :tenant_id (String)

Returns:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/CloudPDF/shares/client.rb', line 116

def create(request_options: {}, **params)
  params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
  request_data = CloudPDF::Shares::Types::SharesCreateRequest.new(params).to_h
  non_body_param_names = %w[tenantId]
  body = request_data.except(*non_body_param_names)

  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",
    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)
    CloudPDF::Types::SharesCreate200Response.load(response.body)
  else
    error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete(request_options: {}, **params) ⇒ untyped

Examples:

client.shares.delete(
  tenant_id: "tenantId",
  share_id: "shareId"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :tenant_id (String)
  • :share_id (String)

Returns:

  • (untyped)

Raises:

  • (error_class)


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/CloudPDF/shares/client.rb', line 199

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)}/shares/#{URI.encode_uri_component(params[:share_id].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

#exchange(request_options: {}, **params) ⇒ CloudPDF::Types::SharesExchange200Response

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).

Examples:

client.shares.exchange(share_token: "shareToken")

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/CloudPDF/shares/client.rb', line 29

def exchange(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/share-sessions",
    body: CloudPDF::Shares::Types::SharesExchangeRequest.new(params).to_h,
    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)
    CloudPDF::Types::SharesExchange200Response.load(response.body)
  else
    error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get(request_options: {}, **params) ⇒ CloudPDF::Types::SharesGet200Response

Examples:

client.shares.get(
  tenant_id: "tenantId",
  share_id: "shareId"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :tenant_id (String)
  • :share_id (String)

Returns:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/CloudPDF/shares/client.rb', line 160

def get(request_options: {}, **params)
  params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
  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)}/shares/#{URI.encode_uri_component(params[:share_id].to_s)}",
    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)
    CloudPDF::Types::SharesGet200Response.load(response.body)
  else
    error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ CloudPDF::Types::SharesList200Response

Examples:

client.shares.list(tenant_id: "tenantId")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :tenant_id (String)
  • :limit (Integer, nil)
  • :cursor (String, nil)
  • :doc_id (String, nil)

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/CloudPDF/shares/client.rb', line 68

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["docId"] = params[:doc_id] if params.key?(:doc_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)}/shares",
    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)
    CloudPDF::Types::SharesList200Response.load(response.body)
  else
    error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update(request_options: {}, **params) ⇒ CloudPDF::Types::SharesUpdate200Response

Examples:

client.shares.update(
  tenant_id: "tenantId",
  share_id: "shareId"
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :tenant_id (String)
  • :share_id (String)

Returns:



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/CloudPDF/shares/client.rb', line 236

def update(request_options: {}, **params)
  params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
  request_data = CloudPDF::Shares::Types::SharesUpdateRequest.new(params).to_h
  non_body_param_names = %w[tenantId shareId]
  body = request_data.except(*non_body_param_names)

  request = CloudPDF::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "v1/tenants/#{URI.encode_uri_component(params[:tenant_id].to_s)}/shares/#{URI.encode_uri_component(params[:share_id].to_s)}",
    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)
    CloudPDF::Types::SharesUpdate200Response.load(response.body)
  else
    error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end