Class: Square::LocationsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/locations_api.rb

Overview

LocationsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #validate_parameters

Constructor Details

#initialize(config, http_call_back: nil) ⇒ LocationsApi

Returns a new instance of LocationsApi.



4
5
6
# File 'lib/square/api/locations_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#create_location(body:) ⇒ CreateLocationResponse Hash

Creates a location. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateLocationRequest)

    Required parameter: An object

Returns:

  • (CreateLocationResponse Hash)

    response from the API call



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/square/api/locations_api.rb', line 45

def create_location(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/locations'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_locationsListLocationsResponse Hash

Provides information of all locations of a business. Many Square API endpoints require a `location_id` parameter. The `id` field of the [`Location`]($m/Location) objects returned by this endpoint correspond to that `location_id` parameter.

Returns:

  • (ListLocationsResponse Hash)

    response from the API call



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/square/api/locations_api.rb', line 13

def list_locations
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/locations'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_location(location_id:) ⇒ RetrieveLocationResponse Hash

Retrieves details of a location. You can specify “main” as the location ID to retrieve details of the main location. retrieve. If you specify the string “main”, then the endpoint returns the main location.

Parameters:

  • location_id (String)

    Required parameter: The ID of the location to

Returns:

  • (RetrieveLocationResponse Hash)

    response from the API call



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
106
107
108
109
110
# File 'lib/square/api/locations_api.rb', line 81

def retrieve_location(location_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/locations/{location_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'location_id' => { 'value' => location_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#update_location(location_id:, body:) ⇒ UpdateLocationResponse Hash

Updates a location. update. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • location_id (String)

    Required parameter: The ID of the location to

  • body (UpdateLocationRequest)

    Required parameter: An object

Returns:

  • (UpdateLocationResponse Hash)

    response from the API call



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/square/api/locations_api.rb', line 119

def update_location(location_id:,
                    body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/locations/{location_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'location_id' => { 'value' => location_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end