Go library for accessing the MyAnimeList API: http://myanimelist.net/modules.php?go=api

go-myanimelist

go-myanimelist is a Go client library for accessing the MyAnimeList API.

GitHub license GoDoc Go Report Card Coverage Status Build Status

Project Status

The MyAnimeList API has been stable for years and as of the latest version, the API of this package is fixed. Unless MyAnimeList changes their API, this project can be considered complete.

As of March 2017, this package is featured in awesome-go.

Installation

This package can be installed using:

go get github.com/nstratos/go-myanimelist/mal

Usage

Import the package using:

import "github.com/nstratos/go-myanimelist/mal"

First construct a new mal client:

c := mal.NewClient()

Then use one of the client's services (Account, Anime or Manga) to access the different MyAnimeList API methods.

List

To get the anime and manga list of a user:

c := mal.NewClient()

list, _, err := c.Anime.List("Xinil")
// ...

list, _, err := c.Manga.List("Xinil")
// ...

Authentication

Beyond List, the rest of the methods require authentication so typically you will use an option to pass username and password to NewClient:

c := mal.NewClient(
	mal.Auth("<your username>", "<your password>"),
)

Search

To search for anime and manga:

c := mal.NewClient(mal.Auth("<your username>", "<your password>"))

result, _, err := c.Anime.Search("bebop")
// ...

result, _, err := c.Manga.Search("bebop")
// ...

For more complex searches, you can provide the % operator which acts as a wildcard and is escaped as %% in Go:

result, _, err := c.Anime.Search("fate%%heaven%%flower")
// ...
// Will return: Fate/stay night Movie: Heaven's Feel - I. presage flower

Note: This is an undocumented feature of the MyAnimeList Search method.

Add

To add anime and manga, you provide their IDs and values through AnimeEntry and MangaEntry:

c := mal.NewClient(mal.Auth("<your username>", "<your password>"))

_, err := c.Anime.Add(9989, mal.AnimeEntry{Status: mal.Current, Episode: 1})
// ...

_, err := c.Manga.Add(35733, mal.MangaEntry{Status: mal.Planned, Chapter: 1, Volume: 1})
// ...

Note that when adding entries, Status is required.

Update

Similar to Add, Update also needs the ID of the entry and the values to be updated:

c := mal.NewClient(mal.Auth("<your username>", "<your password>"))

_, err := c.Anime.Update(9989, mal.AnimeEntry{Status: mal.Completed, Score: 9})
// ...

_, err := c.Manga.Update(35733, mal.MangaEntry{Status: mal.OnHold})
// ...

Delete

To delete anime and manga, simply provide their IDs:

c := mal.NewClient(mal.Auth("<your username>", "<your password>"))

_, err := c.Anime.Delete(9989)
// ...

_, err := c.Manga.Delete(35733)
// ...

More Examples

See package examples: https://godoc.org/github.com/nstratos/go-myanimelist/mal#pkg-examples

Advanced Control

If you need more control over the created requests, you can use an option to pass a custom HTTP client to NewClient:

c := mal.NewClient(
	mal.HTTPClient(&http.Client{}),
)

For example this http.Client will make sure to cancel any request that takes longer than 1 second:

httpcl := &http.Client{
	Timeout: 1 * time.Second,
}
c := mal.NewClient(mal.HTTPClient(httpcl))
// ...

Unit Testing

To run all unit tests:

go test -cover

To see test coverage in your browser:

go test -covermode=count -coverprofile=count.out && go tool cover -html count.out

Integration Testing

The integration tests will exercise the entire package against the live MyAnimeList API. As a result, these tests take much longer to run and there is also a much higher chance of false positives in test failures due to network issues etc.

These tests are meant to be run using a dedicated test account that contains empty anime and manga lists. The username and password of the test account need to be provided every time.

To run the integration tests:

go test -tags=integration -username '<test account username>' -password '<test account password>'

License

MIT

Comments
  • Gettin Unsupported Grant Type when running your Example

    Gettin Unsupported Grant Type when running your Example

    I have basically copied and pasted your code from here: https://github.com/nstratos/go-myanimelist/tree/main/example/malauth

    It opens a Webpage, and when I hit 'allow', I get this response displayed in my browser

    {
       "error": "unsupported_grant_type",
        "message": "The authorization grant type is not supported by the authorization server.",
        "hint": "Check the `grant_type` parameter"
    }
    

    My System

    $ go version
    go version go1.17.2 darwin/amd64
    

    I'm new to OAuth so let me know if I need to make any modifications.

    Thanks in advance.

  • Support new fields for user information endpoint

    Support new fields for user information endpoint

    There are a few fields mentioned in the official docs for Get my user information that are currently missing from UserService.User.

    Αdd support for:

    birthday     | string or null <date>
    time_zone    | string or nullfor example: "America/Los_Angeles"
    is_supporter | boolean or null
    
  • UserService.MyInfo does not pass options to the request

    UserService.MyInfo does not pass options to the request

    A lot of methods use the Client.list internally which handles options but UserService.MyInfo doesn't, so the options have to be passed "manually" but they are currently missing.

    This became obvious because the only option that UserService.MyInfo supports is Fields which is not covered by a test and attempting to cover it makes no difference.

    go test -covermode=count -coverprofile=count.out && go tool cover -html count.out
    

    go-myanimelist-myinfo-no-options

  • Auto refresh the oauth2 token

    Auto refresh the oauth2 token

    This change uses the whole oauth2 token for authentication which includes type, access token, refresh token and expiration (previously only the access token was used).

    By using all the info of the oauth2 token and especially the refresh token, the oauth2 client can now seamlessly refresh the oauth2 token when it expires.

    The documentation and examples have been updated accordingly.

  • MyAnimeList API v2

    MyAnimeList API v2

    Update project for MyAnimeList API v2

    Board: https://github.com/nstratos/go-myanimelist/projects/1

    Docs: https://myanimelist.net/apiconfig/references/api/v2

  • Unit tests for JSON marshal of project types

    Unit tests for JSON marshal of project types

    Unit tests can be improved by verifying that all fields JSON marshal and unmarshal correctly for the various types returned as responses:

    • [ ] Anime
    • [ ] Manga
    • [ ] Forum
    • [ ] Topic
    • [ ] TopicDetails
    • [x] User
    • [ ] UserAnime
    • [ ] AnimeListStatus
    • [ ] UserManga
    • [ ] MangaListStatus
