zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.37k stars 287 forks source link

Add New(...) constructor for client #107

Closed jchorl closed 4 years ago

jchorl commented 4 years ago

Hi!

I'd like to instantiate my own Spotify client. Following this Google Oauth example, I want to do something like

    httpClient, err := util.GetOauthClient(context.TODO(), cfg, "spotifycreds.json")
    if err != nil {
        return spotify.Client{}, fmt.Errorf("GetOauthClient(): %w", err)
    }

    return spotify.New(spotify.WithHTTPClient(httpClient)), nil

I've written generic boilerplate for generating an oauth client that I can use for multiple libs, like google's calendar lib (here)

I opted to follow the functional options pattern described here and also modified the tests to test out the new constructor.

The docs are updated to still recommend the standard auth flow.

Let me know what you think!

zmb3 commented 4 years ago

Closing since #123 was merged.