Class: Retab::Edits

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Edits

Returns a new instance of Edits.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create(instructions:, document: nil, template_id: nil, model: nil, config: nil, bust_cache: nil, request_options: {}) ⇒ Retab::Edit

Create Edit

Parameters:

  • instructions (String)

    Instructions describing how to fill the form fields.

  • document (Retab::MimeData, Pathname, IO, String, Hash, nil) (defaults to: nil)

    Input document (PDF, DOCX, XLSX, or PPTX). Mutually exclusive with template_id.

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

    EditTemplate id to fill. When provided, uses the template’s pre-defined form fields and empty PDF. Mutually exclusive with document.

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

    The model to use for edit inference.

  • config (Retab::EditConfig, nil) (defaults to: nil)

    Edit configuration (rendering options).

  • bust_cache (Boolean, nil) (defaults to: nil)

    If true, skip the LLM cache and force a fresh completion.

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

    (see Retab::Types::RequestOptions)

Returns:



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
120
121
122
123
124
125
126
# File 'lib/retab/edits.rb', line 94

def create(
  instructions:,
  document: nil,
  template_id: nil,
  model: nil,
  config: nil,
  bust_cache: nil,
  request_options: {}
)
  document = Retab::MimeData.coerce(document) unless document.nil?
  body = {
    "instructions" => instructions,
    "document" => document,
    "template_id" => template_id,
    "model" => model,
    "config" => config,
    "bust_cache" => bust_cache
  }.compact
  response = @client.request(
    method: :post,
    path: "/v1/edits",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::Edit.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

#delete(edit_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete Edit

Parameters:

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

    (see Retab::Types::RequestOptions)



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/retab/edits.rb', line 155

def delete(
  edit_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/v1/edits/#{Retab::Util.encode_path(edit_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#get(edit_id:, request_options: {}) ⇒ Retab::Edit

Get Edit

Parameters:

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

    (see Retab::Types::RequestOptions)

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/retab/edits.rb', line 132

def get(
  edit_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/v1/edits/#{Retab::Util.encode_path(edit_id)}",
    auth: true,
    request_options: request_options
  )
  result = Retab::Edit.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: 10, order: "desc", filename: nil, template_id: nil, from_date: nil, to_date: nil, request_options: {}) ⇒ Retab::PaginatedList<Retab::Edit>

List Edits

Parameters:

  • before (String, nil) (defaults to: nil)
  • after (String, nil) (defaults to: nil)
  • limit (Integer, nil) (defaults to: 10)
  • order (Retab::Types::EditsOrder, nil) (defaults to: "desc")
  • filename (String, nil) (defaults to: nil)
  • template_id (String, nil) (defaults to: nil)
  • from_date (String, nil) (defaults to: nil)
  • to_date (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



28
29
30
31
32
33
34
35
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
# File 'lib/retab/edits.rb', line 28

def list(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  filename: nil,
  template_id: nil,
  from_date: nil,
  to_date: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "filename" => filename,
    "template_id" => template_id,
    "from_date" => from_date,
    "to_date" => to_date
  }.compact
  response = @client.request(
    method: :get,
    path: "/v1/edits",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = -> (cursor) {
    list(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      filename: filename,
      template_id: template_id,
      from_date: from_date,
      to_date: to_date,
      request_options: request_options
    )
  }
  Retab::PaginatedList.from_response(
    response,
    model: Retab::Edit,
    filters: {
      before: before,
      limit: limit,
      order: order,
      filename: filename,
      template_id: template_id,
      from_date: from_date,
      to_date: to_date
    },
    fetch_next: fetch_next
  )
end

#templatesObject



13
14
15
# File 'lib/retab/edits.rb', line 13

def templates
  @templates ||= Retab::EditTemplates.new(@client)
end