Class: Mindee::V2::Parsing::Job
- Inherits:
-
Object
- Object
- Mindee::V2::Parsing::Job
- Defined in:
- lib/mindee/v2/parsing/job.rb
Overview
Metadata returned when polling a job (asynchronous request).
Instance Attribute Summary collapse
-
#alias ⇒ String
readonly
Optional alias for the file.
-
#completed_at ⇒ Time?
readonly
Date and time of the Job completion.
-
#created_at ⇒ Time
readonly
Date and time of the Job 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
rubocop:disable Metrics/CyclomaticComplexity.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(server_response) ⇒ Job
rubocop:disable Metrics/CyclomaticComplexity
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mindee/v2/parsing/job.rb', line 37 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']) if server_response.key?('completed_at') && !server_response['completed_at'].nil? @completed_at = Time.iso8601(server_response['completed_at']) end @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.
23 24 25 |
# File 'lib/mindee/v2/parsing/job.rb', line 23 def alias @alias end |
#completed_at ⇒ Time? (readonly)
Returns Date and time of the Job completion. Filled once processing is finished.
17 18 19 |
# File 'lib/mindee/v2/parsing/job.rb', line 17 def completed_at @completed_at end |
#created_at ⇒ Time (readonly)
Returns Date and time of the Job creation.
15 16 17 |
# File 'lib/mindee/v2/parsing/job.rb', line 15 def created_at @created_at end |
#error ⇒ ErrorResponse? (readonly)
Returns Error details when the job failed.
33 34 35 |
# File 'lib/mindee/v2/parsing/job.rb', line 33 def error @error end |
#filename ⇒ String (readonly)
Returns Name of the processed file.
21 22 23 |
# File 'lib/mindee/v2/parsing/job.rb', line 21 def filename @filename end |
#id ⇒ String (readonly)
Returns Unique job identifier.
13 14 15 |
# File 'lib/mindee/v2/parsing/job.rb', line 13 def id @id end |
#model_id ⇒ String (readonly)
Returns Identifier of the model used.
19 20 21 |
# File 'lib/mindee/v2/parsing/job.rb', line 19 def model_id @model_id end |
#polling_url ⇒ String (readonly)
Returns URL to query for updated status.
27 28 29 |
# File 'lib/mindee/v2/parsing/job.rb', line 27 def polling_url @polling_url end |
#result_url ⇒ String? (readonly)
Returns URL that redirects to the final result once ready.
29 30 31 |
# File 'lib/mindee/v2/parsing/job.rb', line 29 def result_url @result_url end |
#status ⇒ String? (readonly)
Returns Current status (submitted, processing, done, …).
25 26 27 |
# File 'lib/mindee/v2/parsing/job.rb', line 25 def status @status end |
#webhooks ⇒ Array<JobWebhook> (readonly)
Returns Webhooks triggered by the job.
31 32 33 |
# File 'lib/mindee/v2/parsing/job.rb', line 31 def webhooks @webhooks end |
Instance Method Details
#to_s ⇒ String
String representation.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mindee/v2/parsing/job.rb', line 63 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.join("\n\n"), ] end lines.join("\n") end |