Skip to content

Commit 1a688ab

Browse files
committed
Implement PaperTaskList()
1 parent 7e932eb commit 1a688ab

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

dummy/paper_task_list_response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"count":0,"next":null,"previous":null,"results":[]}

models/task.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package models
2+
3+
// Task is an object attached to a paper.
4+
type Task struct {
5+
ID string `json:"id"`
6+
Name string `json:"name"`
7+
Description string `json:"description"`
8+
}
9+
10+
type TaskList struct {
11+
Count int `json:"count"`
12+
Next *string `json:"next"`
13+
Previous *string `json:"previous"`
14+
Results []*Task `json:"results"`
15+
}

paper_task_list.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package paperswithcode_go
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/codingpot/paperswithcode-go/models"
7+
"net/url"
8+
)
9+
10+
func (c *Client) PaperTaskList(paperID string) (*models.TaskList, error) {
11+
pURL := fmt.Sprintf("%s/papers/%s/tasks/", c.BaseURL, url.QueryEscape(paperID))
12+
resp, err := c.HTTPClient.Get(pURL)
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
var taskList models.TaskList
18+
err = json.NewDecoder(resp.Body).Decode(&taskList)
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
return &taskList, nil
24+
}

paper_task_list_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package paperswithcode_go
2+
3+
import (
4+
"github.com/codingpot/paperswithcode-go/models"
5+
"github.com/stretchr/testify/assert"
6+
"testing"
7+
)
8+
9+
func TestClient_PaperTaskList(t *testing.T) {
10+
c := NewClient()
11+
got, err := c.PaperTaskList("generative-adversarial-networks")
12+
assert.NoError(t, err)
13+
14+
expected := &models.TaskList{
15+
Count: 0,
16+
Next: nil,
17+
Previous: nil,
18+
Results: []*models.Task{},
19+
}
20+
assert.Equal(t, expected, got)
21+
}

0 commit comments

Comments
 (0)