Class: Square::Labor::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Labor::Client



7
8
9
# File 'lib/square/labor/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#break_typesSquare::BreakTypes::Client

Returns:

  • (Square::BreakTypes::Client)


338
339
340
# File 'lib/square/labor/client.rb', line 338

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.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/square/labor/client.rb', line 50

def bulk_publish_scheduled_shifts(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/labor/scheduled-shifts/bulk-publish",
    body: params
  )
  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`



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/square/labor/client.rb', line 21

def create_scheduled_shift(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/labor/scheduled-shifts",
    body: params
  )
  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.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/square/labor/client.rb', line 201

def create_timecard(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/labor/timecards",
    body: params
  )
  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`.



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/square/labor/client.rb', line 317

def delete_timecard(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "DELETE",
    path: "v2/labor/timecards/#{params[:id]}"
  )
  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)


343
344
345
# File 'lib/square/labor/client.rb', line 343

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.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/square/labor/client.rb', line 158

def publish_scheduled_shift(request_options: {}, **params)
  _path_param_names = ["id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/labor/scheduled-shifts/#{params[:id]}/publish",
    body: params.except(*_path_param_names)
  )
  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.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/square/labor/client.rb', line 99

def retrieve_scheduled_shift(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/labor/scheduled-shifts/#{params[:id]}"
  )
  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`.



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/square/labor/client.rb', line 262

def retrieve_timecard(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/labor/timecards/#{params[:id]}"
  )
  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.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/square/labor/client.rb', line 75

def search_scheduled_shifts(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/labor/scheduled-shifts/search",
    body: params
  )
  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`



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/square/labor/client.rb', line 238

def search_timecards(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/labor/timecards/search",
    body: params
  )
  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)


348
349
350
# File 'lib/square/labor/client.rb', line 348

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

#team_member_wagesSquare::TeamMemberWages::Client

Returns:

  • (Square::TeamMemberWages::Client)


353
354
355
# File 'lib/square/labor/client.rb', line 353

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.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/square/labor/client.rb', line 131

def update_scheduled_shift(request_options: {}, **params)
  _path_param_names = ["id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "PUT",
    path: "v2/labor/scheduled-shifts/#{params[:id]}",
    body: params.except(*_path_param_names)
  )
  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`.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/square/labor/client.rb', line 291

def update_timecard(request_options: {}, **params)
  _path_param_names = ["id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "PUT",
    path: "v2/labor/timecards/#{params[:id]}",
    body: params.except(*_path_param_names)
  )
  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)


358
359
360
# File 'lib/square/labor/client.rb', line 358

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