Class: Square::DevicesApi

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

Overview

DevicesApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from Square::BaseApi

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.

Parameters:

  • body (CreateDeviceCodeRequest)

    Required parameter: An object

Returns:

  • (CreateDeviceCodeResponse Hash)

    response from the API call



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/square/api/devices_api.rb', line 48

def create_device_code(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/devices/codes',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#get_device_code(id:) ⇒ GetDeviceCodeResponse Hash

Retrieves DeviceCode with the associated ID. device code.

Parameters:

  • id (String)

    Required parameter: The unique identifier for the

Returns:

  • (GetDeviceCodeResponse Hash)

    response from the API call



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/square/api/devices_api.rb', line 69

def get_device_code(id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/devices/codes/{id}',
                                 'default')
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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.

Parameters:

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • location_id (String) (defaults to: nil)

    Optional parameter: If specified, only returns

  • product_type (ProductType) (defaults to: nil)

    Optional parameter: If specified, only

  • status (DeviceCodeStatus) (defaults to: nil)

    Optional parameter: If specified, returns

Returns:

  • (ListDeviceCodesResponse Hash)

    response from the API call



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/square/api/devices_api.rb', line 20

def list_device_codes(cursor: nil,
                      location_id: nil,
                      product_type: nil,
                      status: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/devices/codes',
                                 'default')
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(location_id, key: 'location_id'))
               .query_param(new_parameter(product_type, key: 'product_type'))
               .query_param(new_parameter(status, key: 'status'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end