lume/endpoints.go

34 lines
751 B
Go
Raw Normal View History

2020-02-24 03:01:12 +00:00
package lifx
import (
"fmt"
"net/url"
"path"
)
func BuildURL(rawurl, rawpath string) string {
u, _ := url.Parse(rawurl)
u.Path = path.Join(u.Path, rawpath)
return u.String()
}
var (
Endpoint = "https://api.lifx.com/v1"
2020-02-29 01:34:59 +00:00
EndpointState = func(selector string) string {
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/state", selector))
}
2020-02-29 06:08:39 +00:00
EndpointStates = func() string {
return BuildURL(Endpoint, "/lights/states")
}
2020-03-01 05:15:39 +00:00
EndpointColor = func(color string) string {
u, _ := url.Parse(BuildURL(Endpoint, "/color"))
q := u.Query()
q.Set("string", color)
u.RawQuery = q.Encode()
return u.String()
}
2020-02-29 01:34:59 +00:00
EndpointToggle = func(selector string) string {
return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/toggle", selector))
}
2020-02-24 03:01:12 +00:00
)