Sha256: a2d53529a6df53a0a107c7d7d66f2bd27c808c322a02f57d953458f0170a33e7

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

module Bitmovin::Encoding::Inputs
  class AnalysisTask
    # Creates a new Analysis object
    # == Parameters:
    # input::
    #   Either an input-id (string) or a InputResource
    # analysis_id::
    #   Id of the analysis task
    def initialize(input, analysis_id)
      if (input.instance_of?(String))
        @input_id = input
      else
        @input_id = input.id
        @input = input
      end
      @id = analysis_id
    end

    attr_reader :id, :input_id

    def input
      @input
    end

    def status
      five_seconds_ago = (Time.now - 5)
      puts @last_status_call
      if @last_status_call.nil? || @last_status_call <= five_seconds_ago
        response = Bitmovin.client.get File.join("/v1/encoding/inputs/", @input_id, "analysis", @id, "status")
        @status_result = OpenStruct.new(JSON.parse(response.body)['data']['result']['analysis'])
        @last_status_call = Time.now
      end
      @status_result
    end

    def created?
      status.status == "CREATED"
    end

    def queued?
      status.status == "QUEUED"
    end

    def running?
      status.status == "RUNNING"
    end

    def finished?
      status.status == "FINISHED"
    end

    def error?
      status.status == "ERROR"
    end

    def eta?
      status.eta
    end

    def progress?
      status.progress
    end

    # Returns the analysis result
    # Will raise and error if analysis is not yet finished
    def result
      if !finished?
        raise BitmovinError.new(self), "analysis is not finished yet"
      end
      Analysis.new(@input_id).find(@id)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bitmovin-ruby-0.9.1 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.9.0 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.8.1 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.8.0 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.7.0 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.5.0 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.4.0 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.3.0 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.2.0 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.1.1 lib/bitmovin/encoding/inputs/analysis_task.rb
bitmovin-ruby-0.1.0 lib/bitmovin/encoding/inputs/analysis_task.rb