Go library for accessing the GitHub API

go-github go-github is a Go client library for accessing the GitHub API v3. Currently, go-github requires Go version 1.9 or greater. go-github tracks

Dec 30, 2022
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://developer.github.com/v4/).

githubv4 Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). If you're looking for a client

Dec 26, 2022
May 25, 2021
Go library for accessing the Keycloak API

keycloak keycloak is a Go client library for accessing the Keycloak API. Installation go get github.com/zemirco/keycloak Usage package main import (

Dec 1, 2022
NotionGo is a Go client library for accessing the Notion API v1.

NotionGo (WIP) NotionGo is a Go client library for accessing the Notion API v1. Installation NotionGo is compatible with modern Go releases in module

May 22, 2021
go-ftx go-ftx is a Go client library for accessing the FTX API

go-ftx go-ftx is a Go client library for accessing the FTX API

Nov 14, 2022
Go library for accessing the BlaBlaCar API

go-blablacar is a Go client library for accessing the BlaBlaCar API.

Nov 27, 2022
A GoLang wrapper for Politics & War's API. Forego the hassle of accessing the API directly!

A GoLang wrapper for Politics & War's API. Forego the hassle of accessing the API directly!

Mar 5, 2022
Go library for accessing trending repositories and developers at Github.
Go library for accessing trending repositories and developers at Github.

go-trending A package to retrieve trending repositories and developers from Github written in golang. This package were inspired by rochefort/git-tren

Dec 21, 2022
Go(lang) client library for accessing information of an Apache Mesos cluster.

megos Go(lang) client library for accessing an Apache Mesos cluster. Features Determine the Mesos leader Get the current state of every mesos node (ma

Sep 27, 2022
Experimental port of PHP faceted-search library

Experimental port of PHP k-samuel/faceted-search PHP Library https://github.com/k-samuel/faceted-search Bench v1.3.0 PHP 7.4.25 (no xdebug extension)

Sep 17, 2022
Lms-notifier - A simple tool to keep track of lms modules

lms-notifier A simple tool to keep track of lms modules Getting Started These in

Sep 16, 2022
🤖🚀📦 A Discord Bot for accessing the cdnjs platform
🤖🚀📦 A Discord Bot for accessing the cdnjs platform

A bridge between https://cdnjs.com/api and Discord Big shoutout to Br1ght0ne for helping me with writing helpers.go/SplitIn

Aug 17, 2022
efsu is for accessing AWS EFS from your machine without a VPN

efsu: VPN-less access to AWS EFS efsu is for accessing AWS EFS from your machine without a VPN. It achieves this by deploying a Lambda function and sh

Mar 11, 2022
Backgammon Web API. Sophisticed neural net based multi-ply evalution engine for Backgammon moves

Backgammon Web API. Sophisticed neural net based multi-ply evalution engine for Backgammon moves.

Dec 25, 2022
The Bhojpur.NET Platform automates the provisioning of ready-to-use Network, Security, and IT applications

Bhojpur.NET Platform The Bhojpur.NET Platform automates the provisioning of ready-to-use Network, Security, and IT applications Learn more ?? The Bhoj

Nov 9, 2022
The Bhojpur Ara is a software product used for automated resource assembly within Bhojpur.NET Platform ecosystem to enable delivery of applications and services.

Bhojpur Ara - Automated Resource Assembly The Bhojpur Ara is a service product used for automated resource assembly within the Bhojpur.NET Platform ec

Apr 28, 2022
A simple Kubernetes-native CI system for the Bhojpur.NET Platform.

Bhojpur Piro - Kubernetes-native CI A simple Kubernetes-native CI system applied by the Bhojpur.NET Platform. It knows no pipelines, just the jobs and

Apr 28, 2022
The Bhojpur PEE is a software-as-a-service product used as a Provider's Edge Equipment based on Bhojpur.NET Platform for application delivery.

Bhojpur PEE - Provider's Edge Equipment The Bhojpur PEE is a software-as-a-service product used as a Provider's Edge Equipment based on Bhojpur.NET Pl

Dec 31, 2021