<commit_before>//
// This is a list of methods that map to Rdio API methods. Calling them returns a proper
// Go struct of the data, which is probably preferable to getting a blob of JSON or
// a byte stream.
//
// Unfortunately, there is a bit of repetition in this code (the Response struct and
// checking the Status == "ok" response), but I don't know how to consolidate it
//

package rdio

import (
	"encoding/json"
	"errors"
)

func (c *Client) GetNewReleases() ([]Album, error) {
	params := make(map[string][]string)
	body, err := c.Call("getNewReleases", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Album
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}<commit_msg>Starting to stub out some of the other methods<commit_after>//
// This is a list of methods that map to Rdio API methods. Calling them returns a proper
// Go struct of the data, which is probably preferable to getting a blob of JSON or
// a byte stream.
//
// Unfortunately, there is a bit of repetition in this code (the Response struct and
// checking the Status == "ok" response), but I don't know how to consolidate it.
//
// List of methods is here: http://developer.rdio.com/docs/read/rest/Methods
//

package rdio

import (
	"encoding/json"
	"errors"
	"net/url"
)

// Core
// Catalog
// Collection
// Playlists
// Comments
// Social
// Network
// Activity and Statistics

func (c *Client) GetActivityStream() ([]Album, error) {
	params := url.Values{}
	body, err := c.Call("getActivityStream", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Album
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

func (c *Client) GetHeavyRotationAlbums() ([]Album, error) {
	params := url.Values{
		"type": []string{"albums"},
	}
	body, err := c.Call("getHeavyRotation", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Album
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

func (c *Client) GetHeavyRotationArtists() ([]Artist, error) {
	params := url.Values{
		"type": []string{"artists"},
	}
	body, err := c.Call("getHeavyRotation", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Artist
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

func (c *Client) GetNewReleases() ([]Album, error) {
	params := url.Values{}
	body, err := c.Call("getNewReleases", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Album
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

func (c *Client) GetTopChartsArtists() ([]Artist, error) {
	params := url.Values{
		"type": []string{"Artist"},
	}
	body, err := c.Call("getTopCharts", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Artist
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

func (c *Client) GetTopChartsAlbums() ([]Album, error) {
	params := url.Values{
		"type": []string{"Album"},
	}
	body, err := c.Call("getTopCharts", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Album
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

func (c *Client) GetTopChartsTracks() ([]Track, error) {
	params := url.Values{
		"type": []string{"Track"},
	}
	body, err := c.Call("getTopCharts", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Track
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

func (c *Client) GetTopChartsPlaylists() ([]Playlist, error) {
	params := url.Values{
		"type": []string{"Playlist"},
	}
	body, err := c.Call("getTopCharts", params)
	if err != nil {
		return nil, err
	}

	type Response struct {
		Status string
		Result []Playlist
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return nil, errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}

// Playback

func (c *Client) GetPlaybackToken() (string, error) {
	params := url.Values{}
	body, err := c.Call("getPlaybackToken", params)
	if err != nil {
		return "", err
	}

	type Response struct {
		Status string
		Result string
	}

	// parse into json
	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return "", err
	}

	// Check that we got an OK
	if response.Status != "ok" {
		return "", errors.New("Got non-ok response from the Rdio API")
	}

	return response.Result, nil
}
{'fraction_non_alphanumeric': 0.1299891287466998, 'fraction_numerical': 0.0, 'mean_word_length': 3.2649006622516556, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7673712', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2136, 'n_words': 783}