mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
Add /bmx/registry/v1/servicesAvailability
This commit is contained in:
@@ -714,6 +714,7 @@ func setupRouter(server *handlers.Server) *chi.Mux {
|
||||
|
||||
r.Route("/bmx", func(r chi.Router) {
|
||||
r.Get("/registry/v1/services", server.HandleBMXRegistry)
|
||||
r.Get("/registry/v1/servicesAvailability", server.HandleBMXServicesAvailability)
|
||||
|
||||
r.Route("/tunein", func(r chi.Router) {
|
||||
r.Get("/v1/playback/station/{stationID}", server.HandleTuneInPlayback)
|
||||
|
||||
@@ -16,6 +16,7 @@ GET /accounts/{account}/devices/{device}/presets handlers.(
|
||||
GET /accounts/{account}/devices/{device}/recents handlers.(*Server).HandleMargeRecents-fm
|
||||
GET /accounts/{account}/full handlers.(*Server).HandleMargeAccountFull-fm
|
||||
GET /bmx/registry/v1/services handlers.(*Server).HandleBMXRegistry-fm
|
||||
GET /bmx/registry/v1/servicesAvailability handlers.(*Server).HandleBMXServicesAvailability-fm
|
||||
GET /bmx/tunein/v1/playback/episode/{podcastID} handlers.(*Server).HandleTuneInPlaybackPodcast-fm
|
||||
GET /bmx/tunein/v1/playback/episodes/{podcastID} handlers.(*Server).HandleTuneInPodcastInfo-fm
|
||||
GET /bmx/tunein/v1/playback/station/{stationID} handlers.(*Server).HandleTuneInPlayback-fm
|
||||
|
||||
@@ -33,6 +33,12 @@ func (s *Server) HandleBMXRegistry(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte(content))
|
||||
}
|
||||
|
||||
// HandleBMXServicesAvailability returns the BMX services availability.
|
||||
func (s *Server) HandleBMXServicesAvailability(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write(bmxServicesAvailabilityJSON)
|
||||
}
|
||||
|
||||
func (s *Server) writeBMXUnauthorized(w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHandleBMXServicesAvailability(t *testing.T) {
|
||||
r, _ := setupRouter("http://localhost:8001", nil)
|
||||
|
||||
req := httptest.NewRequest("GET", "/bmx/registry/v1/servicesAvailability", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("Expected status 200, got %d", w.Code)
|
||||
}
|
||||
|
||||
contentType := w.Header().Get("Content-Type")
|
||||
if contentType != "application/json" {
|
||||
t.Errorf("Expected Content-Type application/json, got %s", contentType)
|
||||
}
|
||||
|
||||
var resp map[string]interface{}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("Failed to unmarshal response: %v", err)
|
||||
}
|
||||
|
||||
services, ok := resp["services"].([]interface{})
|
||||
if !ok {
|
||||
t.Fatal("Response missing 'services' field")
|
||||
}
|
||||
|
||||
if len(services) != 2 {
|
||||
t.Errorf("Expected 2 services, got %d", len(services))
|
||||
}
|
||||
|
||||
foundTuneIn := false
|
||||
foundSiriusXM := false
|
||||
|
||||
for _, s := range services {
|
||||
service := s.(map[string]interface{})
|
||||
name := service["service"].(string)
|
||||
switch name {
|
||||
case "TUNEIN":
|
||||
foundTuneIn = true
|
||||
if service["canAdd"] != true {
|
||||
t.Errorf("TUNEIN: expected canAdd true, got %v", service["canAdd"])
|
||||
}
|
||||
if service["canRemove"] != false {
|
||||
t.Errorf("TUNEIN: expected canRemove false, got %v", service["canRemove"])
|
||||
}
|
||||
case "SIRIUSXM_EVEREST":
|
||||
foundSiriusXM = true
|
||||
if service["canAdd"] != false {
|
||||
t.Errorf("SIRIUSXM_EVEREST: expected canAdd false, got %v", service["canAdd"])
|
||||
}
|
||||
if service["canRemove"] != true {
|
||||
t.Errorf("SIRIUSXM_EVEREST: expected canRemove true, got %v", service["canRemove"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !foundTuneIn {
|
||||
t.Error("TUNEIN not found in servicesAvailability")
|
||||
}
|
||||
if !foundSiriusXM {
|
||||
t.Error("SIRIUSXM_EVEREST not found in servicesAvailability")
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ var mediaFS embed.FS
|
||||
//go:embed static/bmx_services.json
|
||||
var bmxServicesJSON []byte
|
||||
|
||||
//go:embed static/bmx_services_availability.json
|
||||
var bmxServicesAvailabilityJSON []byte
|
||||
|
||||
// Upstream source available at https://worldwide.bose.com/updates/soundtouch?serialnumber=_serial_
|
||||
// which results in a redirect to https://downloads.bose.com/ced/soundtouch/mr4_22097fe2/index.xml
|
||||
//
|
||||
|
||||
@@ -23,6 +23,7 @@ func setupRouter(targetURL string, ds *datastore.DataStore) (*chi.Mux, *Server)
|
||||
// Setup BMX for tests
|
||||
r.Route("/bmx", func(r chi.Router) {
|
||||
r.Get("/registry/v1/services", server.HandleBMXRegistry)
|
||||
r.Get("/registry/v1/servicesAvailability", server.HandleBMXServicesAvailability)
|
||||
r.Get("/tunein/v1/playback/station/{stationID}", server.HandleTuneInPlayback)
|
||||
r.Get("/tunein/v1/playback/episodes/{podcastID}", server.HandleTuneInPodcastInfo)
|
||||
r.Get("/tunein/v1/playback/episode/{podcastID}", server.HandleTuneInPlaybackPodcast)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"services": [
|
||||
{
|
||||
"canAdd": true,
|
||||
"canRemove": false,
|
||||
"service": "TUNEIN"
|
||||
},
|
||||
{
|
||||
"canAdd": false,
|
||||
"canRemove": true,
|
||||
"service": "SIRIUSXM_EVEREST"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user