1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iot1clickprojects
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/iot1clickprojects/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the AWS IoT 1-Click project(s) associated with your AWS account and
16// region.
17func (c *Client) ListProjects(ctx context.Context, params *ListProjectsInput, optFns ...func(*Options)) (*ListProjectsOutput, error) {
18	if params == nil {
19		params = &ListProjectsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListProjects", params, optFns, addOperationListProjectsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListProjectsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListProjectsInput struct {
33
34	// The maximum number of results to return per request. If not set, a default value
35	// of 100 is used.
36	MaxResults *int32
37
38	// The token to retrieve the next set of results.
39	NextToken *string
40}
41
42type ListProjectsOutput struct {
43
44	// An object containing the list of projects.
45	//
46	// This member is required.
47	Projects []types.ProjectSummary
48
49	// The token used to retrieve the next set of results - will be effectively empty
50	// if there are no further results.
51	NextToken *string
52
53	// Metadata pertaining to the operation's result.
54	ResultMetadata middleware.Metadata
55}
56
57func addOperationListProjectsMiddlewares(stack *middleware.Stack, options Options) (err error) {
58	err = stack.Serialize.Add(&awsRestjson1_serializeOpListProjects{}, middleware.After)
59	if err != nil {
60		return err
61	}
62	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListProjects{}, middleware.After)
63	if err != nil {
64		return err
65	}
66	if err = addSetLoggerMiddleware(stack, options); err != nil {
67		return err
68	}
69	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
70		return err
71	}
72	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
73		return err
74	}
75	if err = addResolveEndpointMiddleware(stack, options); err != nil {
76		return err
77	}
78	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
79		return err
80	}
81	if err = addRetryMiddlewares(stack, options); err != nil {
82		return err
83	}
84	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
85		return err
86	}
87	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
91		return err
92	}
93	if err = addClientUserAgent(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
97		return err
98	}
99	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
100		return err
101	}
102	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListProjects(options.Region), middleware.Before); err != nil {
103		return err
104	}
105	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
106		return err
107	}
108	if err = addResponseErrorMiddleware(stack); err != nil {
109		return err
110	}
111	if err = addRequestResponseLogging(stack, options); err != nil {
112		return err
113	}
114	return nil
115}
116
117// ListProjectsAPIClient is a client that implements the ListProjects operation.
118type ListProjectsAPIClient interface {
119	ListProjects(context.Context, *ListProjectsInput, ...func(*Options)) (*ListProjectsOutput, error)
120}
121
122var _ ListProjectsAPIClient = (*Client)(nil)
123
124// ListProjectsPaginatorOptions is the paginator options for ListProjects
125type ListProjectsPaginatorOptions struct {
126	// The maximum number of results to return per request. If not set, a default value
127	// of 100 is used.
128	Limit int32
129
130	// Set to true if pagination should stop if the service returns a pagination token
131	// that matches the most recent token provided to the service.
132	StopOnDuplicateToken bool
133}
134
135// ListProjectsPaginator is a paginator for ListProjects
136type ListProjectsPaginator struct {
137	options   ListProjectsPaginatorOptions
138	client    ListProjectsAPIClient
139	params    *ListProjectsInput
140	nextToken *string
141	firstPage bool
142}
143
144// NewListProjectsPaginator returns a new ListProjectsPaginator
145func NewListProjectsPaginator(client ListProjectsAPIClient, params *ListProjectsInput, optFns ...func(*ListProjectsPaginatorOptions)) *ListProjectsPaginator {
146	if params == nil {
147		params = &ListProjectsInput{}
148	}
149
150	options := ListProjectsPaginatorOptions{}
151	if params.MaxResults != nil {
152		options.Limit = *params.MaxResults
153	}
154
155	for _, fn := range optFns {
156		fn(&options)
157	}
158
159	return &ListProjectsPaginator{
160		options:   options,
161		client:    client,
162		params:    params,
163		firstPage: true,
164	}
165}
166
167// HasMorePages returns a boolean indicating whether more pages are available
168func (p *ListProjectsPaginator) HasMorePages() bool {
169	return p.firstPage || p.nextToken != nil
170}
171
172// NextPage retrieves the next ListProjects page.
173func (p *ListProjectsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListProjectsOutput, error) {
174	if !p.HasMorePages() {
175		return nil, fmt.Errorf("no more pages available")
176	}
177
178	params := *p.params
179	params.NextToken = p.nextToken
180
181	var limit *int32
182	if p.options.Limit > 0 {
183		limit = &p.options.Limit
184	}
185	params.MaxResults = limit
186
187	result, err := p.client.ListProjects(ctx, &params, optFns...)
188	if err != nil {
189		return nil, err
190	}
191	p.firstPage = false
192
193	prevToken := p.nextToken
194	p.nextToken = result.NextToken
195
196	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
197		p.nextToken = nil
198	}
199
200	return result, nil
201}
202
203func newServiceMetadataMiddleware_opListProjects(region string) *awsmiddleware.RegisterServiceMetadata {
204	return &awsmiddleware.RegisterServiceMetadata{
205		Region:        region,
206		ServiceID:     ServiceID,
207		SigningName:   "iot1click",
208		OperationName: "ListProjects",
209	}
210}
211