Code Monkey home page Code Monkey logo

go-kitsu's Introduction

go-kitsu

go-kitsu is a Go client library for accessing the kitsu.io API.

Go Reference GitHub license Go Report Card Coverage Status Build Status Test Status Integration Status

Installation

This package can be installed using:

go get github.com/nstratos/go-kitsu/kitsu

Usage

Import the package using:

import "github.com/nstratos/go-kitsu/kitsu"

Project Status

This project is currently under development. Expect things to change. Some useful methods like getting users, library entries and anime are already implemented. For a full list of what needs to be implemented please check Roadmap.md.

Endpoint Stability

The Kitsu API does not currently provide endpoint versioning. The only available endpoint is the appropriately named "edge" endpoint (https://kitsu.io/api/edge/) which (to quote the Kitsu API docs) "offers no guarantees: anything could change at any time".

As a result, this package provides as many guarantees as the edge endpoint. Nevertheless there is effort to keep the package as stable as possible through integration tests that exercise the package against the live Kitsu API.

Unit testing

To run all unit tests:

go test

To see test coverage:

go test -cover

For an HTML presentation of the coverage information:

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

And for heat maps:

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

Integration testing

The integration tests will exercise the package against the live Kitsu API and will hopefully reveal incompatible changes. Since these tests are using live data, they take much longer to run and there is a chance for false positives.

The tests need a dedicated test account for authentication. A newly created account has no slug set by default. To set the slug, open the profile settings and set Profile URL.

To run the integration tests:

go test -tags=integration -slug="<test account slug>" -password="<test account password>"

License

MIT

go-kitsu's People

Contributors

dependabot[bot] avatar nstratos avatar robertgzr avatar

Watchers

 avatar  avatar  avatar

Forkers

robertgzr

go-kitsu's Issues

Usage of an external package to simplify interactions with the JSON API document

This issue highlights the benefits and drawbacks of using an external package to interact with the JSON API document, especially the more complex case of unmarshaling to structs. The aim is to have a clear overview, discuss and conclude what is going to be used for the development of this package.

Candidates

Benefits of adding an external dependency

  1. Simplify the code needed for (un)marshaling to structs with unmarshal of included relationships being the most complex case.
  2. Having a robust and battle-tested codebase that handles the intricacies of JSON API for us.
  3. Be resistant to change. This is especially important since the Kitsu API is not yet stable.

Drawbacks

  1. Having a vendored dependency on a package that the user has to import is known to be problematic. This can be mitigated by making sure no code from the dependency is leaked to the final user. There is also heavy development of the dep tool. While it is not yet complete it can help with this problem.
  2. Some of the code gets uglier especially since some packages like google/jsonapi use reflection but the benefit is that the structs of go-kitsu become much simpler and prettier.
  3. The standard cost of dependencies. Obviously having zero dependencies is much more preferred especially for a package like this. Nevertheless it seems that just the case of unmarshaling included relationships is complex enough to justify the cost.

Comparison of candidates

After trying other packages for a while now, it seems that the most robust ones are google/jsonapi and manyminds/api2go. What api2go does better is that it more or less avoids reflection and uses interfaces to let the user control marshaling. Unfortunately at the time of writing, the client capabilities of api2go aka unmarshaling are not yet complete (manyminds/api2go#112).

Other packages like smotes/jsonapi and gonfire/jsonapi while they might help with 2. and 3. they do not help with 1. as filling our structs with data has to be done manually. Nevertheless they might prove more performant overall since they avoid reflection.

That said, since we are dealing with fetching data from an API the overhead of reflection shouldn't be a problem which should make google/jsonapi the strongest candidate as it helps with 1. by allowing to easily unmarshal to structs using custom tags like jsonapi:"attr". Additionaly at the time of writing google/jsonapi seems to be more actively maintained than the rest.

Known Issues with google/jsonapi and possible solutions

While google/jsonapi might be the strongest candidate it comes with a few issues:

  • Right now there seems to be no way of having access to JSON API pagination links without parsing the document two times (google/jsonapi#64). This can be solved by modifying the function UnmarshalManyPayload to also return the map of links but obviously modifying vendored code is not the most elegant solution. The reason this is needed is for providing the user of the go-kitsu package an easy way to access pagination links when they do List requests. The idea was to use a custom Response type that holds the offset as it is done in go-github but maybe there is a better way.

  • The package seems to be unable to unmarshal attributes that are objects (google/jsonapi#74). There is already a case where this is trouble for go-kitsu when trying to get a list of anime including relationships castings.character and castings.person. castings.character includes an attribute called image which is an object containing strings like original. Since this is a field of a relationship, it is not such a big deal but there can be many more cases like this one. The simplest thing to do for now is to not include such problematic fields in our structs and hopefully the issue will get fixed eventually.

Giving google/jsonapi a test drive

Altered code which uses google/jsonapi as a vendored dependency will be committed on a separate branch to have a clearer view of how it works in practice.

Discussion and opinions are more than welcome.

API returns 500 server error when requesting an Anime List that includes castings

Performing a request for an anime list that includes castings returns 500 server error from the API.

This causes the integration test to fail as it performs the following request:

Example:

list, resp, err := c.Anime.List(
	kitsu.Limit(results),
	kitsu.Include("castings.character", "castings.person"),
)

Normally this shouldn't happen as castings is still considered a valid relationship.

It seems that castings will be replaced by a new resource called Staff:

kitsu-api-docs-staff-replaces-castings-screenshot_2022-08-25_004651

The integration test should avoid asking for castings for the time being.

It could ask for a different resource, possibly the new Staff resource, after it is implemented.

Manga

  • Manga
  • Chapters
  • Trending Manga

Users

  • Blocks
  • Favorites
  • Follows
  • Linked accounts
  • Profile Link Sites
  • Profile Links
  • Roles
  • Stats
  • User Roles
  • #11

Anime

  • Anime
  • Episodes
  • Trending Anime

Producers & Staff

  • Anime Productions
  • Anime Staff
  • Manga Staff
  • Producers
  • People
  • Castings

Methods: Users

  • Fetch Collection
  • Fetch Resource
  • Create Resource
  • Update Resource
  • Delete Resource

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.