This commit is contained in:
Deluan
2016-03-02 13:18:39 -05:00
parent 9d41f5a39f
commit 4843ccb46c
42 changed files with 150 additions and 160 deletions
+4 -4
View File
@@ -3,17 +3,17 @@ package api_test
import (
"fmt"
"github.com/astaxie/beego"
_ "github.com/deluan/gosonic/conf"
"net/http"
"net/http/httptest"
_ "github.com/deluan/gosonic/conf"
"strings"
)
const (
testUser = "deluan"
testUser = "deluan"
testPassword = "wordpass"
testClient = "test"
testVersion = "1.0.0"
testClient = "test"
testVersion = "1.0.0"
)
func AddParams(endpoint string, params ...string) string {
+10 -7
View File
@@ -1,10 +1,10 @@
package api
import (
"encoding/xml"
"fmt"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"fmt"
"encoding/xml"
)
type BaseAPIController struct{ beego.Controller }
@@ -16,7 +16,7 @@ func (c *BaseAPIController) NewEmpty() responses.Subsonic {
func (c *BaseAPIController) SendError(errorCode int, message ...interface{}) {
response := responses.Subsonic{Version: beego.AppConfig.String("apiVersion"), Status: "fail"}
var msg string
if (len(message) == 0) {
if len(message) == 0 {
msg = responses.ErrorMsg(errorCode)
} else {
msg = fmt.Sprintf(message[0].(string), message[1:len(message)]...)
@@ -24,13 +24,15 @@ func (c *BaseAPIController) SendError(errorCode int, message ...interface{}) {
response.Error = &responses.Error{Code: errorCode, Message: msg}
xmlBody, _ := xml.Marshal(&response)
c.CustomAbort(200, xml.Header + string(xmlBody))
c.CustomAbort(200, xml.Header+string(xmlBody))
}
func (c *BaseAPIController) prepResponse(response responses.Subsonic) interface{} {
f := c.GetString("f")
if f == "json" {
type jsonWrapper struct{ Subsonic responses.Subsonic `json:"subsonic-response"` }
type jsonWrapper struct {
Subsonic responses.Subsonic `json:"subsonic-response"`
}
return jsonWrapper{Subsonic: response}
}
return response
@@ -39,7 +41,9 @@ func (c *BaseAPIController) prepResponse(response responses.Subsonic) interface{
func (c *BaseAPIController) SendResponse(response responses.Subsonic) {
f := c.GetString("f")
if f == "json" {
type jsonWrapper struct{ Subsonic responses.Subsonic `json:"subsonic-response"` }
type jsonWrapper struct {
Subsonic responses.Subsonic `json:"subsonic-response"`
}
w := &jsonWrapper{Subsonic: response}
c.Data["json"] = &w
c.ServeJSON()
@@ -48,4 +52,3 @@ func (c *BaseAPIController) SendResponse(response responses.Subsonic) {
c.ServeXML()
}
}
+4 -4
View File
@@ -2,12 +2,12 @@ package api
import (
"github.com/astaxie/beego"
"github.com/deluan/gosonic/utils"
"github.com/karlkfi/inject"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/consts"
"strconv"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/utils"
"github.com/karlkfi/inject"
"strconv"
)
type GetIndexesController struct {
@@ -42,7 +42,7 @@ func (c *GetIndexesController) Get() {
i, _ := strconv.Atoi(ifModifiedSince)
l, _ := strconv.Atoi(res.LastModified)
if (l > i) {
if l > i {
indexes, err := c.repo.GetAll()
if err != nil {
beego.Error("Error retrieving Indexes:", err)
+5 -5
View File
@@ -3,14 +3,14 @@ package api_test
import (
"testing"
"github.com/deluan/gosonic/utils"
. "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/tests"
"encoding/xml"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/consts"
"github.com/deluan/gosonic/tests/mocks"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/tests"
"github.com/deluan/gosonic/tests/mocks"
"github.com/deluan/gosonic/utils"
. "github.com/smartystreets/goconvey/convey"
)
const (
@@ -104,4 +104,4 @@ func TestGetIndexes(t *testing.T) {
propRepo.SetError(false)
})
})
}
}
+1 -1
View File
@@ -2,9 +2,9 @@ package api_test
import (
"encoding/xml"
"github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
"testing"
"github.com/deluan/gosonic/tests"
)
func TestGetLicense(t *testing.T) {
+1 -1
View File
@@ -3,8 +3,8 @@ package api
import (
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain"
"github.com/karlkfi/inject"
"github.com/deluan/gosonic/utils"
"github.com/karlkfi/inject"
)
type GetMusicFoldersController struct {
+1 -1
View File
@@ -4,8 +4,8 @@ import (
"testing"
"encoding/xml"
. "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
)
func TestGetMusicFolders(t *testing.T) {
+1 -1
View File
@@ -3,9 +3,9 @@ package api_test
import (
"encoding/xml"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
"testing"
"github.com/deluan/gosonic/tests"
)
func TestPing(t *testing.T) {
+25 -26
View File
@@ -3,53 +3,52 @@ package responses
import "encoding/xml"
type Subsonic struct {
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
Status string `xml:"status,attr" json:"status"`
Version string `xml:"version,attr" json:"version"`
Error *Error `xml:",omitempty" json:"error,omitempty"`
License *License `xml:",omitempty" json:"license,omitempty"`
MusicFolders *MusicFolders `xml:",omitempty" json:"musicFolders,omitempty"`
ArtistIndex *Indexes `xml:",omitempty" json:"indexes,omitempty"`
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
Status string `xml:"status,attr" json:"status"`
Version string `xml:"version,attr" json:"version"`
Error *Error `xml:",omitempty" json:"error,omitempty"`
License *License `xml:",omitempty" json:"license,omitempty"`
MusicFolders *MusicFolders `xml:",omitempty" json:"musicFolders,omitempty"`
ArtistIndex *Indexes `xml:",omitempty" json:"indexes,omitempty"`
}
type Error struct {
XMLName xml.Name `xml:"error" json:"-"`
XMLName xml.Name `xml:"error" json:"-"`
Code int `xml:"code,attr"`
Message string `xml:"message,attr"`
}
type License struct {
XMLName xml.Name `xml:"license" json:"-" json:"-"`
Valid bool `xml:"valid,attr" json:"valid"`
XMLName xml.Name `xml:"license" json:"-"`
Valid bool `xml:"valid,attr" json:"valid"`
}
type MusicFolder struct {
XMLName xml.Name `xml:"musicFolder" json:"-"`
Id string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
XMLName xml.Name `xml:"musicFolder" json:"-"`
Id string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
}
type MusicFolders struct {
XMLName xml.Name `xml:"musicFolders" json:"-"`
Folders []MusicFolder `xml:"musicFolders" json:"musicFolder"`
XMLName xml.Name `xml:"musicFolders" json:"-"`
Folders []MusicFolder `xml:"musicFolders" json:"musicFolder"`
}
type Artist struct {
XMLName xml.Name `xml:"artist" json:"-"`
Id string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
XMLName xml.Name `xml:"artist" json:"-"`
Id string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
}
type Index struct {
XMLName xml.Name `xml:"index" json:"-"`
Name string `xml:"name,attr" json:"name"`
Artists []Artist `xml:"index" json:"artist"`
XMLName xml.Name `xml:"index" json:"-"`
Name string `xml:"name,attr" json:"name"`
Artists []Artist `xml:"index" json:"artist"`
}
type Indexes struct {
XMLName xml.Name `xml:"indexes" json:"-"`
Index []Index `xml:"indexes" json:"index"`
LastModified string `xml:"lastModified,attr" json:"lastModified"`
IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"`
XMLName xml.Name `xml:"indexes" json:"-"`
Index []Index `xml:"indexes" json:"index"`
LastModified string `xml:"lastModified,attr" json:"lastModified"`
IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"`
}
+1 -1
View File
@@ -3,9 +3,9 @@ package api_test
import (
"encoding/xml"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
"testing"
"github.com/deluan/gosonic/tests"
)
func TestCheckParams(t *testing.T) {