Class: Square::Labor::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/labor/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/square/labor/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#break_typesSquare::BreakTypes::Client

Returns:

  • (Square::BreakTypes::Client)


462
463
464
# File 'lib/square/labor/client.rb', line 462

def break_types
  @break_types ||= Square::Labor::BreakTypes::Client.new(client: @client)
end

#bulk_publish_scheduled_shifts(request_options: {}, **params) ⇒ Square::Types::BulkPublishScheduledShiftsResponse

Publishes 1 - 100 scheduled shifts. This endpoint takes a map of individual publish requests and returns a map of responses. When a scheduled shift is published, Square keeps the ‘draft_shift_details` field as is and copies it to the `published_shift_details` field.

The minimum ‘start_at` and maximum `end_at` timestamps of all shifts in a `BulkPublishScheduledShifts` request must fall within a two-week period.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/square/labor/client.rb', line 70

def bulk_publish_scheduled_shifts(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/labor/scheduled-shifts/bulk-publish",
    body: Square::Labor::Types::BulkPublishScheduledShiftsRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::BulkPublishScheduledShiftsResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_scheduled_shift(request_options: {}, **params) ⇒ Square::Types::CreateScheduledShiftResponse

Creates a scheduled shift by providing draft shift details such as job ID, team member assignment, and start and end times.

The following ‘draft_shift_details` fields are required:

  • ‘location_id`

  • ‘job_id`

  • ‘start_at`

  • ‘end_at`

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/square/labor/client.rb', line 31

def create_scheduled_shift(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/labor/scheduled-shifts",
    body: Square::Labor::Types::CreateScheduledShiftRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::CreateScheduledShiftResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_timecard(request_options: {}, **params) ⇒ Square::Types::CreateTimecardResponse

Creates a new ‘Timecard`.

A ‘Timecard` represents a complete workday for a single team member. You must provide the following values in your request to this endpoint:

  • ‘location_id`

  • ‘team_member_id`

  • ‘start_at`

An attempt to create a new ‘Timecard` can result in a `BAD_REQUEST` error when:

  • The ‘status` of the new `Timecard` is `OPEN` and the team member has another

timecard with an ‘OPEN` status.

  • The ‘start_at` date is in the future.

  • The ‘start_at` or `end_at` date overlaps another timecard for the same team member.

  • The ‘Break` instances are set in the request and a break `start_at`

is before the ‘Timecard.start_at`, a break `end_at` is after the `Timecard.end_at`, or both.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/square/labor/client.rb', line 278

def create_timecard(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/labor/timecards",
    body: Square::Labor::Types::CreateTimecardRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::CreateTimecardResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_timecard(request_options: {}, **params) ⇒ Square::Types::DeleteTimecardResponse

Deletes a ‘Timecard`.

Parameters:

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

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/square/labor/client.rb', line 439

def delete_timecard(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "v2/labor/timecards/#{params[:id]}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::DeleteTimecardResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#employee_wagesSquare::EmployeeWages::Client

Returns:

  • (Square::EmployeeWages::Client)


467
468
469
# File 'lib/square/labor/client.rb', line 467

def employee_wages
  @employee_wages ||= Square::Labor::EmployeeWages::Client.new(client: @client)
end

#publish_scheduled_shift(request_options: {}, **params) ⇒ Square::Types::PublishScheduledShiftResponse

Publishes a scheduled shift. When a scheduled shift is published, Square keeps the ‘draft_shift_details` field as is and copies it to the `published_shift_details` field.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/square/labor/client.rb', line 223

def publish_scheduled_shift(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request_data = Square::Labor::Types::PublishScheduledShiftRequest.new(params).to_h
  non_body_param_names = ["id"]
  body = request_data.except(*non_body_param_names)

  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/labor/scheduled-shifts/#{params[:id]}/publish",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::PublishScheduledShiftResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#retrieve_scheduled_shift(request_options: {}, **params) ⇒ Square::Types::RetrieveScheduledShiftResponse

Retrieves a scheduled shift by ID.

Parameters:

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

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/square/labor/client.rb', line 140

def retrieve_scheduled_shift(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/labor/scheduled-shifts/#{params[:id]}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::RetrieveScheduledShiftResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#retrieve_timecard(request_options: {}, **params) ⇒ Square::Types::RetrieveTimecardResponse

Returns a single ‘Timecard` specified by `id`.

Parameters:

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

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/square/labor/client.rb', line 360

def retrieve_timecard(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/labor/timecards/#{params[:id]}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::RetrieveTimecardResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#search_scheduled_shifts(request_options: {}, **params) ⇒ Square::Types::SearchScheduledShiftsResponse

Returns a paginated list of scheduled shifts, with optional filter and sort settings. By default, results are sorted by ‘start_at` in ascending order.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/square/labor/client.rb', line 105

def search_scheduled_shifts(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/labor/scheduled-shifts/search",
    body: Square::Labor::Types::SearchScheduledShiftsRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::SearchScheduledShiftsResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#search_timecards(request_options: {}, **params) ⇒ Square::Types::SearchTimecardsResponse

Returns a paginated list of ‘Timecard` records for a business. The list to be returned can be filtered by:

  • Location IDs

  • Team member IDs

  • Timecard status (‘OPEN` or `CLOSED`)

  • Timecard start

  • Timecard end

  • Workday details

The list can be sorted by:

  • ‘START_AT`

  • ‘END_AT`

  • ‘CREATED_AT`

  • ‘UPDATED_AT`

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/square/labor/client.rb', line 325

def search_timecards(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/labor/timecards/search",
    body: Square::Labor::Types::SearchTimecardsRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::SearchTimecardsResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#shiftsSquare::Shifts::Client

Returns:

  • (Square::Shifts::Client)


472
473
474
# File 'lib/square/labor/client.rb', line 472

def shifts
  @shifts ||= Square::Labor::Shifts::Client.new(client: @client)
end

#team_member_wagesSquare::TeamMemberWages::Client

Returns:

  • (Square::TeamMemberWages::Client)


477
478
479
# File 'lib/square/labor/client.rb', line 477

def team_member_wages
  @team_member_wages ||= Square::Labor::TeamMemberWages::Client.new(client: @client)
end

#update_scheduled_shift(request_options: {}, **params) ⇒ Square::Types::UpdateScheduledShiftResponse

Updates the draft shift details for a scheduled shift. This endpoint supports sparse updates, so only new, changed, or removed fields are required in the request. You must publish the shift to make updates public.

You can make the following updates to ‘draft_shift_details`:

  • Change the ‘location_id`, `job_id`, `start_at`, and `end_at` fields.

  • Add, change, or clear the ‘team_member_id` and `notes` fields. To clear these fields,

set the value to null.

  • Change the ‘is_deleted` field. To delete a scheduled shift, set `is_deleted` to true

and then publish the shift.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/square/labor/client.rb', line 183

def update_scheduled_shift(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request_data = Square::Labor::Types::UpdateScheduledShiftRequest.new(params).to_h
  non_body_param_names = ["id"]
  body = request_data.except(*non_body_param_names)

  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "v2/labor/scheduled-shifts/#{params[:id]}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::UpdateScheduledShiftResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_timecard(request_options: {}, **params) ⇒ Square::Types::UpdateTimecardResponse

Updates an existing ‘Timecard`.

When adding a ‘Break` to a `Timecard`, any earlier `Break` instances in the `Timecard` have the `end_at` property set to a valid RFC-3339 datetime string.

When closing a ‘Timecard`, all `Break` instances in the `Timecard` must be complete with `end_at` set on each `Break`.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/square/labor/client.rb', line 400

def update_timecard(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request_data = Square::Labor::Types::UpdateTimecardRequest.new(params).to_h
  non_body_param_names = ["id"]
  body = request_data.except(*non_body_param_names)

  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "v2/labor/timecards/#{params[:id]}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Square::Types::UpdateTimecardResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#workweek_configsSquare::WorkweekConfigs::Client

Returns:

  • (Square::WorkweekConfigs::Client)


482
483
484
# File 'lib/square/labor/client.rb', line 482

def workweek_configs
  @workweek_configs ||= Square::Labor::WorkweekConfigs::Client.new(client: @client)
end