Class: Bitmovin::Encoding::Inputs::AnalysisTask

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmovin/encoding/inputs/analysis_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, analysis_id) ⇒ AnalysisTask

Creates a new Analysis object

Parameters:

input

Either an input-id (string) or a InputResource

analysis_id

Id of the analysis task



9
10
11
12
13
14
15
16
17
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 9

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



19
20
21
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 19

def id
  @id
end

#input_idObject (readonly)

Returns the value of attribute input_id.



19
20
21
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 19

def input_id
  @input_id
end

Instance Method Details

#created?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 36

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

#error?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 52

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

#eta?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 56

def eta?
  status.eta
end

#finished?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 48

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

#inputObject



21
22
23
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 21

def input
  @input
end

#progress?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 60

def progress?
  status.progress
end

#queued?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 40

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

#resultObject

Returns the analysis result Will raise and error if analysis is not yet finished



66
67
68
69
70
71
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 66

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

#running?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 44

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

#statusObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/bitmovin/encoding/inputs/analysis_task.rb', line 25

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