Class: Square::Labor::BreakTypes::Client

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

Instance Method Summary collapse

Constructor Details

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



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

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Square::Types::CreateBreakTypeResponse

Creates a new ‘BreakType`.

A ‘BreakType` is a template for creating `Break` objects. You must provide the following values in your request to this endpoint:

  • ‘location_id`

  • ‘break_name`

  • ‘expected_duration`

  • ‘is_paid`

You can only have three ‘BreakType` instances per location. If you attempt to add a fourth `BreakType` for a location, an `INVALID_REQUEST_ERROR` “Exceeded limit of 3 breaks per location.” is returned.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/square/labor/break_types/client.rb', line 50

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

  raise _response.body
end

#delete(request_options: {}, **params) ⇒ Square::Types::DeleteBreakTypeResponse

Deletes an existing ‘BreakType`.

A ‘BreakType` can be deleted even if it is referenced from a `Shift`.



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

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

  raise _response.body
end

#get(request_options: {}, **params) ⇒ Square::Types::GetBreakTypeResponse

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



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/square/labor/break_types/client.rb', line 68

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

  raise _response.body
end

#list(request_options: {}, **params) ⇒ Square::Types::ListBreakTypesResponse

Returns a paginated list of ‘BreakType` instances for a business.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/square/labor/break_types/client.rb', line 15

def list(request_options: {}, **params)
  _query_param_names = %w[location_id limit cursor]
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/labor/break-types",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::ListBreakTypesResponse.load(_response.body)
  end

  raise _response.body
end

#update(request_options: {}, **params) ⇒ Square::Types::UpdateBreakTypeResponse

Updates an existing ‘BreakType`.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/square/labor/break_types/client.rb', line 85

def update(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/break-types/#{params[:id]}",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::UpdateBreakTypeResponse.load(_response.body)
  end

  raise _response.body
end