Class: Square::DevicesApi
- Defined in:
- lib/square/api/devices_api.rb
Overview
DevicesApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#create_device_code(body:) ⇒ CreateDeviceCodeResponse Hash
Creates a DeviceCode that can be used to login to a Square Terminal device to enter the connected terminal mode.
-
#get_device_code(id:) ⇒ GetDeviceCodeResponse Hash
Retrieves DeviceCode with the associated ID.
-
#initialize(config, http_call_back: nil) ⇒ DevicesApi
constructor
A new instance of DevicesApi.
-
#list_device_codes(cursor: nil, location_id: nil, product_type: nil, status: nil) ⇒ ListDeviceCodesResponse Hash
Lists all DeviceCodes associated with the merchant.
Methods inherited from BaseApi
#execute_request, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ DevicesApi
Returns a new instance of DevicesApi.
4 5 6 |
# File 'lib/square/api/devices_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#create_device_code(body:) ⇒ CreateDeviceCodeResponse Hash
Creates a DeviceCode that can be used to login to a Square Terminal device to enter the connected terminal mode. containing the fields to POST for the request. See the corresponding object definition for field details.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/square/api/devices_api.rb', line 68 def create_device_code(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/devices/codes' _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 |
#get_device_code(id:) ⇒ GetDeviceCodeResponse Hash
Retrieves DeviceCode with the associated ID. device code.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/square/api/devices_api.rb', line 101 def get_device_code(id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/devices/codes/{id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'id' => { 'value' => 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 |
#list_device_codes(cursor: nil, location_id: nil, product_type: nil, status: nil) ⇒ ListDeviceCodesResponse Hash
Lists all DeviceCodes associated with the merchant. a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See [Paginating results](developer.squareup.com/docs/working-with-apis/pagination) for more information. DeviceCodes of the specified location. Returns DeviceCodes of all locations if empty. returns DeviceCodes targeting the specified product type. Returns DeviceCodes of all product types if empty. DeviceCodes with the specified statuses. Returns DeviceCodes of status `PAIRED` and `UNPAIRED` if empty.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/square/api/devices_api.rb', line 24 def list_device_codes(cursor: nil, location_id: nil, product_type: nil, status: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/devices/codes' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'cursor' => cursor, 'location_id' => location_id, 'product_type' => product_type, 'status' => status ) _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 |