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
94
95
96
97
# 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)



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/retab/edit_templates.rb', line 158

def delete(
  template_id:,
  request_options: {}
)
  @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:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/retab/edit_templates.rb', line 103

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::PaginatedList<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::PaginatedList.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:



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

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