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)


272
273
274
# File 'lib/square/labor/client.rb', line 272

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.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/square/labor/client.rb', line 44

def bulk_publish_scheduled_shifts(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/labor/scheduled-shifts/bulk-publish",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::BulkPublishScheduledShiftsResponse.load(_response.body)
  end

  raise _response.body
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
# 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::SANDBOX,
    method: "POST",
    path: "v2/labor/scheduled-shifts",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::CreateScheduledShiftResponse.load(_response.body)
  end

  raise _response.body
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.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/square/labor/client.rb', line 165

def create_timecard(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/labor/timecards",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::CreateTimecardResponse.load(_response.body)
  end

  raise _response.body
end

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

Deletes a ‘Timecard`.



257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/square/labor/client.rb', line 257

def delete_timecard(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "DELETE",
    path: "v2/labor/timecards/#{params[:id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::DeleteTimecardResponse.load(_response.body)
  end

  raise _response.body
end

#employee_wagesSquare::EmployeeWages::Client

Returns:

  • (Square::EmployeeWages::Client)


277
278
279
# File 'lib/square/labor/client.rb', line 277

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.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/square/labor/client.rb', line 128

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::SANDBOX,
    method: "POST",
    path: "v2/labor/scheduled-shifts/#{params[:id]}/publish",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::PublishScheduledShiftResponse.load(_response.body)
  end

  raise _response.body
end

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

Retrieves a scheduled shift by ID.



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/square/labor/client.rb', line 81

def retrieve_scheduled_shift(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/labor/scheduled-shifts/#{params[:id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::RetrieveScheduledShiftResponse.load(_response.body)
  end

  raise _response.body
end

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

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



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/square/labor/client.rb', line 214

def retrieve_timecard(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/labor/timecards/#{params[:id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::RetrieveTimecardResponse.load(_response.body)
  end

  raise _response.body
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.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/square/labor/client.rb', line 63

def search_scheduled_shifts(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/labor/scheduled-shifts/search",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::SearchScheduledShiftsResponse.load(_response.body)
  end

  raise _response.body
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`



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/square/labor/client.rb', line 196

def search_timecards(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/labor/timecards/search",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::SearchTimecardsResponse.load(_response.body)
  end

  raise _response.body
end

#shiftsSquare::Shifts::Client

Returns:

  • (Square::Shifts::Client)


282
283
284
# File 'lib/square/labor/client.rb', line 282

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

#team_member_wagesSquare::TeamMemberWages::Client

Returns:

  • (Square::TeamMemberWages::Client)


287
288
289
# File 'lib/square/labor/client.rb', line 287

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.



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

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::SANDBOX,
    method: "PUT",
    path: "v2/labor/scheduled-shifts/#{params[:id]}",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::UpdateScheduledShiftResponse.load(_response.body)
  end

  raise _response.body
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`.



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

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

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "PUT",
    path: "v2/labor/timecards/#{params[:id]}",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::UpdateTimecardResponse.load(_response.body)
  end

  raise _response.body
end

#workweek_configsSquare::WorkweekConfigs::Client

Returns:

  • (Square::WorkweekConfigs::Client)


292
293
294
# File 'lib/square/labor/client.rb', line 292

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