Class: Polar::Resources::Files

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

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Polar::Resources::Base

Instance Method Details

#create(attributes) ⇒ Hash

Create a file upload

Parameters:

  • attributes (Hash)

    File attributes

Options Hash (attributes):

  • :name (String)

    File name

  • :mime_type (String)

    File MIME type

  • :size (Integer)

    File size in bytes

  • :organization_id (String)

    Organization ID

Returns:

  • (Hash)

    File upload information including signed URL



25
26
27
28
# File 'lib/polar/resources/files.rb', line 25

def create(attributes)
  response = post('/files/', attributes)
  response.body
end

#delete(id) ⇒ Boolean

Delete a file

Parameters:

  • id (String)

    File ID

Returns:

  • (Boolean)

    Success status



51
52
53
54
# File 'lib/polar/resources/files.rb', line 51

def delete(id)
  delete("/files/#{id}")
  true
end

#list(params = {}) ⇒ PaginatedResponse

List files

Parameters:

  • params (Hash) (defaults to: {})

    Query parameters

Options Hash (params):

  • :organization_id (String)

    Filter by organization ID

  • :page (Integer)

    Page number

  • :limit (Integer)

    Items per page

Returns:



14
15
16
# File 'lib/polar/resources/files.rb', line 14

def list(params = {})
  paginate('/files/', params)
end

#update(id, attributes) ⇒ Hash

Update file metadata

Parameters:

  • id (String)

    File ID

  • attributes (Hash)

    Updated attributes

Returns:

  • (Hash)

    Updated file



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

def update(id, attributes)
  response = patch("/files/#{id}", attributes)
  response.body
end

#uploaded(id, completion_data = {}) ⇒ Hash

Mark file upload as completed

Parameters:

  • id (String)

    File ID

  • completion_data (Hash) (defaults to: {})

    Upload completion data

Returns:

  • (Hash)

    Completed file data



34
35
36
37
# File 'lib/polar/resources/files.rb', line 34

def uploaded(id, completion_data = {})
  response = post("/files/#{id}/uploaded", completion_data)
  response.body
end