Sha256: 95fe5d5117e7a9059df6dab0a2ca18fd145449c5dc27303b6bfa378fe2487fd9

Contents?: true

Size: 873 Bytes

Versions: 10

Compression:

Stored size: 873 Bytes

Contents

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

  identity :id

  attribute :created_at
  attribute :filename
  attribute :mime_type
  attribute :download_url
  attribute :upload_url

  has_one :component_action

  attr_accessor :file, :component_action_id

  def save!
    if self.file.kind_of?(File)
      body = File.read(self.file)
    else
      body = self.file
    end

    params = {
      "component_action_id" => component_action_id,
      "log" => {
        "file"      => body,
        "filename"  => filename || "log",
        "mime_type" => mime_type,
      }
    }

    merge_attributes(self.connection.create_log(params).body["log"])
  end

  def contents
    body = Faraday.get(download_url).body
    if filename.match(/\.gz$/)
      Zlib::GzipReader.new(StringIO.new(body, "rb")).read
    else
      body
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ey-core-3.1.8 lib/ey-core/models/log.rb
ey-core-3.1.7 lib/ey-core/models/log.rb
ey-core-3.1.6 lib/ey-core/models/log.rb
ey-core-3.1.5 lib/ey-core/models/log.rb
ey-core-3.1.4 lib/ey-core/models/log.rb
ey-core-3.1.3 lib/ey-core/models/log.rb
ey-core-3.1.2 lib/ey-core/models/log.rb
ey-core-3.1.1 lib/ey-core/models/log.rb
ey-core-3.1.0 lib/ey-core/models/log.rb
ey-core-3.0.5 lib/ey-core/models/log.rb