class Podio::FileAttachment

@see developers.podio.com/doc/files

Public Class Methods

attach(id, ref_type, ref_id) click to toggle source

Attach a file to an existing reference @see developers.podio.com/doc/files/attach-file-22518

# File lib/podio/models/file_attachment.rb, line 85
def attach(id, ref_type, ref_id)
  Podio.connection.post do |req|
    req.url "/file/#{id}/attach"
    req.body = {:ref_type => ref_type, :ref_id => ref_id}
  end
end
copy(id) click to toggle source

@see developers.podio.com/doc/files/copy-file-89977

# File lib/podio/models/file_attachment.rb, line 93
def copy(id)
  Podio.connection.post("/file/#{id}/copy").body['file_id']
end
create(name, content_type) click to toggle source

Uploading a file is a two-step operation First, the file must be created to get a file id and the path to move it to

# File lib/podio/models/file_attachment.rb, line 176
def create(name, content_type)
  response = Podio.connection.post do |req|
    req.url "/file/"
    req.body = { :name => name, :mimetype => content_type }
  end

  response.body
end
create_from_external_file_id(linked_account_id, external_file_id, preserve_permissions=false, options={}) click to toggle source
# File lib/podio/models/file_attachment.rb, line 71
def create_from_external_file_id(linked_account_id, external_file_id, preserve_permissions=false, options={})
  response = Podio.client.connection.post do |req|
    req.url("/file/linked_account/#{linked_account_id}/", options)
    req.body = {
        :external_file_id     => external_file_id,
        :preserve_permissions => preserve_permissions
    }
  end

  member response.body
end
delete(id) click to toggle source

@see developers.podio.com/doc/files/delete-file-22453

# File lib/podio/models/file_attachment.rb, line 98
def delete(id)
  Podio.connection.delete("/file/#{id}")
end
find(id) click to toggle source

@see developers.podio.com/doc/files/get-file-22451

# File lib/podio/models/file_attachment.rb, line 103
def find(id)
  member Podio.connection.get("/file/#{id}").body
end
find_all(options={}) click to toggle source

@see developers.podio.com/doc/files/get-files-4497983

# File lib/podio/models/file_attachment.rb, line 113
def find_all(options={})
  list Podio.connection.get { |req|
    req.url("/file/", options)
  }.body
end
find_for_app(app_id, options={}) click to toggle source

@see developers.podio.com/doc/files/get-files-on-app-22472

# File lib/podio/models/file_attachment.rb, line 120
def find_for_app(app_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/app/#{app_id}/", options)
  }.body
end
find_for_google(linked_account_id, options={}) click to toggle source
# File lib/podio/models/file_attachment.rb, line 147
def find_for_google(linked_account_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/google/#{linked_account_id}/", options)
  }.body
end
find_for_space(space_id, options={}) click to toggle source

@see developers.podio.com/doc/files/get-files-on-space-22471

# File lib/podio/models/file_attachment.rb, line 127
def find_for_space(space_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/space/#{space_id}/", options)
  }.body
end
find_latest_for_app(app_id, options={}) click to toggle source

@see developers.podio.com/doc/files/get-latest-files-on-app-22473

# File lib/podio/models/file_attachment.rb, line 134
def find_latest_for_app(app_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/app/#{app_id}/latest/", options)
  }.body
end
find_latest_for_space(space_id, options={}) click to toggle source

@see developers.podio.com/doc/files/get-latest-files-on-space-22470

# File lib/podio/models/file_attachment.rb, line 141
def find_latest_for_space(space_id, options={})
  list Podio.connection.get { |req|
    req.url("/file/space/#{space_id}/latest/", options)
  }.body
end
find_raw(id) click to toggle source

@see developers.podio.com/doc/files/download-file-1004147

# File lib/podio/models/file_attachment.rb, line 108
def find_raw(id)
  Podio.client.connection.get("/file/#{id}/raw").body
end
replace(old_file_id, new_file_id) click to toggle source

@see developers.podio.com/doc/files/replace-file-22450

# File lib/podio/models/file_attachment.rb, line 154
def replace(old_file_id, new_file_id)
  Podio.connection.post { |req|
    req.url "/file/#{new_file_id}/replace"
    req.body = { :old_file_id => old_file_id }
  }.body
end
set_available(id) click to toggle source

Then, when the file has been moved, it must be marked as available

# File lib/podio/models/file_attachment.rb, line 186
def set_available(id)
  Podio.connection.post "/file/#{id}/available"
end
update(id, description) click to toggle source

@see developers.podio.com/doc/files/update-file-22454

# File lib/podio/models/file_attachment.rb, line 162
def update(id, description)
  Podio.connection.put { |req|
    req.url "/file/#{file_id}"
    req.body = { :description => description }
  }.body
end
upload(file_stream, file_name) click to toggle source

Accepts an open file stream along with a file name and uploads the file to Podio @see developers.podio.com/doc/files/upload-file-1004361

# File lib/podio/models/file_attachment.rb, line 51
def upload(file_stream, file_name)
  response = Podio.client.connection.post do |req|
    req.options[:timeout] = 1200
    req.url "/file/v2/"
    req.headers['Content-Type'] = 'multipart/form-data'
    req.body = {:source => Faraday::UploadIO.new(file_stream, nil, nil), :filename => file_name}
  end

  member response.body
end
upload_from_url(url) click to toggle source
# File lib/podio/models/file_attachment.rb, line 62
def upload_from_url(url)
  response = Podio.client.connection.post do |req|
    req.url "/file/from_url/"
    req.body = {:url => url}
  end

  member response.body
end

Public Instance Methods

api_friendly_ref_type() click to toggle source
# File lib/podio/models/file_attachment.rb, line 37
def api_friendly_ref_type
  'file'
end
has_thumbnail?() click to toggle source
# File lib/podio/models/file_attachment.rb, line 29
def has_thumbnail?
  self.thumbnail_link.present?
end
image?() click to toggle source
# File lib/podio/models/file_attachment.rb, line 33
def image?
  ['image/png', 'image/jpeg', 'image/gif', 'image/bmp'].include?(self.mimetype)
end
raw_data(size=nil) click to toggle source

Returns the raw bytes of a file for images pass the size used by podio in its urls e.g. files.podio.com/:file/medium

# File lib/podio/models/file_attachment.rb, line 43
def raw_data(size=nil)
  link = size ? "#{self.link}/#{size}" : self.link
  Podio.connection.get(link).body
end