|
5 | 5 | "context"
|
6 | 6 | "fmt"
|
7 | 7 | "net/http"
|
| 8 | + "net/url" |
8 | 9 | "os"
|
9 | 10 | )
|
10 | 11 |
|
@@ -51,7 +52,10 @@ type File struct {
|
51 | 52 |
|
52 | 53 | // FilesList is a list of files that belong to the user or organization.
|
53 | 54 | type FilesList struct {
|
54 |
| - Files []File `json:"data"` |
| 55 | + Files []File `json:"data"` |
| 56 | + LastID *string `json:"last_id"` |
| 57 | + FirstID *string `json:"first_id"` |
| 58 | + HasMore bool `json:"has_more"` |
55 | 59 |
|
56 | 60 | httpHeader
|
57 | 61 | }
|
@@ -138,7 +142,33 @@ func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error) {
|
138 | 142 | // ListFiles Lists the currently available files,
|
139 | 143 | // and provides basic information about each file such as the file name and purpose.
|
140 | 144 | func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) {
|
141 |
| - req, err := c.newRequest(ctx, http.MethodGet, c.fullURL("/files")) |
| 145 | + return c.ListFilesWithOpts(ctx, nil, nil, nil) |
| 146 | +} |
| 147 | + |
| 148 | +func (c *Client) ListFilesWithOpts( |
| 149 | + ctx context.Context, |
| 150 | + limit *int, |
| 151 | + order *string, |
| 152 | + after *string, |
| 153 | +) (files FilesList, err error) { |
| 154 | + urlValues := url.Values{} |
| 155 | + if limit != nil { |
| 156 | + urlValues.Add("limit", fmt.Sprintf("%d", *limit)) |
| 157 | + } |
| 158 | + if order != nil { |
| 159 | + urlValues.Add("order", *order) |
| 160 | + } |
| 161 | + if after != nil { |
| 162 | + urlValues.Add("after", *after) |
| 163 | + } |
| 164 | + |
| 165 | + encodedValues := "" |
| 166 | + if len(urlValues) > 0 { |
| 167 | + encodedValues = "?" + urlValues.Encode() |
| 168 | + } |
| 169 | + |
| 170 | + urlSuffix := fmt.Sprintf("%s%s", "/files", encodedValues) |
| 171 | + req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix)) |
142 | 172 | if err != nil {
|
143 | 173 | return
|
144 | 174 | }
|
|
0 commit comments