1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package frauddetector 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/frauddetector/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Gets all batch prediction jobs or a specific job if you specify a job ID. This 16// is a paginated API. If you provide a null maxResults, this action retrieves a 17// maximum of 50 records per page. If you provide a maxResults, the value must be 18// between 1 and 50. To get the next page results, provide the pagination token 19// from the GetBatchPredictionJobsResponse as part of your request. A null 20// pagination token fetches the records from the beginning. 21func (c *Client) GetBatchPredictionJobs(ctx context.Context, params *GetBatchPredictionJobsInput, optFns ...func(*Options)) (*GetBatchPredictionJobsOutput, error) { 22 if params == nil { 23 params = &GetBatchPredictionJobsInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "GetBatchPredictionJobs", params, optFns, addOperationGetBatchPredictionJobsMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*GetBatchPredictionJobsOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36type GetBatchPredictionJobsInput struct { 37 38 // The batch prediction job for which to get the details. 39 JobId *string 40 41 // The maximum number of objects to return for the request. 42 MaxResults *int32 43 44 // The next token from the previous request. 45 NextToken *string 46} 47 48type GetBatchPredictionJobsOutput struct { 49 50 // An array containing the details of each batch prediction job. 51 BatchPredictions []types.BatchPrediction 52 53 // The next token for the subsequent request. 54 NextToken *string 55 56 // Metadata pertaining to the operation's result. 57 ResultMetadata middleware.Metadata 58} 59 60func addOperationGetBatchPredictionJobsMiddlewares(stack *middleware.Stack, options Options) (err error) { 61 err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetBatchPredictionJobs{}, middleware.After) 62 if err != nil { 63 return err 64 } 65 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetBatchPredictionJobs{}, middleware.After) 66 if err != nil { 67 return err 68 } 69 if err = addSetLoggerMiddleware(stack, options); err != nil { 70 return err 71 } 72 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 73 return err 74 } 75 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 76 return err 77 } 78 if err = addResolveEndpointMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 82 return err 83 } 84 if err = addRetryMiddlewares(stack, options); err != nil { 85 return err 86 } 87 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 91 return err 92 } 93 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 94 return err 95 } 96 if err = addClientUserAgent(stack); err != nil { 97 return err 98 } 99 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 100 return err 101 } 102 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 103 return err 104 } 105 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetBatchPredictionJobs(options.Region), middleware.Before); err != nil { 106 return err 107 } 108 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 109 return err 110 } 111 if err = addResponseErrorMiddleware(stack); err != nil { 112 return err 113 } 114 if err = addRequestResponseLogging(stack, options); err != nil { 115 return err 116 } 117 return nil 118} 119 120// GetBatchPredictionJobsAPIClient is a client that implements the 121// GetBatchPredictionJobs operation. 122type GetBatchPredictionJobsAPIClient interface { 123 GetBatchPredictionJobs(context.Context, *GetBatchPredictionJobsInput, ...func(*Options)) (*GetBatchPredictionJobsOutput, error) 124} 125 126var _ GetBatchPredictionJobsAPIClient = (*Client)(nil) 127 128// GetBatchPredictionJobsPaginatorOptions is the paginator options for 129// GetBatchPredictionJobs 130type GetBatchPredictionJobsPaginatorOptions struct { 131 // The maximum number of objects to return for the request. 132 Limit int32 133 134 // Set to true if pagination should stop if the service returns a pagination token 135 // that matches the most recent token provided to the service. 136 StopOnDuplicateToken bool 137} 138 139// GetBatchPredictionJobsPaginator is a paginator for GetBatchPredictionJobs 140type GetBatchPredictionJobsPaginator struct { 141 options GetBatchPredictionJobsPaginatorOptions 142 client GetBatchPredictionJobsAPIClient 143 params *GetBatchPredictionJobsInput 144 nextToken *string 145 firstPage bool 146} 147 148// NewGetBatchPredictionJobsPaginator returns a new GetBatchPredictionJobsPaginator 149func NewGetBatchPredictionJobsPaginator(client GetBatchPredictionJobsAPIClient, params *GetBatchPredictionJobsInput, optFns ...func(*GetBatchPredictionJobsPaginatorOptions)) *GetBatchPredictionJobsPaginator { 150 if params == nil { 151 params = &GetBatchPredictionJobsInput{} 152 } 153 154 options := GetBatchPredictionJobsPaginatorOptions{} 155 if params.MaxResults != nil { 156 options.Limit = *params.MaxResults 157 } 158 159 for _, fn := range optFns { 160 fn(&options) 161 } 162 163 return &GetBatchPredictionJobsPaginator{ 164 options: options, 165 client: client, 166 params: params, 167 firstPage: true, 168 } 169} 170 171// HasMorePages returns a boolean indicating whether more pages are available 172func (p *GetBatchPredictionJobsPaginator) HasMorePages() bool { 173 return p.firstPage || p.nextToken != nil 174} 175 176// NextPage retrieves the next GetBatchPredictionJobs page. 177func (p *GetBatchPredictionJobsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetBatchPredictionJobsOutput, error) { 178 if !p.HasMorePages() { 179 return nil, fmt.Errorf("no more pages available") 180 } 181 182 params := *p.params 183 params.NextToken = p.nextToken 184 185 var limit *int32 186 if p.options.Limit > 0 { 187 limit = &p.options.Limit 188 } 189 params.MaxResults = limit 190 191 result, err := p.client.GetBatchPredictionJobs(ctx, ¶ms, optFns...) 192 if err != nil { 193 return nil, err 194 } 195 p.firstPage = false 196 197 prevToken := p.nextToken 198 p.nextToken = result.NextToken 199 200 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 201 p.nextToken = nil 202 } 203 204 return result, nil 205} 206 207func newServiceMetadataMiddleware_opGetBatchPredictionJobs(region string) *awsmiddleware.RegisterServiceMetadata { 208 return &awsmiddleware.RegisterServiceMetadata{ 209 Region: region, 210 ServiceID: ServiceID, 211 SigningName: "frauddetector", 212 OperationName: "GetBatchPredictionJobs", 213 } 214} 215