Class: Inttegro::Resources::FileLinks

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

Overview

Client for revocable public capability URLs that deliver Inttegro files.

Access this resource through Client#file_links.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ FileLinks

Returns a new instance of FileLinks.

Parameters:



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

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

Instance Method Details

#create(payload, idempotency_key: nil) ⇒ Inttegro::FileLink::Creation

Create a public file link.

Parameters:

  • payload (Hash, Inttegro::FileLink::CreateRequest) —

    file, delivery, and expiry fields

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

    explicit key for safely retrying this logical write

Returns:



20
21
22
23
24
25
26
27
# File 'lib/inttegro/resources/file_links.rb', line 20

def create(payload, idempotency_key: nil)
  @http.post_model(
    "/file_links/create",
    Inttegro::FileLink::Creation,
    payload,
    headers: headers(idempotency_key)
  )
end

#lookup(id:) ⇒ Inttegro::FileLink

Retrieve a file link without exposing its token material.

Parameters:

  • id (String) —

    unique file-link identifier

Returns:



33
34
35
# File 'lib/inttegro/resources/file_links.rb', line 33

def lookup(id:)
  @http.post_resource("/file_links/lookup", Inttegro::FileLink, :file_link, { id: id })
end

#open(url, save_to: nil) ⇒ Inttegro::FileDownload

Download the bytes exposed by a public file-link URL.

This public capability request does not use the client's API key. When save_to is supplied, the response is also written to that path before being returned.

Parameters:

  • url (String) —

    complete public file-link capability URL

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

    optional local path for the downloaded bytes

Returns:



65
66
67
68
69
# File 'lib/inttegro/resources/file_links.rb', line 65

def open(url, save_to: nil)
  download = @http.get_binary_public(url)
  download.save_to(save_to) if save_to
  download
end

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

Retrieve a filtered page of file links.

Parameters:

Returns:



41
42
43
# File 'lib/inttegro/resources/file_links.rb', line 41

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

#revoke(payload, idempotency_key: nil) ⇒ Inttegro::FileLink

Revoke a file link so its capability URL can no longer serve the file.

Parameters:

  • payload (Hash, Inttegro::FileLink::RevokeRequest) —

    file-link identifier and request metadata

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

    explicit key for safely retrying this logical write

Returns:



50
51
52
53
54
55
# File 'lib/inttegro/resources/file_links.rb', line 50

def revoke(payload, idempotency_key: nil)
  @http.post_resource("/file_links/revoke", Inttegro::FileLink, :file_link,
    payload,
    headers: headers(idempotency_key)
  )
end