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:) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/square/api/devices_api.rb', line 84

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(device_id:) ⇒ ApiResponse

Retrieves Device with the associated ‘device_id`. desired `Device`.

Parameters:

  • device_id (String)

    Required parameter: The unique ID for the

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/square/api/devices_api.rb', line 125

def get_device(device_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/devices/{device_id}',
                                 'default')
               .template_param(new_parameter(device_id, key: 'device_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

#get_device_code(id:) ⇒ ApiResponse

Retrieves DeviceCode with the associated ID. device code.

Parameters:

  • id (String)

    Required parameter: The unique identifier for the

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/square/api/devices_api.rb', line 105

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) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/square/api/devices_api.rb', line 56

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

#list_devices(cursor: nil, sort_order: nil, limit: nil, location_id: nil) ⇒ ApiResponse

List devices associated with the merchant. Currently, only Terminal API devices are supported. a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. See [Pagination](developer.squareup.com/docs/build-basics/common-api-p atterns/pagination) for more information. results are listed. - ‘ASC` - Oldest to newest. - `DESC` - Newest to oldest (default). in a single page. devices at the target location.

Parameters:

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • sort_order (SortOrder) (defaults to: nil)

    Optional parameter: The order in which

  • limit (Integer) (defaults to: nil)

    Optional parameter: The number of results to return

  • location_id (String) (defaults to: nil)

    Optional parameter: If present, only returns

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



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

def list_devices(cursor: nil,
                 sort_order: nil,
                 limit: nil,
                 location_id: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/devices',
                                 'default')
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(sort_order, key: 'sort_order'))
               .query_param(new_parameter(limit, key: 'limit'))
               .query_param(new_parameter(location_id, key: 'location_id'))
               .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