anime

package
v3.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2022 License: GPL-3.0 Imports: 12 Imported by: 1

README

MAL2Go/user/anime

MAL2Go user/anime package has functionality related to updating the user's anime list.

To get anime data, refer to the anime package.

There are multiple possible server responses and errors currently haven't been implemented yet.

Installation

In a terminal, run

go get "github.com/MikunoNaka/MAL2Go/v2/user/anime"

Usage

Firstly, import this package and instanciate the client.

import (
  "github.com/MikunoNaka/MAL2Go/v2/user/anime"
)

Now instanciate with

myClient := anime.Client {
  AuthToken: "Bearer " + yourTokenHere,
}
  • Delete an anime from user's anime list
animeId := 457 // anime's ID

resp := myClient.DeleteAnime(animeId)

/* if anime is successfully deleted, resp is 200
 * if anime isn't in the list resp is 404 */
fmt.Println(resp)
  • Get user's anime list

Possible statuses are:

  • watching
  • completed
  • on_hold
  • dropped
  • plan_to_watch

Leaving blank ("") gets all the anime

Possible sorts are:

  • list_score
  • list_updated_at
  • anime_title
  • anime_start_date
  • anime_id (beta)

Leaving user blank ("") or as "@me" returns the authenticated user's list

user := "0ZeroTsu" 
status := "watching"
sort := "list_score"

limit := 1000 // max is 1000
offset := 0

// fields := []string{} means get all the fields
fields := []string{"title"}

animeList, err := myClient.GetAnimeList(user, status, sort, limit, offset, fields)
if err != nil {
  fmt.Println(err)
}

// animeList.Animes is an array of the animes in the list
for _, anime := range animeList.Animes {
  fmt.Println(anime.Title)
}

fmt.Println(animeList.Paging.NextPage, animeList.Paging.PrevPage)
  • Set an anime's status
animeId := 457 // anime's ID
status := "dropped"
resp, _ := myClient.SetStatus(animeId, status)
fmt.Println(resp.Error, resp.Message)
  • Set watched episodes
animeId := 457 // anime's ID
epWatched := 22
resp, _ := myClient.SetWatchedEpisodes(animeId, epWatched)
fmt.Println(resp.Error, resp.Message)
  • Set is rewatching status
animeId := 457 // anime's ID
isRewatching := true
_, _ := myClient.SetIsRewatching(animeId, isRewatching)
  • Set an anime's score
animeId := 457 // anime's ID
score := 10
_, _ := myClient.SetScore(animeId, score)
  • Set an anime's priority

Priority on MyAnimeList ranges from 0 to 2

animeId := 457 // anime's ID
priority := 2
_, _ := myClient.SetPriority(animeId, priority)
  • Set an anime's rewatch value

Rewatch value on MyAnimeList ranges from 0 to 5

animeId := 457 // anime's ID
rewatchValue := 4
_, _ := myClient.SetRewatchValue(animeId, rewatchValue)
  • Set an anime's rewatch count

Number of times user has rewatched the anime. There is no limit

animeId := 457 // anime's ID
rewatchCount := 69
_, _ := myClient.SetRewatchCount(animeId, rewatchCount)
  • Set an anime's tags
animeId := 457 // anime's ID
tags := "tags"
_, _ := myClient.UpdateTags(animeId, tags)
  • Set an anime's comments
animeId := 457 // anime's ID
comments := "I love this"
_, _ := myClient.UpdateComments(animeId, comments)
  • Update all fields of an anime

WARNING: this function can overwrite any data and set it to null if you don't specify a value to it.

Refrain/use it carefully to avoid data loss.

updateData := anime.UpdateAnimeData {
  Status: "watching",
  IsRewatching: true,
  Score: 10,
  EpWatched: 22,
  Priority: 2,
  TimesRewatched: 69,
  RewatchValue: 4,
  Tags: "tags",
  Comments: "I love this",
}

animeId := 457 // anime's ID

resp, err := myClient.UpdateAnime(animeId, updateData)
if err != nil {
  fmt.Println(err)
}

fmt.Println(resp.Error, resp.Message)

Structure

  • animelist.go Contains the exported functions to do some basic functions with anime lists.

  • animelist.structs.go Contains all the structs representing animelist data pulled from MyAnimeList.

  • client.go The Client for accessing the API with this package.

  • request_handler.go Responsible for making HTTP requests

  • update_animelist.go Contains all the exported functions to update an anime entry in user's animelist.

Documentation

Index

Constants

View Source
const BASE_URL string = "https://api.myanimelist.net/v2"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client util.DefaultClient

func (Client) DeleteAnime

func (c Client) DeleteAnime(id int) (string, error)

Delete an anime from user's anime list

func (Client) GetAnimeList

func (c Client) GetAnimeList(user, status, sort string, limit, offset int, fields []string) ([]a.Anime, bool, error)

Get authenticated user's anime list returns true as second value if there are more animes present

func (Client) SetIsRewatching

func (c Client) SetIsRewatching(id int, isRewatching bool) (UpdateResponse, error)

update just an anime's rewatching status

func (Client) SetPriority

func (c Client) SetPriority(id int, priority int) (UpdateResponse, error)

update just an anime's priority

func (Client) SetRewatchCount

func (c Client) SetRewatchCount(id int, rewatchCount int) (UpdateResponse, error)

update just an anime's rewatch count

func (Client) SetRewatchValue

func (c Client) SetRewatchValue(id int, rewatchValue int) (UpdateResponse, error)

update just an anime's rewatch value

func (Client) SetScore

func (c Client) SetScore(id int, score int) (UpdateResponse, error)

update just the anime's score

func (Client) SetStatus

func (c Client) SetStatus(id int, status string) (UpdateResponse, error)

update just an anime's status

func (Client) SetWatchedEpisodes

func (c Client) SetWatchedEpisodes(id int, episodesWatched int) (UpdateResponse, error)

update just an anime's num of episodes watched

func (Client) UpdateAnime

func (c Client) UpdateAnime(id int, data UpdateAnimeData) (UpdateResponse, error)
This will overwrite everything
* i won't use it.. but it's pretty flexible
* so this will stay here

Update/Add an anime to user's anime list

func (Client) UpdateComments

func (c Client) UpdateComments(id int, comments string) (UpdateResponse, error)

update just an anime's comments

func (Client) UpdateTags

func (c Client) UpdateTags(id int, tags string) (UpdateResponse, error)

update just an anime's tags

type UpdateAnimeData

type UpdateAnimeData struct {
	Status         string
	IsRewatching   bool
	Score          int
	EpWatched      int
	Priority       int
	TimesRewatched int
	RewatchValue   int
	Tags           string
	Comments       string
}

type UpdateResponse

type UpdateResponse struct {
	Status         string `json:"status"`
	Score          int    `json:"score"`
	EpWatched      int    `json:"num_episodes_watched"`
	IsRewatching   bool   `json:"is_rewatching"`
	StartDate      string `json:"start_date"`
	FinishDate     string `json:"finish_date"`
	Priority       string `json:"priority"`
	TimesRewatched string `json:"num_times_rewatched"`
	RewatchValue   string `json:"rewatch_value"`
	Tags           string `json:"tags"`
	Comments       string `json:"string"`
	UpdatedAt      string `json:"updated_at"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL