Class: Retab::EditTemplates

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ EditTemplates

Returns a new instance of EditTemplates.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create(name:, document:, form_fields:, request_options: {}) ⇒ Retab::EditTemplate

Create Template

Parameters:

  • name (String)

    Name of the template.

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

    The PDF document to use as the empty template.

  • form_fields (Array<Retab::FormField>)

    Form fields to attach to the template.

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

    (see Retab::Types::RequestOptions)

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/retab/edit_templates.rb', line 71

def create(
  name:,
  document:,
  form_fields:,
  request_options: {}
)
  document = Retab::MimeData.coerce(document) unless document.nil?
  body = {
    'name' => name,
    'document' => document,
    'form_fields' => form_fields
  }
  response = @client.request(
    method: :post,
    path: '/v1/edits/templates',
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::EditTemplate.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(template_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete Template

Parameters:

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

    (see Retab::Types::RequestOptions)



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/retab/edit_templates.rb', line 146

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

#get(template_id:, request_options: {}) ⇒ Retab::EditTemplate

Get Template

Parameters:

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

    (see Retab::Types::RequestOptions)

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/retab/edit_templates.rb', line 99

def get(
  template_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/v1/edits/templates/#{Retab::Util.encode_path(template_id)}",
    auth: true,
    request_options: request_options
  )
  result = Retab::EditTemplate.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', name: nil, sort_by: 'created_at', request_options: {}) ⇒ Retab::Types::ListStruct<Retab::EditTemplate>

List Templates

Parameters:

  • before (String, nil) (defaults to: nil)
  • after (String, nil) (defaults to: nil)
  • limit (Integer, nil) (defaults to: 10)
  • order (Retab::Types::EditTemplatesOrder, nil) (defaults to: 'desc')
  • name (String, nil) (defaults to: nil)
  • sort_by (String, nil) (defaults to: 'created_at')
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



22
23
24
25
26
27
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
# File 'lib/retab/edit_templates.rb', line 22

def list(
  before: nil,
  after: nil,
  limit: 10,
  order: 'desc',
  name: nil,
  sort_by: 'created_at',
  request_options: {}
)
  params = {
    'before' => before,
    'after' => after,
    'limit' => limit,
    'order' => order,
    'name' => name,
    'sort_by' => sort_by
  }.compact
  response = @client.request(
    method: :get,
    path: '/v1/edits/templates',
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      name: name,
      sort_by: sort_by,
      request_options: request_options
    )
  }
  Retab::Types::ListStruct.from_response(
    response,
    model: Retab::EditTemplate,
    filters: { before: before, limit: limit, order: order, name: name, sort_by: sort_by },
    fetch_next: fetch_next
  )
end

#update(template_id:, name: nil, form_fields: nil, request_options: {}) ⇒ Retab::EditTemplate

Update Template

Parameters:

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

    New name for the template.

  • form_fields (Array<Retab::FormField>, nil) (defaults to: nil)

    Replacement list of form fields.

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

    (see Retab::Types::RequestOptions)

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/retab/edit_templates.rb', line 120

def update(
  template_id:,
  name: nil,
  form_fields: nil,
  request_options: {}
)
  body = {
    'name' => name,
    'form_fields' => form_fields
  }.compact
  response = @client.request(
    method: :patch,
    path: "/v1/edits/templates/#{Retab::Util.encode_path(template_id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::EditTemplate.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