Sha256: a0da959d4379fd9a359648c3806d0883132af87fc6dca5f001d6f2f9c5e742e8

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

class Encoding < Hashie::Mash
end

class Assembly < ActiveRecord::Base
  unloadable

  ASSEMBLY_STATUS_KEY     = "ok"
  ASSEMBLY_COMPLETE_VALUE = "ASSEMBLY_COMPLETED"

  attr_accessible :project_id, :assembly_id, :assembly_url, :user_id

  belongs_to :project
  belongs_to :user

  named_scope :processed, :conditions => {:processed => true}
  named_scope :unprocessed, :conditions => {:processed => false}

  before_create :set_processed_to_false

  def completed?
    raw_assembly(:reload)[ASSEMBLY_STATUS_KEY] == ASSEMBLY_COMPLETE_VALUE
  end

  def custom_fields
    HashWithIndifferentAccess.new(raw_assembly["fields"])
  end

  def encodings
    raise ChiliVideos::Error::IncompleteAssembly unless completed?

    raw_assembly["results"]["encode"].map do |raw_encoding|
      Encoding.new(raw_encoding)
    end
  end

  # Retrieves and caches the content of .assembly_url. If you pass
  # in :reload as an argument, it will visit the URL again and replace
  # the existing values.
  #
  # reload_or_not - determines whether the method call should use a cached
  #                 version of the content or not. :reload is the only value
  #                 which will have an impact on the method call.
  #
  # Returns the HTTP response as a Hash
  def raw_assembly(symbol = nil)
    return @raw_assembly if @raw_assembly && symbol != :reload
    @raw_assembly = Retriever.get(assembly_url)
  end

  class << self
    class ::Retriever
      include HTTParty
      format :json
    end
  end

  private
    def set_processed_to_false
      self.processed = false
      true
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chili_videos-0.2.1 app/models/assembly.rb
chili_videos-0.2.0 app/models/assembly.rb
chili_videos-0.1.0 app/models/assembly.rb