Class: Retab::WorkflowBlocks

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ WorkflowBlocks

Returns a new instance of WorkflowBlocks.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create(workflow_id:, type:, id: nil, label: nil, position_x: nil, position_y: nil, width: nil, height: nil, config: nil, parent_id: nil, request_options: {}) ⇒ Retab::WorkflowBlock

Create Block

Parameters:

  • workflow_id (String)

    Workflow to create the block in.

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

    Opaque block ID. Omit to let the server generate one. Block IDs are unique per ORGANIZATION (not per workflow) — reusing a human-friendly id like ‘block_extract’ across multiple workflows in the same org will fail with 409. Prefer the server-generated “blk_<nanoid>“ form for predictability.

  • type (Retab::Types::WorkflowBlockCreateRequestType)

    Block type

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

    Display label

  • position_x (Float, nil) (defaults to: nil)

    X position

  • position_y (Float, nil) (defaults to: nil)

    Y position

  • width (Float, nil) (defaults to: nil)

    Block width

  • height (Float, nil) (defaults to: nil)

    Block height

  • config (Hash{String => Object}, nil) (defaults to: nil)

    Block configuration

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

    ID of parent container block (while_loop, for_each)

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

    (see Retab::Types::RequestOptions)

Returns:



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
# File 'lib/retab/workflow_blocks.rb', line 70

def create(
  workflow_id:,
  type:,
  id: nil,
  label: nil,
  position_x: nil,
  position_y: nil,
  width: nil,
  height: nil,
  config: nil,
  parent_id: nil,
  request_options: {}
)
  body = {
    'workflow_id' => workflow_id,
    'id' => id,
    'type' => type,
    'label' => label,
    'position_x' => position_x,
    'position_y' => position_y,
    'width' => width,
    'height' => height,
    'config' => config,
    'parent_id' => parent_id
  }.compact
  response = @client.request(
    method: :post,
    path: '/v1/workflows/blocks',
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::WorkflowBlock.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(block_id:, workflow_id: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Delete Block

Parameters:

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

    Optional disambiguator for legacy duplicate block IDs. See “GET /blocks/block_id“ for the full rationale.

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

    (see Retab::Types::RequestOptions)



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/retab/workflow_blocks.rb', line 189

def delete(
  block_id:,
  workflow_id: nil,
  request_options: {}
)
  params = {
    'workflow_id' => workflow_id
  }.compact
  response = @client.request(
    method: :delete,
    path: "/v1/workflows/blocks/#{Retab::Util.encode_path(block_id)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  nil
end

#get(block_id:, workflow_id: nil, request_options: {}) ⇒ Retab::WorkflowBlock

Get Block

Parameters:

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

    Optional disambiguator for legacy duplicate block IDs. Required only when the block id is not unique within the org — in that case the unqualified call returns 409 listing the colliding workflow_ids. Newly-created blocks use server-generated opaque IDs and never need this.

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

    (see Retab::Types::RequestOptions)

Returns:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/retab/workflow_blocks.rb', line 112

def get(
  block_id:,
  workflow_id: nil,
  request_options: {}
)
  params = {
    'workflow_id' => workflow_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/v1/workflows/blocks/#{Retab::Util.encode_path(block_id)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  result = Retab::WorkflowBlock.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(workflow_id:, before: nil, after: nil, limit: 100, request_options: {}) ⇒ Retab::Types::ListStruct<Retab::WorkflowBlock>

List Blocks

Parameters:

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

    Block id cursor: return the page before this id (mutually exclusive with “after“).

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

    Block id cursor: return the page after this id (mutually exclusive with “before“).

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

    Maximum number of blocks to return per page (1-200).

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

    (see Retab::Types::RequestOptions)

Returns:



20
21
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
# File 'lib/retab/workflow_blocks.rb', line 20

def list(
  workflow_id:,
  before: nil,
  after: nil,
  limit: 100,
  request_options: {}
)
  params = {
    'workflow_id' => workflow_id,
    'before' => before,
    'after' => after,
    'limit' => limit
  }.compact
  response = @client.request(
    method: :get,
    path: '/v1/workflows/blocks',
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list(
      workflow_id: workflow_id,
      before: before,
      after: cursor,
      limit: limit,
      request_options: request_options
    )
  }
  Retab::Types::ListStruct.from_response(
    response,
    model: Retab::WorkflowBlock,
    filters: { workflow_id: workflow_id, before: before, limit: limit },
    fetch_next: fetch_next
  )
end

#update(block_id:, label: nil, position_x: nil, position_y: nil, width: nil, height: nil, config: nil, parent_id: nil, config_mode: nil, workflow_id: nil, request_options: {}) ⇒ Retab::WorkflowBlock

Update Block

Parameters:

  • block_id (String)
  • label (String, nil) (defaults to: nil)
  • position_x (Float, nil) (defaults to: nil)
  • position_y (Float, nil) (defaults to: nil)
  • width (Float, nil) (defaults to: nil)
  • height (Float, nil) (defaults to: nil)
  • config (Hash{String => Object}, nil) (defaults to: nil)
  • parent_id (String, nil) (defaults to: nil)
  • config_mode (Retab::Types::UpdateWorkflowBlockRequestConfigMode, nil) (defaults to: nil)

    How to apply the “config“ field. ‘merge’ (default) deep-merges the patch into the existing config with null-as-delete; ‘replace’ uses the patch as the full new config. Not persisted.

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

    Optional disambiguator for legacy duplicate block IDs. See “GET /blocks/block_id“ for the full rationale.

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

    (see Retab::Types::RequestOptions)

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/retab/workflow_blocks.rb', line 145

def update(
  block_id:,
  label: nil,
  position_x: nil,
  position_y: nil,
  width: nil,
  height: nil,
  config: nil,
  parent_id: nil,
  config_mode: nil,
  workflow_id: nil,
  request_options: {}
)
  params = {
    'workflow_id' => workflow_id
  }.compact
  body = {
    'label' => label,
    'position_x' => position_x,
    'position_y' => position_y,
    'width' => width,
    'height' => height,
    'config' => config,
    'parent_id' => parent_id,
    'config_mode' => config_mode
  }.compact
  response = @client.request(
    method: :patch,
    path: "/v1/workflows/blocks/#{Retab::Util.encode_path(block_id)}",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = Retab::WorkflowBlock.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