From 2026b473a63c2750cb7245f545205ff1d76f4624 Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Sun, 14 Feb 2016 19:09:04 -0500 Subject: Added documentation and clarity to Bridge.GetAllSchedules and Bridge.GetSchedule --- schedule.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'schedule.go') diff --git a/schedule.go b/schedule.go index 8c49de2..f35802d 100644 --- a/schedule.go +++ b/schedule.go @@ -31,7 +31,7 @@ type Schedule struct { ID string } -// Bridge.GetSchedules will get Alarms and Timers in a Schedule struct. +// Bridge.GetAllSchedules will get Alarms and Timers in a Schedule struct. func (bridge *Bridge) GetAllSchedules() ([]Schedule, error) { uri := fmt.Sprintf("/api/%s/schedules", bridge.Username) body, _, err := bridge.Get(uri) @@ -39,12 +39,13 @@ func (bridge *Bridge) GetAllSchedules() ([]Schedule, error) { return []Schedule{}, err } + // Each index key is the topmost element of the json array. + // Unmarshal the array, loop through each index key, and add it to the list schedules := map[string]Schedule{} err = json.Unmarshal(body, &schedules) if err != nil { return []Schedule{}, err } - scheduleList := []Schedule{} for key, value := range schedules { schedule := Schedule{} @@ -52,16 +53,12 @@ func (bridge *Bridge) GetAllSchedules() ([]Schedule, error) { schedule.ID = key scheduleList = append(scheduleList, schedule) } - - // for sched := range scheduleList { - // fmt.Println("\n\nScheduleoutput: ", scheduleList[sched]) - // } - return scheduleList, nil } // Bridge.GetSchedule will get the attributes for an individual schedule. // This is used as to optimize time when updating the state of a schedule item. +// Note: The ID is not an index, it's a unique key generated for each schedule. func (bridge *Bridge) GetSchedule(id string) (Schedule, error) { uri := fmt.Sprintf("/api/%s/schedules/%s", bridge.Username, id) body, _, err := bridge.Get(uri) -- cgit v1.2.3