-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_responses.go
45 lines (40 loc) · 1.15 KB
/
api_responses.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package metaphor
import "context"
type SearchResponse struct {
Results []struct {
ID string `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
PublishedDate string `json:"publishedDate"`
Author string `json:"author"`
Score float64 `json:"score"`
Extract string
} `json:"results"`
}
type ContentsResponse struct {
Contents []struct {
ID string `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
Extract string `json:"extract"`
} `json:"contents"`
}
type ErrorResponse struct {
Text string `json:"error"`
}
// GetContents retrieves contents for the latest search results.
//
// Parameters:
// - ctx: the context.Context for the request.
// - client: The Metaphor client used for the request.
//
// Returns:
// - *ContentsResponse: The contents response object.
// - error: An error if the contents retrieval fails.
func (response SearchResponse) GetContents(ctx context.Context, client *Client) (*ContentsResponse, error) {
ids := []string{}
for _, result := range response.Results {
ids = append(ids, result.ID)
}
return client.GetContents(ctx, ids)
}