1
+ local json = require " st.json"
1
2
local log = require " log"
2
- local net_url = require " net.url"
3
3
local st_utils = require " st.utils"
4
- local json = require " st.json"
5
4
6
5
local RestClient = require " lunchbox.rest"
7
6
@@ -13,11 +12,13 @@ local RestClient = require "lunchbox.rest"
13
12
--- @return string | nil partial contents of partial read if successful
14
13
local function process_rest_response (response , err , partial , err_callback )
15
14
if err == nil and response == nil then
16
- log .error (st_utils .stringify_table ({
17
- resp = response ,
18
- maybe_err = err ,
19
- maybe_partial = partial ,
20
- }, " [SonosRestApi] Unexpected nil for both response and error processing REST reply" , false ))
15
+ log .error (
16
+ st_utils .stringify_table ({
17
+ resp = response ,
18
+ maybe_err = err ,
19
+ maybe_partial = partial ,
20
+ }, " [SonosRestApi] Unexpected nil for both response and error processing REST reply" , false )
21
+ )
21
22
end
22
23
if err ~= nil then
23
24
if type (err_callback ) == " function" then
71
72
local SonosRestApi = {}
72
73
73
74
--- Query a Sonos Group IP address for individual player info
74
- --- @param ip_or_url string | table
75
- --- @param ... unknown
75
+ --- @param url table a URL table created by ` net_url `
76
+ --- @param headers table<string,string> ?
76
77
--- @return SonosDiscoveryInfo | SonosErrorResponse | nil
77
78
--- @return string | nil error
78
- --- @overload fun ( ip_or_url : table , headers : table<string,string> ): SonosDiscoveryInfo ?, string ?
79
- --- @overload fun ( ip_or_url : string , port : number , headers : table<string,string> ): SonosDiscoveryInfo ?, string ?
80
- function SonosRestApi .get_player_info (ip_or_url , ...)
81
- local url
82
- local headers
83
- if type (ip_or_url ) == " table" then
84
- headers = select (1 , ... )
85
- ip_or_url .path = " /api/v1/players/local/info"
86
- url = ip_or_url
87
- else
88
- local port = select (1 , ... )
89
- headers = select (2 , ... )
90
- url = net_url .parse (string.format (" https://%s:%s/api/v1/players/local/info" , ip_or_url , port ))
91
- end
79
+ function SonosRestApi .get_player_info (url , headers )
80
+ url .path = " /api/v1/players/local/info"
92
81
return process_rest_response (RestClient .one_shot_get (url , headers ))
93
82
end
94
83
95
- --- @param ip_or_url string | table
96
- --- @param ... unknown
84
+ --- @param url table a URL table created by ` net_url`
85
+ --- @param household HouseholdId
86
+ --- @param headers table<string,string> ?
97
87
--- @return SonosGroupsResponseBody | SonosErrorResponse | nil response
98
88
--- @return nil | string error
99
- --- @overload fun ( ip_or_url : table , household : HouseholdId , headers : table<string,string> ?): SonosGroupsResponseBody ?, string ?
100
- --- @overload fun ( ip_or_url : string , port : number , household : HouseholdId , headers : table<string,string> ?): SonosGroupsResponseBody ?, string ?
101
- function SonosRestApi .get_groups_info (ip_or_url , ...)
102
- local url
103
- local headers
104
- if type (ip_or_url ) == " table" then
105
- local household = select (1 , ... )
106
- headers = select (2 , ... )
107
- ip_or_url .path = string.format (" /api/v1/households/%s/groups" , household )
108
- url = ip_or_url
109
- else
110
- local port = select (1 , ... )
111
- local household = select (2 , ... )
112
- headers = select (3 , ... )
113
- url = net_url .parse (string.format (" https://%s:%s/api/v1/households/%s/groups" , ip_or_url , port , household ))
114
- end
89
+ function SonosRestApi .get_groups_info (url , household , headers )
90
+ url .path = string.format (" /api/v1/households/%s/groups" , household )
115
91
return process_rest_response (RestClient .one_shot_get (url , headers ))
116
92
end
117
93
118
- --- @param ip_or_url string | table
119
- --- @param ... unknown
94
+ --- @param url table a URL table created by ` net_url`
95
+ --- @param household HouseholdId
96
+ --- @param headers table<string,string> ?
120
97
--- @return SonosFavoritesResponseBody | SonosErrorResponse | nil response
121
98
--- @return nil | string error
122
- --- @overload fun ( ip_or_url : table , household : HouseholdId , headers : table<string,string> ?): SonosFavoritesResponseBody ?, string ?
123
- --- @overload fun ( ip_or_url : string , port : number , household : HouseholdId , headers : table<string,string> ?): SonosFavoritesResponseBody ?, string ?
124
- function SonosRestApi .get_favorites (ip_or_url , ...)
125
- local url
126
- local headers
127
- if type (ip_or_url ) == " table" then
128
- local household = select (1 , ... )
129
- headers = select (2 , ... )
130
- ip_or_url .path = string.format (" /api/v1/households/%s/favorites" , household )
131
- url = ip_or_url
132
- else
133
- local port = select (1 , ... )
134
- local household = select (2 , ... )
135
- headers = select (3 , ... )
136
- url = net_url .parse (string.format (" https://%s:%s/api/v1/households/%s/favorites" , ip_or_url , port , household ))
137
- end
99
+ function SonosRestApi .get_favorites (url , household , headers )
100
+ url .path = string.format (" /api/v1/households/%s/favorites" , household )
138
101
return process_rest_response (RestClient .one_shot_get (url , headers ))
139
102
end
140
103
0 commit comments