Class: Retab::Jobs

Inherits:
Object
  • Object
show all
Defined in:
lib/retab/jobs.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Jobs

Returns a new instance of Jobs.



9
10
11
# File 'lib/retab/jobs.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#cancel(job_id:, request_options: {}) ⇒ Retab::Job

Cancel Job

Parameters:

  • job_id (String)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/retab/jobs.rb', line 182

def cancel(
  job_id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/v1/jobs/#{Retab::Util.encode_path(job_id)}/cancel",
    auth: true,
    request_options: request_options
  )
  result = Retab::Job.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create(endpoint:, request:, metadata: nil, request_options: {}) ⇒ Retab::Job

Create Job

Parameters:

  • endpoint (Retab::Types::CreateJobRequestEndpoint)
  • request (Hash{String => Object})
  • metadata (Hash{String => String}, nil) (defaults to: nil)

    Max 16 pairs; keys ≤64 chars, values ≤512 chars

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/retab/jobs.rb', line 127

def create(
  endpoint:,
  request:,
  metadata: nil,
  request_options: {}
)
  body = {
    'endpoint' => endpoint,
    'request' => request,
    'metadata' => 
  }.compact
  response = @client.request(
    method: :post,
    path: '/v1/jobs',
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::Job.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#get(job_id:, include_request: false, include_response: false, request_options: {}) ⇒ Retab::Job

Retrieve Job

Parameters:

  • job_id (String)
  • include_request (Boolean, nil) (defaults to: false)

    Include the original request payload in the response.

  • include_response (Boolean, nil) (defaults to: false)

    Include the job response payload in the response.

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/retab/jobs.rb', line 156

def get(
  job_id:,
  include_request: false,
  include_response: false,
  request_options: {}
)
  params = {
    'include_request' => include_request,
    'include_response' => include_response
  }.compact
  response = @client.request(
    method: :get,
    path: "/v1/jobs/#{Retab::Util.encode_path(job_id)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  result = Retab::Job.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#list(before: nil, after: nil, limit: 20, order: 'desc', job_id: nil, status: nil, endpoint: nil, source: nil, project_id: nil, workflow_id: nil, workflow_block_id: nil, model: nil, filename_regex: nil, filename_contains: nil, document_type: nil, from_date: nil, to_date: nil, metadata: nil, include_request: false, include_response: false, request_options: {}) ⇒ Retab::Types::ListStruct<Retab::Job>

List Jobs

Parameters:

  • before (String, nil) (defaults to: nil)

    First job ID from the current page, used to fetch the previous page

  • after (String, nil) (defaults to: nil)

    Last job ID from the previous page, used to fetch the next page

  • limit (Integer, nil) (defaults to: 20)

    Number of jobs to return

  • order (Retab::Types::JobsOrder, nil) (defaults to: 'desc')

    Sort order by created_at

  • job_id (String, nil) (defaults to: nil)

    Filter by job ID

  • status (Retab::Types::JobsStatus, nil) (defaults to: nil)

    Filter by status

  • endpoint (Retab::Types::JobsEndpoint, nil) (defaults to: nil)

    Filter by endpoint

  • source (Retab::Types::JobsSource, nil) (defaults to: nil)

    High-level source filter. Use api/project/workflow.

  • project_id (String, nil) (defaults to: nil)

    Filter by request.project_id

  • workflow_id (String, nil) (defaults to: nil)

    Filter by metadata.workflow_id

  • workflow_block_id (String, nil) (defaults to: nil)

    Filter by metadata.workflow_block_id or metadata.block_id

  • model (String, nil) (defaults to: nil)

    Filter by request.model

  • filename_regex (String, nil) (defaults to: nil)

    Regex or plain text pattern applied to request filenames.

  • filename_contains (String, nil) (defaults to: nil)

    Plain text substring applied to request filenames.

  • document_type (Array<String>, nil) (defaults to: nil)

    Filter by document type. Can be repeated. Accepted values: bmp, csv, doc, docm, docx, dotm, dotx, eml, gif, heic, heif, htm, html, jpeg, jpg, json, md, mhtml, msg, odp, ods, odt, ots, ott, pdf, png, ppt, pptx, rtf, svg, tif, tiff, tsv, txt, webp, xlam, xls, xlsb, xlsm, xlsx, xltm, xltx, xml, yaml, yml.

  • from_date (String, nil) (defaults to: nil)

    Filter jobs created on or after this date (YYYY-MM-DD)

  • to_date (String, nil) (defaults to: nil)

    Filter jobs created on or before this date (YYYY-MM-DD)

  • metadata (String, nil) (defaults to: nil)

    JSON object string to filter metadata key/value pairs.

  • include_request (Boolean, nil) (defaults to: false)

    Whether to include the full original request body in each listed job.

  • include_response (Boolean, nil) (defaults to: false)

    Whether to include full response payloads in each listed job.

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/retab/jobs.rb', line 36

def list(
  before: nil,
  after: nil,
  limit: 20,
  order: 'desc',
  job_id: nil,
  status: nil,
  endpoint: nil,
  source: nil,
  project_id: nil,
  workflow_id: nil,
  workflow_block_id: nil,
  model: nil,
  filename_regex: nil,
  filename_contains: nil,
  document_type: nil,
  from_date: nil,
  to_date: nil,
  metadata: nil,
  include_request: false,
  include_response: false,
  request_options: {}
)
  params = {
    'before' => before,
    'after' => after,
    'limit' => limit,
    'order' => order,
    'job_id' => job_id,
    'status' => status,
    'endpoint' => endpoint,
    'source' => source,
    'project_id' => project_id,
    'workflow_id' => workflow_id,
    'workflow_block_id' => workflow_block_id,
    'model' => model,
    'filename_regex' => filename_regex,
    'filename_contains' => filename_contains,
    'document_type' => document_type,
    'from_date' => from_date,
    'to_date' => to_date,
    'metadata' => ,
    'include_request' => include_request,
    'include_response' => include_response
  }.compact
  response = @client.request(
    method: :get,
    path: '/v1/jobs',
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      job_id: job_id,
      status: status,
      endpoint: endpoint,
      source: source,
      project_id: project_id,
      workflow_id: workflow_id,
      workflow_block_id: workflow_block_id,
      model: model,
      filename_regex: filename_regex,
      filename_contains: filename_contains,
      document_type: document_type,
      from_date: from_date,
      to_date: to_date,
      metadata: ,
      include_request: include_request,
      include_response: include_response,
      request_options: request_options
    )
  }
  Retab::Types::ListStruct.from_response(
    response,
    model: Retab::Job,
    filters: { before: before, limit: limit, order: order, job_id: job_id, status: status, endpoint: endpoint, source: source, project_id: project_id, workflow_id: workflow_id, workflow_block_id: workflow_block_id, model: model, filename_regex: filename_regex, filename_contains: filename_contains, document_type: document_type, from_date: from_date, to_date: to_date, metadata: , include_request: include_request, include_response: include_response },
    fetch_next: fetch_next
  )
end

#retry(job_id:, request_options: {}) ⇒ Retab::Job

Retry Job

Parameters:

  • job_id (String)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/retab/jobs.rb', line 201

def retry(
  job_id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/v1/jobs/#{Retab::Util.encode_path(job_id)}/retry",
    auth: true,
    request_options: request_options
  )
  result = Retab::Job.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end