-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaper_list.go
55 lines (47 loc) · 1.35 KB
/
paper_list.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
46
47
48
49
50
51
52
53
54
55
package paperswithcode_go
import (
"github.com/codingpot/paperswithcode-go/v2/models"
"net/url"
"strconv"
)
// PaperList returns multiple papers.
func (c *Client) PaperList(params PaperListParams) (models.PaperList, error) {
papersListURL := c.baseURL + "/papers?" + params.Build()
return getJson[models.PaperList](c, papersListURL)
}
// PaperListParams is the parameter for PaperList method.
type PaperListParams struct {
// Q to search papers (default: "")
// If empty, it returns all papers.
Q string
ArxivID string
Title string
Abstract string
// Page is the number of page to search (default: 1)
Page int
// ItemsPerPage returns how many papers are returned in a single response.
ItemsPerPage int
}
func (p PaperListParams) Build() string {
b := url.Values{}
b.Set("page", strconv.Itoa(p.Page))
b.Set("items_per_page", strconv.Itoa(p.ItemsPerPage))
addParamsIfValid(b, "q", p.Q)
addParamsIfValid(b, "arxiv_id", p.ArxivID)
addParamsIfValid(b, "title", p.Title)
addParamsIfValid(b, "abstract", p.Abstract)
return b.Encode()
}
func addParamsIfValid(b url.Values, key string, value string) {
if value != "" {
b.Set(key, value)
}
}
// PaperListParamsDefault returns the default PaperListParams.
func PaperListParamsDefault() PaperListParams {
return PaperListParams{
Q: "",
Page: 1,
ItemsPerPage: 50,
}
}