Class: Inttegro::Resources::Files

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

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Files

Returns a new instance of Files.



7
8
9
# File 'lib/inttegro/resources/files.rb', line 7

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

Instance Method Details

#contents(file_id:, disposition: "attachment") ⇒ Object



28
29
30
# File 'lib/inttegro/resources/files.rb', line 28

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) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/inttegro/resources/files.rb', line 11

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



32
33
34
# File 'lib/inttegro/resources/files.rb', line 32

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

#lookup(file_id:) ⇒ Object



20
21
22
# File 'lib/inttegro/resources/files.rb', line 20

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

#page(payload = {}) ⇒ Object



24
25
26
# File 'lib/inttegro/resources/files.rb', line 24

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