Sha256: c4f7f4c96d605bcf5d6269bc1b5d01a3d49793dfae01eefe062163198c7ac703

Contents?: true

Size: 1.44 KB

Versions: 53

Compression:

Stored size: 1.44 KB

Contents

class Ey::Core::Client::ApplicationArchive < Ey::Core::Model
  extend Ey::Core::Associations

  identity :id

  attribute :sha256
  attribute :filename
  attribute :upload_successful
  attribute :upload_url
  attribute :url

  has_one :application

  # FIXME: hard coded in core, not exposed via api
  def mime_type
    "text/plain"
  end

  def save!
    if new_record?
      requires :filename
      params = {
        "url" => self.collection.url,
        "application" => self.application_id,
        "application_archive" => {
          "filename" => filename,
          "sha256"   => sha256,
        },
      }
      merge_attributes(self.connection.create_application_archive(params).body["application_archive"])
    else
      params = {
        "id" => id,
        "application" => self.application_id,
        "application_archive" => {
          "upload_successful" => upload_successful,
        }
      }
      merge_attributes(self.connection.update_application_archive(params).body["application_archive"])
    end
  end

  def upload(options)
    requires :upload_url

    params = {
      "body"       => options[:body] || File.read(options[:file]),
      "mime_type"  => self.mime_type,
      "upload_url" => self.upload_url,
    }

    self.connection.upload_file(params)

    self.upload_successful = true
    self.save
  end

  def download
    requires :url

    params = {
      "url" => self.url,
    }

    self.connection.download_file(params)
  end
end

Version data entries

53 entries across 53 versions & 3 rubygems

Version Path
ey-core-3.6.4 lib/ey-core/models/application_archive.rb
ey-core-3.6.3 lib/ey-core/models/application_archive.rb
ey-core-3.6.1 lib/ey-core/models/application_archive.rb
groove-ey-core-3.6.3 lib/ey-core/models/application_archive.rb
groove-ey-core-3.6.2 lib/ey-core/models/application_archive.rb
groove-ey-core-3.6.1 lib/ey-core/models/application_archive.rb
ey-core-3.5.0 lib/ey-core/models/application_archive.rb
ey-core-3.4.4 lib/ey-core/models/application_archive.rb
ey-core-3.4.2 lib/ey-core/models/application_archive.rb
ey-core-3.4.1 lib/ey-core/models/application_archive.rb
ey-core-3.4.0 lib/ey-core/models/application_archive.rb
ey-core-3.3.1 lib/ey-core/models/application_archive.rb
ey-core-3.3.0 lib/ey-core/models/application_archive.rb
ey-core-3.2.6 lib/ey-core/models/application_archive.rb
ey-core-3.2.5 lib/ey-core/models/application_archive.rb
ey-core-3.2.4 lib/ey-core/models/application_archive.rb
ey-core-3.2.3 lib/ey-core/models/application_archive.rb
ey-core-3.2.2 lib/ey-core/models/application_archive.rb
ey-core-3.2.1 lib/ey-core/models/application_archive.rb
ey-core-3.2.0 lib/ey-core/models/application_archive.rb