Class: Inttegro::Resources::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/inttegro/resources/files.rb

Overview

Client for uploading, listing, downloading, and deleting application-owned files.

Access this resource through Client#files.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Files

Returns a new instance of Files.

Parameters:



11
12
13
# File 'lib/inttegro/resources/files.rb', line 11

def initialize(http)
  @http = T.let(http, Inttegro::HTTPClient)
end

Instance Method Details

#contents(file_id:, disposition: "attachment") ⇒ Inttegro::FileDownload

Retrieve the original bytes for a file.

Parameters:

  • file_id (String) —

    unique file identifier

  • disposition (String) (defaults to: "attachment") —

    requested delivery disposition, normally "attachment" or "inline"

Returns:



53
54
55
# File 'lib/inttegro/resources/files.rb', line 53

def contents(file_id:, disposition: "attachment")
  @http.post_binary_json("/files/contents", { file_id: file_id, disposition: disposition })
end

#create(file:, purpose:, title: nil, custom_data: nil, idempotency_key: nil) ⇒ Inttegro::File

Upload a file using multipart form data.

Parameters:

  • file (String) —

    local path of the file to upload

  • purpose (String) —

    API purpose assigned to the file

  • title (String, nil) (defaults to: nil) —

    optional display title

  • custom_data (Hash, nil) (defaults to: nil) —

    optional merchant-defined data

  • idempotency_key (String, nil) (defaults to: nil) —

    explicit key for safely retrying this logical write

Returns:



23
24
25
26
27
28
29
30
# File 'lib/inttegro/resources/files.rb', line 23

def create(file:, purpose:, title: nil, custom_data: nil, idempotency_key: nil)
  headers = idempotency_key ? { "Idempotency-Key" => idempotency_key } : {}
  @http.post_multipart_resource("/files/create", Inttegro::File, :file,
    fields: { purpose: purpose, title: title, custom_data: custom_data },
    files: { file: file },
    headers: headers
  )
end

#delete(file_id:) ⇒ Inttegro::File

Tombstone a file and request backing-object cleanup under the API's reference policy.

Parameters:

  • file_id (String) —

    unique file identifier

Returns:



61
62
63
# File 'lib/inttegro/resources/files.rb', line 61

def delete(file_id:)
  @http.post_resource("/files/delete", Inttegro::File, :file, { file_id: file_id })
end

#lookup(file_id:) ⇒ Inttegro::File

Retrieve metadata for one file.

Parameters:

  • file_id (String) —

    unique file identifier

Returns:



36
37
38
# File 'lib/inttegro/resources/files.rb', line 36

def lookup(file_id:)
  @http.post_resource("/files/lookup", Inttegro::File, :file, { file_id: file_id })
end

#page(payload = {}) ⇒ Inttegro::File::Page

Retrieve a filtered page of files.

Parameters:

Returns:



44
45
46
# File 'lib/inttegro/resources/files.rb', line 44

def page(payload = {})
  @http.post_resource("/files/page", Inttegro::File::Page, :page, payload || {})
end