Class: CloudPDF::Doc::Annotations::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



10
11
12
# File 'lib/CloudPDF/doc/annotations/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

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

Doc JWTs may instead carry collab scopes (annotations:create:self, …) that refine per-annotation authorship rules; the API token is exempt from both.

Examples:

client.doc.annotations.create(
  doc_id: "docId",
  layer_name: "layerName",
  pon: 1,
  request: {
    key: "value"
  }
)

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

  • :doc_id (String)
  • :layer_name (String)
  • :pon (Integer)
  • :document_password (String, nil)

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/CloudPDF/doc/annotations/client.rb', line 86

def create(request_options: {}, **params)
  params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[doc_id layer_name pon]
  body_params = params.except(*path_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)}/annotations/pages/#{URI.encode_uri_component(params[:pon].to_s)}/items",
    headers: headers,
    body: body_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::DocAnnotationsCreate200Response.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) ⇒ CloudPDF::Types::DocAnnotationsDelete200Response

Examples:

client.doc.annotations.delete(
  doc_id: "docId",
  layer_name: "layerName",
  pon: 1,
  annot_key: "annotKey"
)

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

  • :doc_id (String)
  • :layer_name (String)
  • :pon (Integer)
  • :annot_key (String)
  • :document_password (String, nil)

Returns:



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/CloudPDF/doc/annotations/client.rb', line 138

def delete(request_options: {}, **params)
  params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
  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: "DELETE",
    path: "v1/docs/#{URI.encode_uri_component(params[:doc_id].to_s)}/layers/#{URI.encode_uri_component(params[:layer_name].to_s)}/annotations/pages/#{URI.encode_uri_component(params[:pon].to_s)}/items/#{URI.encode_uri_component(params[:annot_key].to_s)}",
    headers: headers,
    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::DocAnnotationsDelete200Response.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::DocAnnotationsList200Response

Examples:

client.doc.annotations.list(
  doc_id: "docId",
  layer_name: "layerName",
  pon: 1
)

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

  • :doc_id (String)
  • :layer_name (String)
  • :pon (Integer)
  • :document_password (String, nil)

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/CloudPDF/doc/annotations/client.rb', line 34

def list(request_options: {}, **params)
  params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
  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: "GET",
    path: "v1/docs/#{URI.encode_uri_component(params[:doc_id].to_s)}/layers/#{URI.encode_uri_component(params[:layer_name].to_s)}/annotations/pages/#{URI.encode_uri_component(params[:pon].to_s)}/items",
    headers: headers,
    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::DocAnnotationsList200Response.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::DocAnnotationsUpdate200Response

Examples:

client.doc.annotations.update(
  doc_id: "docId",
  layer_name: "layerName",
  pon: 1,
  annot_key: "annotKey",
  request: {
    key: "value"
  }
)

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

  • :doc_id (String)
  • :layer_name (String)
  • :pon (Integer)
  • :annot_key (String)
  • :document_password (String, nil)

Returns:



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/CloudPDF/doc/annotations/client.rb', line 189

def update(request_options: {}, **params)
  params = CloudPDF::Internal::Types::Utils.normalize_keys(params)
  path_param_names = %i[doc_id layer_name pon annot_key]
  body_params = params.except(*path_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: "PATCH",
    path: "v1/docs/#{URI.encode_uri_component(params[:doc_id].to_s)}/layers/#{URI.encode_uri_component(params[:layer_name].to_s)}/annotations/pages/#{URI.encode_uri_component(params[:pon].to_s)}/items/#{URI.encode_uri_component(params[:annot_key].to_s)}",
    headers: headers,
    body: body_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::DocAnnotationsUpdate200Response.load(response.body)
  else
    error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end