spotify_client

package module
v0.0.0-...-1525fee Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2014 License: MIT Imports: 8 Imported by: 0

README

spotify_client

A Spotify Web Service API client written in Go. The spotify_client project aims to become a full featured, robust library for Golang that can be used to build cloud-based applications that interact with the Spotify developer APIs.

Installation

This is still a work in progress, and the library does not support the full Spotify Web Service API yet. Before you get too far, you'll need to create a Spotify Developer account. You can do that by following the instructions at:

https://developer.spotify.com/my-applications/

Once you've created your developer account and registered your spotify sample application, you'll need to provide the 'client_id' and 'client_secret' data in order for this library to talk to the Spotify servers. In the server.go file, you'll find these two lines where you can insert those values:

var ClientId s.ClientId = ""
var ClientSecret s.ClientSecret = ""

All of the interfaces you'll need are in the lib.go file. I have also included a small example web server that uses all of the existing API features.

Running the example web server will start an HTTP listener on your local host at port 8080. You can start the server with:

$> go run server.go

You can then point your local browser at http://localhost:8080/. When that page loads you will be redirected to the Spotify OAuth user login page. Enter your spotify credentials. Once authenticated, the example server will then retrieve a list of your playlists. Clicking on the linked playlist will then retrieve the track list and render that to simple (ugly) HTML.

API Reference

For reference, this library is built to use the official Spotify Web API. More details are visible here: https://developer.spotify.com/web-api/

Contributors

If you're a Spotify fan who'd like to develop applications in Go, I'd love to hear from you! Contact the author - jason@buberel.org

Documentation

Overview

*

A client library for the Spotify Web Service API, written in the Go
programming language (golang). Use of this library requires
a Spotify Developer Account. Start here to set one up:

https://developer.spotify.com/my-applications/

See the README.md for more information.

*

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken string

Type overrides to ensure various string-like values don't get mixed up.

type AddTrackToPlaylistRequest

type AddTrackToPlaylistRequest struct {
	Uris []string `json:"uris"`
}

type AddTrackToPlaylistResponse

type AddTrackToPlaylistResponse struct {
	SnapshotId string `json:"snapshot_id"`
}

func AddTracksToPlaylist

func AddTracksToPlaylist(accessToken AccessToken, username Username, playlist Playlist, tracks []Track) (AddTrackToPlaylistResponse, error)

Method will add tracks to an existing playlist

type Album

type Album struct {
	AlbumType string `json:"album_type"`
	Href      string `json:"href"`
	Id        string `json:"id"`
	Name      string `json:"name"`
}

type Artist

type Artist struct {
	Href string `json:"href"`
	Id   string `json:"id"`
	Name string `json:"name"`
}

type ClientId

type ClientId string

type ClientSecret

type ClientSecret string

type CreatePlaylistRequest

type CreatePlaylistRequest struct {
	Name   string `json:"name"`
	Public bool   `json:"public"`
}

type Params

type Params map[string]string

A Params is a map containing URL parameters.

type Playlist

type Playlist struct {
	Href  string        `json:"href"`
	Id    string        `json:"id"`
	Name  string        `json:"name"`
	Owner PlaylistOwner `json:"owner"`
}

func CreatePlaylist

func CreatePlaylist(accessToken AccessToken, username Username, playlistName string, playlistPublic bool) (Playlist, error)

Given an AccessToken, UserName (retrieved using the GetAccessToken and GetUserInfo functions), and new playlist name, this method will create a new playlist.

func GetPlaylistInfo

func GetPlaylistInfo(accessToken AccessToken, username Username, playlistId string) (Playlist, error)

Given an AccessToken, UserName (retrieved using the GetAccessToken and GetUserInfo functions), and Playlist ID, this function will return a simplified Playlist object

func GetUserPlaylists

func GetUserPlaylists(accessToken AccessToken, username Username) ([]Playlist, error)

Given an AccessToken and a UserName (retrieved using the GetAccessToken and GetUserInfo functions), this function will extract all of the user's playlists as a slice of Playlist objects.

type PlaylistOwner

type PlaylistOwner struct {
	Href string `json:"href"`
	Id   string `json:"id"`
}

type PlaylistResponse

type PlaylistResponse struct {
	Href     string     `json:"href"`
	Limit    int32      `json:"limit"`
	Offset   int32      `json:"offset"`
	Next     string     `json:"next"`
	Previous string     `json:"previous"`
	Total    int32      `json:"total"`
	Items    []Playlist `json:"items"`
}

type PlaylistTrack

type PlaylistTrack struct {
	Track Track `json:"track"`
}

type RedirectUri

type RedirectUri string

type ResponseUserAgent

type ResponseUserAgent struct {
	Useragent string `json:"user-agent"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken  AccessToken `json:"access_token"`
	TokenType    string      `json:"token_type"`
	ExpiresIn    int64       `json:"expires_in"`
	RefreshToken string      `json:"refresh_token"`
}

func GetAccessToken

func GetAccessToken(accessCode string, clientId ClientId, clientSecret ClientSecret, redirectUri RedirectUri) (*TokenResponse, error)

Given an access code returned by the spotify web server, along with the Client ID and Client Secret for your spotify app (see: https://developer.spotify.com/my-applications/) this method will retrieve an access token, returned as type TokenResponse

type Track

type Track struct {
	Id      string   `json:"id"`
	Href    string   `json:"href"`
	Name    string   `json:"name"`
	Album   Album    `json:"album"`
	Artists []Artist `json:"artists"`
}

func GetTracksForPlaylist

func GetTracksForPlaylist(accessToken AccessToken, owner Username, playlistId string) ([]Track, error)

For a given user and playlist, this method will return track listings for each entry in the selected playlist as a slice of Track objects.

type TracklistResponse

type TracklistResponse struct {
	Href     string          `json:"href"`
	Items    []PlaylistTrack `json:"items"`
	Limit    int32           `json:"limit"`
	Offset   int32           `json:"offset"`
	Next     string          `json:"next"`
	Previous string          `json:"previous"`
	Total    int32           `json:"total"`
}

type UserInfoResponse

type UserInfoResponse struct {
	Id          Username `json:"id"`
	URI         string   `json:"uri"`
	DisplayName string   `json:"display_name"`
	Email       string   `json:"email"`
}

func GetUserInfo

func GetUserInfo(accessToken AccessToken) (*UserInfoResponse, error)

Given an AccessToken returned by the GetAccessToken method, this function will retrieve information about the authenticated user. This information is used to retrieve their playlists later.

type Username

type Username string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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