Class: Dato::Upload::File

Inherits:
Object
  • Object
show all
Defined in:
lib/dato/upload/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, source, upload_attributes = {}, field_attributes = {}) ⇒ File

Returns a new instance of File.



10
11
12
13
14
15
# File 'lib/dato/upload/file.rb', line 10

def initialize(client, source, upload_attributes = {}, field_attributes = {})
  @client = client
  @source = source
  @upload_attributes = upload_attributes
  @field_attributes = field_attributes
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/dato/upload/file.rb', line 8

def client
  @client
end

#field_attributesObject (readonly)

Returns the value of attribute field_attributes.



8
9
10
# File 'lib/dato/upload/file.rb', line 8

def field_attributes
  @field_attributes
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/dato/upload/file.rb', line 8

def source
  @source
end

#upload_attributesObject (readonly)

Returns the value of attribute upload_attributes.



8
9
10
# File 'lib/dato/upload/file.rb', line 8

def upload_attributes
  @upload_attributes
end

Instance Method Details

#uploadObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dato/upload/file.rb', line 17

def upload
  upload_path = CreateUploadPath.new(client, source).upload_path

  upload = client.uploads.create(
    upload_attributes.merge(path: upload_path),
  )

  {
    alt: nil,
    title: nil,
    custom_data: {},
  }.merge(field_attributes).merge(upload_id: upload["id"])
end