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// Lists the device event history, including device connection status, for up to 30 16// days. 17func (c *Client) ListDeviceEvents(ctx context.Context, params *ListDeviceEventsInput, optFns ...func(*Options)) (*ListDeviceEventsOutput, error) { 18 if params == nil { 19 params = &ListDeviceEventsInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListDeviceEvents", params, optFns, addOperationListDeviceEventsMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListDeviceEventsOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListDeviceEventsInput struct { 33 34 // The ARN of a device. 35 // 36 // This member is required. 37 DeviceArn *string 38 39 // The event type to filter device events. If EventType isn't specified, this 40 // returns a list of all device events in reverse chronological order. If EventType 41 // is specified, this returns a list of device events for that EventType in reverse 42 // chronological order. 43 EventType types.DeviceEventType 44 45 // The maximum number of results to include in the response. The default value is 46 // 50. If more results exist than the specified MaxResults value, a token is 47 // included in the response so that the remaining results can be retrieved. 48 MaxResults *int32 49 50 // An optional token returned from a prior request. Use this token for pagination 51 // of results from this action. If this parameter is specified, the response only 52 // includes results beyond the token, up to the value specified by MaxResults. When 53 // the end of results is reached, the response has a value of null. 54 NextToken *string 55} 56 57type ListDeviceEventsOutput struct { 58 59 // The device events requested for the device ARN. 60 DeviceEvents []types.DeviceEvent 61 62 // The token returned to indicate that there is more data available. 63 NextToken *string 64 65 // Metadata pertaining to the operation's result. 66 ResultMetadata middleware.Metadata 67} 68 69func addOperationListDeviceEventsMiddlewares(stack *middleware.Stack, options Options) (err error) { 70 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListDeviceEvents{}, middleware.After) 71 if err != nil { 72 return err 73 } 74 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListDeviceEvents{}, middleware.After) 75 if err != nil { 76 return err 77 } 78 if err = addSetLoggerMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 82 return err 83 } 84 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 85 return err 86 } 87 if err = addResolveEndpointMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 91 return err 92 } 93 if err = addRetryMiddlewares(stack, options); err != nil { 94 return err 95 } 96 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 97 return err 98 } 99 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 103 return err 104 } 105 if err = addClientUserAgent(stack); err != nil { 106 return err 107 } 108 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = addOpListDeviceEventsValidationMiddleware(stack); err != nil { 115 return err 116 } 117 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListDeviceEvents(options.Region), middleware.Before); err != nil { 118 return err 119 } 120 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addResponseErrorMiddleware(stack); err != nil { 124 return err 125 } 126 if err = addRequestResponseLogging(stack, options); err != nil { 127 return err 128 } 129 return nil 130} 131 132// ListDeviceEventsAPIClient is a client that implements the ListDeviceEvents 133// operation. 134type ListDeviceEventsAPIClient interface { 135 ListDeviceEvents(context.Context, *ListDeviceEventsInput, ...func(*Options)) (*ListDeviceEventsOutput, error) 136} 137 138var _ ListDeviceEventsAPIClient = (*Client)(nil) 139 140// ListDeviceEventsPaginatorOptions is the paginator options for ListDeviceEvents 141type ListDeviceEventsPaginatorOptions struct { 142 // The maximum number of results to include in the response. The default value is 143 // 50. If more results exist than the specified MaxResults value, a token is 144 // included in the response so that the remaining results can be retrieved. 145 Limit int32 146 147 // Set to true if pagination should stop if the service returns a pagination token 148 // that matches the most recent token provided to the service. 149 StopOnDuplicateToken bool 150} 151 152// ListDeviceEventsPaginator is a paginator for ListDeviceEvents 153type ListDeviceEventsPaginator struct { 154 options ListDeviceEventsPaginatorOptions 155 client ListDeviceEventsAPIClient 156 params *ListDeviceEventsInput 157 nextToken *string 158 firstPage bool 159} 160 161// NewListDeviceEventsPaginator returns a new ListDeviceEventsPaginator 162func NewListDeviceEventsPaginator(client ListDeviceEventsAPIClient, params *ListDeviceEventsInput, optFns ...func(*ListDeviceEventsPaginatorOptions)) *ListDeviceEventsPaginator { 163 options := ListDeviceEventsPaginatorOptions{} 164 if params.MaxResults != nil { 165 options.Limit = *params.MaxResults 166 } 167 168 for _, fn := range optFns { 169 fn(&options) 170 } 171 172 if params == nil { 173 params = &ListDeviceEventsInput{} 174 } 175 176 return &ListDeviceEventsPaginator{ 177 options: options, 178 client: client, 179 params: params, 180 firstPage: true, 181 } 182} 183 184// HasMorePages returns a boolean indicating whether more pages are available 185func (p *ListDeviceEventsPaginator) HasMorePages() bool { 186 return p.firstPage || p.nextToken != nil 187} 188 189// NextPage retrieves the next ListDeviceEvents page. 190func (p *ListDeviceEventsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListDeviceEventsOutput, error) { 191 if !p.HasMorePages() { 192 return nil, fmt.Errorf("no more pages available") 193 } 194 195 params := *p.params 196 params.NextToken = p.nextToken 197 198 var limit *int32 199 if p.options.Limit > 0 { 200 limit = &p.options.Limit 201 } 202 params.MaxResults = limit 203 204 result, err := p.client.ListDeviceEvents(ctx, ¶ms, optFns...) 205 if err != nil { 206 return nil, err 207 } 208 p.firstPage = false 209 210 prevToken := p.nextToken 211 p.nextToken = result.NextToken 212 213 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 214 p.nextToken = nil 215 } 216 217 return result, nil 218} 219 220func newServiceMetadataMiddleware_opListDeviceEvents(region string) *awsmiddleware.RegisterServiceMetadata { 221 return &awsmiddleware.RegisterServiceMetadata{ 222 Region: region, 223 ServiceID: ServiceID, 224 SigningName: "a4b", 225 OperationName: "ListDeviceEvents", 226 } 227} 228