Class: Telnyx::Resources::Documents

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/documents.rb

Overview

Documents

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Documents

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Documents.

Parameters:



197
198
199
# File 'lib/telnyx/resources/documents.rb', line 197

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(id, request_options: {}) ⇒ Telnyx::Models::DocumentDeleteResponse

Delete a document.<br /><br />A document can only be deleted if it’s not linked to a service. If it is linked to a service, it must be unlinked prior to deleting.

Parameters:

  • id (String)

    Identifies the resource.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



99
100
101
102
103
104
105
106
# File 'lib/telnyx/resources/documents.rb', line 99

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["documents/%1$s", id],
    model: Telnyx::Models::DocumentDeleteResponse,
    options: params[:request_options]
  )
end

#download(id, request_options: {}) ⇒ StringIO

Download a document.

Parameters:

  • id (String)

    Identifies the resource.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (StringIO)

See Also:



119
120
121
122
123
124
125
126
127
# File 'lib/telnyx/resources/documents.rb', line 119

def download(id, params = {})
  @client.request(
    method: :get,
    path: ["documents/%1$s/download", id],
    headers: {"accept" => "application/octet-stream"},
    model: StringIO,
    options: params[:request_options]
  )
end

Generates a temporary pre-signed URL that can be used to download the document directly from the storage backend without authentication.

Parameters:

  • id (String)

    Uniquely identifies the document

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



141
142
143
144
145
146
147
148
# File 'lib/telnyx/resources/documents.rb', line 141

def generate_download_link(id, params = {})
  @client.request(
    method: :get,
    path: ["documents/%1$s/download_link", id],
    model: Telnyx::Models::DocumentGenerateDownloadLinkResponse,
    options: params[:request_options]
  )
end

#list(filter: nil, page_number: nil, page_size: nil, sort: nil, request_options: {}) ⇒ Telnyx::Internal::DefaultFlatPagination<Telnyx::Models::DocServiceDocument>

Some parameter documentations has been truncated, see Models::DocumentListParams for more details.

List all documents ordered by created_at descending.

Parameters:

Returns:

See Also:



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/telnyx/resources/documents.rb', line 73

def list(params = {})
  parsed, options = Telnyx::DocumentListParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "documents",
    query: query.transform_keys(page_number: "page[number]", page_size: "page[size]"),
    page: Telnyx::Internal::DefaultFlatPagination,
    model: Telnyx::DocServiceDocument,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ Telnyx::Models::DocumentRetrieveResponse

Retrieve a document.

Parameters:

  • id (String)

    Identifies the resource.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



18
19
20
21
22
23
24
25
# File 'lib/telnyx/resources/documents.rb', line 18

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["documents/%1$s", id],
    model: Telnyx::Models::DocumentRetrieveResponse,
    options: params[:request_options]
  )
end

#update(document_id, customer_reference: nil, filename: nil, request_options: {}) ⇒ Telnyx::Models::DocumentUpdateResponse

Update a document.

Parameters:

  • document_id (String)

    Identifies the resource.

  • customer_reference (String)

    Optional reference string for customer tracking.

  • filename (String)

    The filename of the document.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



42
43
44
45
46
47
48
49
50
51
# File 'lib/telnyx/resources/documents.rb', line 42

def update(document_id, params = {})
  parsed, options = Telnyx::DocumentUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["documents/%1$s", document_id],
    body: parsed,
    model: Telnyx::Models::DocumentUpdateResponse,
    options: options
  )
end

#upload(document:, request_options: {}) ⇒ Telnyx::Models::DocumentUploadResponse

Upload a document.<br /><br />Uploaded files must be linked to a service within 30 minutes or they will be automatically deleted.

Parameters:

Returns:

See Also:



161
162
163
164
165
166
167
168
169
170
# File 'lib/telnyx/resources/documents.rb', line 161

def upload(params)
  parsed, options = Telnyx::DocumentUploadParams.dump_request(params)
  @client.request(
    method: :post,
    path: "documents?content-type=multipart",
    body: parsed[:document],
    model: Telnyx::Models::DocumentUploadResponse,
    options: options
  )
end

#upload_json(document:, request_options: {}) ⇒ Telnyx::Models::DocumentUploadJsonResponse

Upload a document.<br /><br />Uploaded files must be linked to a service within 30 minutes or they will be automatically deleted.



183
184
185
186
187
188
189
190
191
192
# File 'lib/telnyx/resources/documents.rb', line 183

def upload_json(params)
  parsed, options = Telnyx::DocumentUploadJsonParams.dump_request(params)
  @client.request(
    method: :post,
    path: "documents",
    body: parsed[:document],
    model: Telnyx::Models::DocumentUploadJsonResponse,
    options: options
  )
end