Class: Mindee::Parsing::V2::Job
- Inherits:
-
Object
- Object
- Mindee::Parsing::V2::Job
- Defined in:
- lib/mindee/parsing/v2/job.rb
Overview
Metadata returned when polling a job (asynchronous request).
Instance Attribute Summary collapse
-
#alias ⇒ String
readonly
Optional alias for the file.
-
#created_at ⇒ DateTime?
readonly
Timestamp of creation.
-
#error ⇒ ErrorResponse?
readonly
Error details when the job failed.
-
#filename ⇒ String
readonly
Name of the processed file.
-
#id ⇒ String
readonly
Unique job identifier.
-
#model_id ⇒ String
readonly
Identifier of the model used.
-
#polling_url ⇒ String
readonly
URL to query for updated status.
-
#result_url ⇒ String?
readonly
URL that redirects to the final result once ready.
-
#status ⇒ String?
readonly
Current status (submitted, processing, done, …).
-
#webhooks ⇒ Array<JobWebhook>
readonly
Webhooks triggered by the job.
Instance Method Summary collapse
-
#initialize(server_response) ⇒ Job
constructor
A new instance of Job.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(server_response) ⇒ Job
Returns a new instance of Job.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mindee/parsing/v2/job.rb', line 34 def initialize(server_response) raise ArgumentError, 'server_response must be a Hash' unless server_response.is_a?(Hash) @id = server_response['id'] @status = server_response['status'] if server_response.key?('status') unless server_response['error'].nil? || server_response['error'].empty? @error = ErrorResponse.new(server_response['error']) end @created_at = Time.iso8601(server_response['created_at']) @model_id = server_response['model_id'] @polling_url = server_response['polling_url'] @filename = server_response['filename'] @result_url = server_response['result_url'] @alias = server_response['alias'] @webhooks = [] server_response['webhooks'].each do |webhook| @webhooks.push JobWebhook.new(webhook) end end |
Instance Attribute Details
#alias ⇒ String (readonly)
Returns Optional alias for the file.
21 22 23 |
# File 'lib/mindee/parsing/v2/job.rb', line 21 def alias @alias end |
#created_at ⇒ DateTime? (readonly)
Returns Timestamp of creation.
15 16 17 |
# File 'lib/mindee/parsing/v2/job.rb', line 15 def created_at @created_at end |
#error ⇒ ErrorResponse? (readonly)
Returns Error details when the job failed.
31 32 33 |
# File 'lib/mindee/parsing/v2/job.rb', line 31 def error @error end |
#filename ⇒ String (readonly)
Returns Name of the processed file.
19 20 21 |
# File 'lib/mindee/parsing/v2/job.rb', line 19 def filename @filename end |
#id ⇒ String (readonly)
Returns Unique job identifier.
13 14 15 |
# File 'lib/mindee/parsing/v2/job.rb', line 13 def id @id end |
#model_id ⇒ String (readonly)
Returns Identifier of the model used.
17 18 19 |
# File 'lib/mindee/parsing/v2/job.rb', line 17 def model_id @model_id end |
#polling_url ⇒ String (readonly)
Returns URL to query for updated status.
25 26 27 |
# File 'lib/mindee/parsing/v2/job.rb', line 25 def polling_url @polling_url end |
#result_url ⇒ String? (readonly)
Returns URL that redirects to the final result once ready.
27 28 29 |
# File 'lib/mindee/parsing/v2/job.rb', line 27 def result_url @result_url end |
#status ⇒ String? (readonly)
Returns Current status (submitted, processing, done, …).
23 24 25 |
# File 'lib/mindee/parsing/v2/job.rb', line 23 def status @status end |
#webhooks ⇒ Array<JobWebhook> (readonly)
Returns Webhooks triggered by the job.
29 30 31 |
# File 'lib/mindee/parsing/v2/job.rb', line 29 def webhooks @webhooks end |
Instance Method Details
#to_s ⇒ String
String representation.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mindee/parsing/v2/job.rb', line 56 def to_s lines = [ 'Job', '###', ":ID: #{@id}", ":CreatedAt: #{@created_at}", ":ModelID: #{@model_id}", ":Filename: #{@filename}", ":Alias: #{@alias}", ":Status: #{@status}", ":PollingURL: #{@polling_url}", ":ResultURL: #{@result_url}", ] lines << @error.to_s if @error unless @webhooks.empty? lines += [ '', 'Webhooks', '=========', @webhooks.map(&:to_s).join("\n\n"), ] end lines.join("\n") end |