Class: Api2Convert::Model::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/api2convert/model/job.rb

Overview

A conversion job — the central API2Convert resource.

#server and #token are needed to upload local files; #output holds the produced files once #completed?. #raw keeps the full decoded response for fields not surfaced as typed attributes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, status:, token:, server:, callback:, conversion:, input:, output:, errors:, warnings:, raw:) ⇒ Job

Returns a new instance of Job.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/api2convert/model/job.rb', line 14

def initialize(id:, status:, token:, server:, callback:,
               conversion:, input:, output:, errors:, warnings:, raw:)
  @id = id
  @status = status
  @token = token
  @server = server
  @callback = callback
  @conversion = conversion
  @input = input
  @output = output
  @errors = errors
  @warnings = warnings
  @raw = raw
  freeze
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def callback
  @callback
end

#conversionObject (readonly)

Returns the value of attribute conversion.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def conversion
  @conversion
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def errors
  @errors
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def id
  @id
end

#inputObject (readonly)

Returns the value of attribute input.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def output
  @output
end

#rawObject (readonly)

Returns the value of attribute raw.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def raw
  @raw
end

#serverObject (readonly)

Returns the value of attribute server.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def server
  @server
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def status
  @status
end

#tokenObject (readonly)

Returns the value of attribute token.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def token
  @token
end

#warningsObject (readonly)

Returns the value of attribute warnings.



11
12
13
# File 'lib/api2convert/model/job.rb', line 11

def warnings
  @warnings
end

Class Method Details

.from_hash(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/api2convert/model/job.rb', line 30

def self.from_hash(data)
  d = Support::Data.as_object(data)
  new(
    id: Support::Data.as_str(d["id"]),
    status: Status.from_hash(d["status"]),
    token: Support::Data.nullable_str(d["token"]),
    server: Support::Data.nullable_str(d["server"]),
    callback: Support::Data.nullable_str(d["callback"]),
    conversion: Support::Data.map_objects(d["conversion"]) { |x| Conversion.from_hash(x) },
    input: Support::Data.map_objects(d["input"]) { |x| InputFile.from_hash(x) },
    output: Support::Data.map_objects(d["output"]) { |x| OutputFile.from_hash(x) },
    errors: Support::Data.map_objects(d["errors"]) { |x| JobMessage.from_hash(x) },
    warnings: Support::Data.map_objects(d["warnings"]) { |x| JobMessage.from_hash(x) },
    raw: d
  )
end

Instance Method Details

#canceled?Boolean

The job was canceled server-side — terminal, and produced no output.

Returns:

  • (Boolean)


56
57
58
# File 'lib/api2convert/model/job.rb', line 56

def canceled?
  @status.code == JobStatus::CANCELED
end

#completed?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/api2convert/model/job.rb', line 47

def completed?
  @status.code == JobStatus::COMPLETED
end

#failed?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/api2convert/model/job.rb', line 51

def failed?
  @status.code == JobStatus::FAILED
end

#terminal?Boolean

Finished (completed, failed or canceled) and will not change further.

Returns:

  • (Boolean)


61
62
63
# File 'lib/api2convert/model/job.rb', line 61

def terminal?
  JobStatus.terminal?(@status.code)
end