Giter Club home page Giter Club logo

go-yamusic's Introduction

yamusic

Go Reference Go

Description

Unofficial Go client library for Yandex.Music API.

Golang fork of Node.js library. Client style based on google/go-github.

Usage

import "github.com/ndrewnee/go-yamusic/yamusic"

Construct a new Yandex.Music client, then use the various services on the client to access different parts of the Yandex.Music API.

Using functional options for friendly APIs.

package main

import (
    "github.com/ndrewnee/go-yamusic/yamusic"
    "github.com/rubyist/circuitbreaker"
    "context"
    "log"
    "net/http"
    "time"
)

func main() {
    // constructing http client with circuit breaker
    // it implements yamusic.Doer interface
    circuitClient := circuit.NewHTTPClient(time.Second * 5, 10, nil)
    client := yamusic.NewClient(
        // if you want http client with circuit breaker
        yamusic.HTTPClient(circuitClient),
        // provide user_id and access_token (needed by some methods)
        yamusic.AccessToken(100, "some_access_token"),
    )
    // list all genres
    genres, resp, err := client.Genres().List(context.Background())
    if err != nil {
        log.Fatal(err)
    }
    // resp is general type *http.Response
    if resp.StatusCode != http.StatusOK {
        log.Fatal("http status is not 200")
    }
    log.Println("Genres: ", genres)
    // create new public playlist. Need access token
    createdPlaylist, _, err := client.Playlists().Create(context.Background(), "New Playlist", true)
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Created playlist: ", createdPlaylist)
}

๐Ÿ‘ท Build

Build package

make build

๐Ÿงช Testing

Run unit tests:

make test

Run integration tests:

Note that you should set YANDEX_USER_ID and YANDEX_ACCESS_TOKEN environment variables.

make test_integration

๐Ÿ– Lint

Run linters

make lint

go-yamusic's People

Contributors

bugscatcher avatar ndrewnee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

go-yamusic's Issues

Add information about userid

User id is used in many methods, but it's not clear from docs how to get it. Can you please add a recommended way?

Btw, Python library fetches and stores account information on init to avoid asking user to provide user id in each method.


Getting token is also not clear, but it's probably because there's no official way to get. Leaving this discussion here in case somebody looks for it as me.

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.