1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package alexaforbusiness 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/alexaforbusiness/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Searches devices and lists the ones that meet a set of filter criteria. 16func (c *Client) SearchDevices(ctx context.Context, params *SearchDevicesInput, optFns ...func(*Options)) (*SearchDevicesOutput, error) { 17 if params == nil { 18 params = &SearchDevicesInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "SearchDevices", params, optFns, addOperationSearchDevicesMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*SearchDevicesOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type SearchDevicesInput struct { 32 33 // The filters to use to list a specified set of devices. Supported filter keys are 34 // DeviceName, DeviceStatus, DeviceStatusDetailCode, RoomName, DeviceType, 35 // DeviceSerialNumber, UnassociatedOnly, ConnectionStatus (ONLINE and OFFLINE), 36 // NetworkProfileName, NetworkProfileArn, Feature, and FailureCode. 37 Filters []types.Filter 38 39 // The maximum number of results to include in the response. If more results exist 40 // than the specified MaxResults value, a token is included in the response so that 41 // the remaining results can be retrieved. 42 MaxResults *int32 43 44 // An optional token returned from a prior request. Use this token for pagination 45 // of results from this action. If this parameter is specified, the response 46 // includes only results beyond the token, up to the value specified by MaxResults. 47 NextToken *string 48 49 // The sort order to use in listing the specified set of devices. Supported sort 50 // keys are DeviceName, DeviceStatus, RoomName, DeviceType, DeviceSerialNumber, 51 // ConnectionStatus, NetworkProfileName, NetworkProfileArn, Feature, and 52 // FailureCode. 53 SortCriteria []types.Sort 54} 55 56type SearchDevicesOutput struct { 57 58 // The devices that meet the specified set of filter criteria, in sort order. 59 Devices []types.DeviceData 60 61 // The token returned to indicate that there is more data available. 62 NextToken *string 63 64 // The total number of devices returned. 65 TotalCount *int32 66 67 // Metadata pertaining to the operation's result. 68 ResultMetadata middleware.Metadata 69} 70 71func addOperationSearchDevicesMiddlewares(stack *middleware.Stack, options Options) (err error) { 72 err = stack.Serialize.Add(&awsAwsjson11_serializeOpSearchDevices{}, middleware.After) 73 if err != nil { 74 return err 75 } 76 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpSearchDevices{}, middleware.After) 77 if err != nil { 78 return err 79 } 80 if err = addSetLoggerMiddleware(stack, options); err != nil { 81 return err 82 } 83 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 84 return err 85 } 86 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 87 return err 88 } 89 if err = addResolveEndpointMiddleware(stack, options); err != nil { 90 return err 91 } 92 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 93 return err 94 } 95 if err = addRetryMiddlewares(stack, options); err != nil { 96 return err 97 } 98 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 102 return err 103 } 104 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 105 return err 106 } 107 if err = addClientUserAgent(stack); err != nil { 108 return err 109 } 110 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 111 return err 112 } 113 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 114 return err 115 } 116 if err = addOpSearchDevicesValidationMiddleware(stack); err != nil { 117 return err 118 } 119 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearchDevices(options.Region), middleware.Before); err != nil { 120 return err 121 } 122 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addResponseErrorMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addRequestResponseLogging(stack, options); err != nil { 129 return err 130 } 131 return nil 132} 133 134// SearchDevicesAPIClient is a client that implements the SearchDevices operation. 135type SearchDevicesAPIClient interface { 136 SearchDevices(context.Context, *SearchDevicesInput, ...func(*Options)) (*SearchDevicesOutput, error) 137} 138 139var _ SearchDevicesAPIClient = (*Client)(nil) 140 141// SearchDevicesPaginatorOptions is the paginator options for SearchDevices 142type SearchDevicesPaginatorOptions struct { 143 // The maximum number of results to include in the response. If more results exist 144 // than the specified MaxResults value, a token is included in the response so that 145 // the remaining results can be retrieved. 146 Limit int32 147 148 // Set to true if pagination should stop if the service returns a pagination token 149 // that matches the most recent token provided to the service. 150 StopOnDuplicateToken bool 151} 152 153// SearchDevicesPaginator is a paginator for SearchDevices 154type SearchDevicesPaginator struct { 155 options SearchDevicesPaginatorOptions 156 client SearchDevicesAPIClient 157 params *SearchDevicesInput 158 nextToken *string 159 firstPage bool 160} 161 162// NewSearchDevicesPaginator returns a new SearchDevicesPaginator 163func NewSearchDevicesPaginator(client SearchDevicesAPIClient, params *SearchDevicesInput, optFns ...func(*SearchDevicesPaginatorOptions)) *SearchDevicesPaginator { 164 options := SearchDevicesPaginatorOptions{} 165 if params.MaxResults != nil { 166 options.Limit = *params.MaxResults 167 } 168 169 for _, fn := range optFns { 170 fn(&options) 171 } 172 173 if params == nil { 174 params = &SearchDevicesInput{} 175 } 176 177 return &SearchDevicesPaginator{ 178 options: options, 179 client: client, 180 params: params, 181 firstPage: true, 182 } 183} 184 185// HasMorePages returns a boolean indicating whether more pages are available 186func (p *SearchDevicesPaginator) HasMorePages() bool { 187 return p.firstPage || p.nextToken != nil 188} 189 190// NextPage retrieves the next SearchDevices page. 191func (p *SearchDevicesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchDevicesOutput, error) { 192 if !p.HasMorePages() { 193 return nil, fmt.Errorf("no more pages available") 194 } 195 196 params := *p.params 197 params.NextToken = p.nextToken 198 199 var limit *int32 200 if p.options.Limit > 0 { 201 limit = &p.options.Limit 202 } 203 params.MaxResults = limit 204 205 result, err := p.client.SearchDevices(ctx, ¶ms, optFns...) 206 if err != nil { 207 return nil, err 208 } 209 p.firstPage = false 210 211 prevToken := p.nextToken 212 p.nextToken = result.NextToken 213 214 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 215 p.nextToken = nil 216 } 217 218 return result, nil 219} 220 221func newServiceMetadataMiddleware_opSearchDevices(region string) *awsmiddleware.RegisterServiceMetadata { 222 return &awsmiddleware.RegisterServiceMetadata{ 223 Region: region, 224 ServiceID: ServiceID, 225 SigningName: "a4b", 226 OperationName: "SearchDevices", 227 } 228} 229