Skip to content

Commit 28bb680

Browse files
committed
feat(config): authorized reregister, get server device settings
1 parent 9be54a3 commit 28bb680

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

api.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ type CacophonyAPI struct {
6262

6363
// joinURL creates an absolute url with supplied baseURL, and all paths
6464
func joinURL(baseURL string, paths ...string) string {
65-
6665
u, err := url.Parse(baseURL)
6766
if err != nil {
6867
return ""
@@ -79,6 +78,7 @@ func (api *CacophonyAPI) getAPIURL() string {
7978
func (api *CacophonyAPI) getAuthURL() string {
8079
return joinURL(api.serverURL, authURL)
8180
}
81+
8282
func (api *CacophonyAPI) getRegURL() string {
8383
return joinURL(api.serverURL, apiBasePath, regURL)
8484
}
@@ -233,7 +233,6 @@ func (api *CacophonyAPI) authenticate() error {
233233
data["groupname"] = api.device.group
234234
}
235235
payload, err := json.Marshal(data)
236-
237236
if err != nil {
238237
return err
239238
}
@@ -294,7 +293,7 @@ func shaHash(r io.Reader) (string, error) {
294293
func (api *CacophonyAPI) UploadVideo(r io.Reader, data map[string]interface{}) (int, error) {
295294
buf := new(bytes.Buffer)
296295
w := multipart.NewWriter(buf)
297-
//This will write to fileBytes as it reads r to get the sha hash
296+
// This will write to fileBytes as it reads r to get the sha hash
298297
var fileBytes bytes.Buffer
299298
tee := io.TeeReader(r, &fileBytes)
300299
hash, err := shaHash(tee)
@@ -311,7 +310,6 @@ func (api *CacophonyAPI) UploadVideo(r io.Reader, data map[string]interface{}) (
311310

312311
// JSON encoded "data" parameter.
313312
dataBuf, err := json.Marshal(data)
314-
315313
if err != nil {
316314
return 0, err
317315
}
@@ -519,7 +517,7 @@ func handleHTTPResponse(resp *http.Response) error {
519517
return nil
520518
}
521519

522-
//formatTimestamp to time.RFC3339Nano format
520+
// formatTimestamp to time.RFC3339Nano format
523521
func formatTimestamp(t time.Time) string {
524522
return t.UTC().Format(time.RFC3339Nano)
525523
}
@@ -539,7 +537,7 @@ func (api *CacophonyAPI) GetSchedule() ([]byte, error) {
539537
return nil, err
540538
}
541539
req.Header.Set("Authorization", api.token)
542-
//client := new(http.Client)
540+
// client := new(http.Client)
543541

544542
resp, err := api.httpClient.Do(req)
545543
if err != nil {
@@ -562,7 +560,6 @@ func (api *CacophonyAPI) ReRegisterByAuthorized(newName, newGroup, newPassword,
562560
if err != nil {
563561
return err
564562
}
565-
log.Println("jsonAll", string(jsonAll))
566563
url := joinURL(api.serverURL, apiBasePath, "devices/reregister-authorized")
567564
req, err := http.NewRequest("POST", url, bytes.NewReader(jsonAll))
568565
if err != nil {
@@ -589,8 +586,6 @@ func (api *CacophonyAPI) ReRegisterByAuthorized(newName, newGroup, newPassword,
589586
name: newName,
590587
password: newPassword,
591588
}
592-
log.Println("respData.Token", respData.Token)
593-
log.Println("respData.ID", respData.ID)
594589

595590
api.token = respData.Token
596591
api.device.password = newPassword

0 commit comments

Comments
 (0)