Skip to content

Commit

Permalink
Update docs, examples, tests and democlient (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
nstratos authored Mar 29, 2023
1 parent 92740b3 commit 23294af
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ count.out
cover.out
*token-cache.txt
*.exe
malauth
!malauth/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ _, _, err := c.Anime.UpdateMyListStatus(ctx, 967,
mal.NumEpisodesWatched(73),
mal.Score(8),
mal.Comments("You wa shock!"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
// ...

Expand All @@ -315,6 +317,8 @@ _, _, err := c.Manga.UpdateMyListStatus(ctx, 401,
mal.NumVolumesRead(1),
mal.NumChaptersRead(5),
mal.Comments("Migi"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
// ...
```
Expand Down
9 changes: 7 additions & 2 deletions example/malauth/democlient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/nstratos/go-myanimelist/mal"
)
Expand Down Expand Up @@ -261,12 +262,14 @@ func (c *demoClient) updateMyAnimeListStatus(ctx context.Context) {
mal.NumEpisodesWatched(73),
mal.Score(8),
mal.Comments("You wa shock!"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
if err != nil {
c.err = err
return
}
fmt.Printf("Status: %q, Score: %d, Episodes Watched: %d, Comments: %s\n", s.Status, s.Score, s.NumEpisodesWatched, s.Comments)
fmt.Printf("Status: %q, Score: %d, Episodes Watched: %d, Comments: %q, Start Date: %s\n", s.Status, s.Score, s.NumEpisodesWatched, s.Comments, s.StartDate)
}

func (c *demoClient) updateMyMangaListStatus(ctx context.Context) {
Expand All @@ -278,12 +281,14 @@ func (c *demoClient) updateMyMangaListStatus(ctx context.Context) {
mal.NumVolumesRead(1),
mal.NumChaptersRead(5),
mal.Comments("Migi"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
if err != nil {
c.err = err
return
}
fmt.Printf("Status: %q, Volumes Read: %d, Chapters Read: %d, Comments: %s\n", s.Status, s.NumVolumesRead, s.NumChaptersRead, s.Comments)
fmt.Printf("Status: %q, Volumes Read: %d, Chapters Read: %d, Comments: %q, Start Date: %s\n", s.Status, s.NumVolumesRead, s.NumChaptersRead, s.Comments, s.StartDate)
}

func (c *demoClient) deleteMyAnimeListItem(ctx context.Context) {
Expand Down
4 changes: 4 additions & 0 deletions mal/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ manga ID and then options to specify the status, score, comments, tags etc.
mal.NumEpisodesWatched(73),
mal.Score(8),
mal.Comments("You wa shock!"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
// ...
Expand All @@ -281,6 +283,8 @@ manga ID and then options to specify the status, score, comments, tags etc.
mal.NumVolumesRead(1),
mal.NumChaptersRead(5),
mal.Comments("Migi"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
// ...
Expand Down
7 changes: 5 additions & 2 deletions mal/example_useranimelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"time"

"github.com/nstratos/go-myanimelist/mal"
)
Expand Down Expand Up @@ -55,12 +56,14 @@ func ExampleAnimeService_UpdateMyListStatus() {
mal.NumEpisodesWatched(73),
mal.Score(8),
mal.Comments("You wa shock!"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
if err != nil {
fmt.Printf("Anime.UpdateMyListStatus error: %v", err)
return
}
fmt.Printf("Status: %q, Score: %d, Episodes Watched: %d, Comments: %s\n", s.Status, s.Score, s.NumEpisodesWatched, s.Comments)
fmt.Printf("Status: %q, Score: %d, Episodes Watched: %d, Comments: %q, Start Date: %s\n", s.Status, s.Score, s.NumEpisodesWatched, s.Comments, s.StartDate)
// Output:
// Status: "watching", Score: 8, Episodes Watched: 73, Comments: You wa shock!
// Status: "watching", Score: 8, Episodes Watched: 73, Comments: "You wa shock!", Start Date: 2022-02-20
}
7 changes: 5 additions & 2 deletions mal/example_usermangalist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"time"

"github.com/nstratos/go-myanimelist/mal"
)
Expand Down Expand Up @@ -52,12 +53,14 @@ func ExampleMangaService_UpdateMyListStatus() {
mal.NumVolumesRead(1),
mal.NumChaptersRead(5),
mal.Comments("Migi"),
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}), // Remove an existing date.
)
if err != nil {
fmt.Printf("Manga.UpdateMyListStatus error: %v", err)
return
}
fmt.Printf("Status: %q, Volumes Read: %d, Chapters Read: %d, Comments: %s\n", s.Status, s.NumVolumesRead, s.NumChaptersRead, s.Comments)
fmt.Printf("Status: %q, Volumes Read: %d, Chapters Read: %d, Comments: %q, Start Date: %s\n", s.Status, s.NumVolumesRead, s.NumChaptersRead, s.Comments, s.StartDate)
// Output:
// Status: "reading", Volumes Read: 1, Chapters Read: 5, Comments: Migi
// Status: "reading", Volumes Read: 1, Chapters Read: 5, Comments: "Migi", Start Date: 2022-02-20
}
8 changes: 8 additions & 0 deletions mal/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func testUpdateUserAnimeList(ctx context.Context, t *testing.T, client *mal.Clie
mal.RewatchValue(1),
mal.Score(1),
mal.Tags{"foo", "bar"},
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}),
); err != nil {
t.Fatalf("Anime.UpdateMyListStatus(%d) returned err: %v", id, err)
}
Expand Down Expand Up @@ -157,6 +159,8 @@ func testUpdateUserAnimeList(ctx context.Context, t *testing.T, client *mal.Clie
RewatchValue: 1,
Tags: []string{"foo", "bar"},
Comments: "test comment",
StartDate: "2022-02-20",
FinishDate: "",
}
a.Status.UpdatedAt = time.Time{}
if got := a.Status; !reflect.DeepEqual(got, want) {
Expand Down Expand Up @@ -201,6 +205,8 @@ func testUpdateUserMangaList(ctx context.Context, t *testing.T, client *mal.Clie
mal.RereadValue(1),
mal.Score(1),
mal.Tags{"foo", "bar"},
mal.StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
mal.FinishDate(time.Time{}),
); err != nil {
t.Fatalf("Manga.UpdateMyListStatus(%d) returned err: %v", id, err)
}
Expand Down Expand Up @@ -232,6 +238,8 @@ func testUpdateUserMangaList(ctx context.Context, t *testing.T, client *mal.Clie
RereadValue: 1,
Tags: []string{"foo", "bar"},
Comments: "test comment",
StartDate: "2022-02-20",
FinishDate: "",
}
a.Status.UpdatedAt = time.Time{}
if got := a.Status; !reflect.DeepEqual(got, want) {
Expand Down
1 change: 1 addition & 0 deletions mal/testdata/updateMyAnimeList.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"num_episodes_watched":73,
"is_rewatching":false,
"updated_at":"2021-03-16T07:36:44+00:00",
"start_date":"2022-02-20",
"priority":0,
"num_times_rewatched":0,
"rewatch_value":0,
Expand Down
1 change: 1 addition & 0 deletions mal/testdata/updateMyMangaList.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"num_chapters_read":5,
"score":0,
"updated_at":"2021-03-22T18:15:09+00:00",
"start_date":"2022-02-20",
"priority":0,
"num_times_reread":0,
"reread_value":0,
Expand Down
2 changes: 2 additions & 0 deletions mal/usermangalist.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type MangaListStatus struct {
RereadValue int `json:"reread_value"`
Tags []string `json:"tags"`
Comments string `json:"comments"`
StartDate string `json:"start_date"`
FinishDate string `json:"finish_date"`
}

// mangaList represents the anime list of a user.
Expand Down
7 changes: 6 additions & 1 deletion mal/usermangalist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestMangaServiceUpdateMyListStatus(t *testing.T) {
mux.HandleFunc("/manga/1/my_list_status", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
testContentType(t, r, "application/x-www-form-urlencoded")
testBody(t, r, "comments=comments&is_rereading=true&num_chapters_read=3&num_times_reread=2&num_volumes_read=3&priority=2&reread_value=1&score=8&status=completed&tags=foo%2Cbar")
testBody(t, r, "comments=comments&finish_date=&is_rereading=true&num_chapters_read=3&num_times_reread=2&num_volumes_read=3&priority=2&reread_value=1&score=8&start_date=2022-02-20&status=completed&tags=foo%2Cbar")
const out = `
{
"status": "completed",
Expand All @@ -108,6 +108,7 @@ func TestMangaServiceUpdateMyListStatus(t *testing.T) {
"num_chapters_read": 3,
"is_rereading": true,
"updated_at": "2018-04-25T15:59:52Z",
"start_date": "2022-02-20",
"priority": 2,
"num_times_reread": 2,
"reread_value": 1,
Expand All @@ -129,6 +130,8 @@ func TestMangaServiceUpdateMyListStatus(t *testing.T) {
RereadValue(1),
Tags{"foo", "bar"},
Comments("comments"),
StartDate(time.Date(2022, 02, 20, 0, 0, 0, 0, time.UTC)),
FinishDate(time.Time{}),
)
if err != nil {
t.Errorf("Manga.UpdateMyListStatus returned error: %v", err)
Expand All @@ -146,6 +149,8 @@ func TestMangaServiceUpdateMyListStatus(t *testing.T) {
Tags: []string{"foo", "bar"},
Comments: "comments",
UpdatedAt: time.Date(2018, 04, 25, 15, 59, 52, 0, time.UTC),
StartDate: "2022-02-20",
FinishDate: "",
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Manga.UpdateMyListStatus returned\nhave: %+v\n\nwant: %+v", got, want)
Expand Down

0 comments on commit 23294af

Please sign in to comment.