Class: FilestackFilelink

Inherits:
Object
  • Object
show all
Includes:
FilestackCommon, UploadUtils
Defined in:
lib/filestack/models/filelink.rb

Overview

This class represents a file stored on your Filestack storage. Once initialized, you may perform transformations, conversions, get metadata, update, or delete it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UploadUtils

#build_store_task, #get_url, #make_call, #send_upload

Methods included from FilestackCommon

#send_delete, #send_download, #send_get_content, #send_metadata, #send_overwrite, #send_tags

Constructor Details

#initialize(handle, apikey: nil, security: nil, upload_response: nil) ⇒ FilestackFilelink

Initialize FilestackFilelink

Parameters:

  • file_handle (String)

    The FilestackFilelink handle

  • apikey (String) (defaults to: nil)

    Your Filestack API Key (optional)

  • security (FilestackSecurity) (defaults to: nil)

    Filestack security object, if security is enabled.



21
22
23
24
25
26
# File 'lib/filestack/models/filelink.rb', line 21

def initialize(handle, apikey: nil, security: nil, upload_response: nil)
  @handle = handle
  @apikey = apikey
  @security = security
  @upload_response = upload_response
end

Instance Attribute Details

#apikeyObject (readonly)

Returns the value of attribute apikey.



13
14
15
# File 'lib/filestack/models/filelink.rb', line 13

def apikey
  @apikey
end

#handleObject (readonly)

Returns the value of attribute handle.



13
14
15
# File 'lib/filestack/models/filelink.rb', line 13

def handle
  @handle
end

#securityObject (readonly)

Returns the value of attribute security.



13
14
15
# File 'lib/filestack/models/filelink.rb', line 13

def security
  @security
end

#upload_responseObject (readonly)

Returns the value of attribute upload_response.



13
14
15
# File 'lib/filestack/models/filelink.rb', line 13

def upload_response
  @upload_response
end

Instance Method Details

#deleteTyphoeus::Response

Delete filelink

Returns:

  • (Typhoeus::Response)


47
48
49
# File 'lib/filestack/models/filelink.rb', line 47

def delete
  send_delete(handle, apikey, security)
end

#download(filepath) ⇒ Typhoeus::Response

Download FilestackFilelink

Parameters:

  • filepath (String)

    The local destination of the downloaded filelink

Returns:

  • (Typhoeus::Response)


40
41
42
# File 'lib/filestack/models/filelink.rb', line 40

def download(filepath)
  send_download(url, filepath)
end

#get_contentBytes

Get content of filelink

Returns:

  • (Bytes)


31
32
33
# File 'lib/filestack/models/filelink.rb', line 31

def get_content
  send_get_content(url)
end

#metadata(params = {}) ⇒ Hash

Return metadata for file handle

Returns:



78
79
80
# File 'lib/filestack/models/filelink.rb', line 78

def (params = {})
  (@handle, @security, params)
end

#overwrite(filepath) ⇒ Typhoeus::Response

Ovewrite filelink by uploading local file

Parameters:

  • filepath (String)

    filepath of file to upload

Returns:

  • (Typhoeus::Response)


56
57
58
# File 'lib/filestack/models/filelink.rb', line 56

def overwrite(filepath)
  send_overwrite(filepath, handle, apikey, security)
end

#sfwBool

Return true (SFW) or false (NSFW)

Returns:

  • (Bool)


85
86
87
# File 'lib/filestack/models/filelink.rb', line 85

def sfw
  send_tags('sfw', @handle, @security)
end

#tagsHash

Return auto and user tags for the filelink

Returns:



71
72
73
# File 'lib/filestack/models/filelink.rb', line 71

def tags
  send_tags('tags', @handle, @security)
end

#transformFilestack::Transform

Turn the filelink into a transform object to perform transform operations

Returns:

  • (Filestack::Transform)


64
65
66
# File 'lib/filestack/models/filelink.rb', line 64

def transform
  Transform.new(handle: @handle, apikey: @apikey, security: @security)
end

#urlString

Get the URL of the FilestackFilelink

Returns:

  • (String)


92
93
94
95
96
# File 'lib/filestack/models/filelink.rb', line 92

def url
  UploadUtils.get_url(
    FilestackConfig::CDN_URL, handle: handle, security: security
  )
end