// API makes a an API request to the Playlyfe API
API makes a an API request to the Playlyfe API
// API makes a an API request to the Playlyfe API
func (p *Playlyfe) API(method string, route string, query H, postbody interface{}, result interface{}, raw bool) error {
	var body string
	var err error
	var errs []error
	var plError Error
	err = p.checkToken(query)
	if err != nil {
		return err
	}
	params := url.Values{}
	for k, v := range query {
		params.Add(k, v.(string))
	}
	apiRoute := p.apiEndpoint + route + "?" + params.Encode()
	switch method {
	case "GET":
		_, body, errs = p.client.Get(apiRoute).Query(query).End()
	case "POST":
		_, body, errs = p.client.Post(apiRoute).Query(query).Send(postbody).End()
	case "PATCH":
		_, body, errs = p.client.Patch(apiRoute).Query(query).Send(postbody).End()
	case "PUT":
		_, body, errs = p.client.Put(apiRoute).Query(query).Send(postbody).End()
	case "DELETE":
		_, body, errs = p.client.Delete(apiRoute).Query(query).End()
	default:
		_, body, errs = p.client.Head(apiRoute).Query(query).End()
	}
	if errs != nil {
		return errs[0]
	}
	if strings.Contains(body, `"error"`) {
		err = json.Unmarshal([]byte(body), &plError)
		if err != nil {
			return p.newJSONError()
		}
		return &plError
	}
	if raw {
		if str, ok := result.(*[]byte); ok {
			*str = []byte(body)
		}
	} else {
		err = json.Unmarshal([]byte(body), &result)
		if err != nil {
			return p.newJSONError()
		}
	}
	return nil
}
func ( p * Playlyfe ) API ( method string , route string , query H , postbody interface { } , result interface { } , raw bool ) error { var body string var err error var errs [ ] error var plError Error err = p . checkToken ( query ) if err != nil { return err } params := url . Values { } for k , v := range query { params . Add ( k , v . ( string ) ) } apiRoute := p . apiEndpoint + route + " " + params . Encode ( ) switch method { case " " : _ , body , errs = p . client . Get ( apiRoute ) . Query ( query ) . End ( ) case " " : _ , body , errs = p . client . Post ( apiRoute ) . Query ( query ) . Send ( postbody ) . End ( ) case " " : _ , body , errs = p . client . Patch ( apiRoute ) . Query ( query ) . Send ( postbody ) . End ( ) case " " : _ , body , errs = p . client . Put ( apiRoute ) . Query ( query ) . Send ( postbody ) . End ( ) case " " : _ , body , errs = p . client . Delete ( apiRoute ) . Query ( query ) . End ( ) default : _ , body , errs = p . client . Head ( apiRoute ) . Query ( query ) . End ( ) } if errs != nil { return errs [ 0 ] } if strings . Contains ( body , `"error"` ) { err = json . Unmarshal ( [ ] byte ( body ) , & plError ) if err != nil { return p . newJSONError ( ) } return & plError } if raw { if str , ok := result . ( * [ ] byte ) ; ok { * str = [ ] byte ( body ) } } else { err = json . Unmarshal ( [ ] byte ( body ) , & result ) if err != nil { return p . newJSONError ( ) } } return nil }
API makes a an API request to the Playlyfe API
API makes a an API request to the Playlyfe API