Class: Square::LocationsApi
- Defined in:
- lib/square/api/locations_api.rb
Overview
LocationsApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#create_location(body:) ⇒ CreateLocationResponse Hash
Creates a [location](developer.squareup.com/docs/locations-api).
-
#initialize(config, http_call_back: nil) ⇒ LocationsApi
constructor
A new instance of LocationsApi.
-
#list_locations ⇒ ListLocationsResponse Hash
Provides details about all of the seller's [locations](developer.squareup.com/docs/locations-api), including those with an inactive status.
-
#retrieve_location(location_id:) ⇒ RetrieveLocationResponse Hash
Retrieves details of a single location.
-
#update_location(location_id:, body:) ⇒ UpdateLocationResponse Hash
Updates a [location](developer.squareup.com/docs/locations-api).
Methods inherited from BaseApi
#execute_request, #get_user_agent, #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](developer.squareup.com/docs/locations-api). Creating new locations allows for separate configuration of receipt layouts, item prices, and sales reports. Developers can use locations to separate sales activity through applications that integrate with Square from sales activity elsewhere in a seller's account. Locations created programmatically with the Locations API last forever and are visible to the seller for their own management. Therefore, ensure that each location has a sensible and unique name. containing the fields to POST for the request. See the corresponding object definition for field details.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/square/api/locations_api.rb', line 53 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' } # 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_locations ⇒ ListLocationsResponse Hash
Provides details about all of the seller's [locations](developer.squareup.com/docs/locations-api), including those with an inactive status.
12 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 |
# File 'lib/square/api/locations_api.rb', line 12 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 single location. Specify “main” as the location ID to retrieve details of the [main location](developer.squareup.com/docs/locations-api#about-the-main -location). retrieve. Specify the string “main” to return the main location.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/square/api/locations_api.rb', line 89 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](developer.squareup.com/docs/locations-api). update. containing the fields to POST for the request. See the corresponding object definition for field details.
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 152 153 154 155 156 157 158 159 |
# File 'lib/square/api/locations_api.rb', line 127 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' } # 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 |