diff --git a/config.go b/config.go index a26a051..cbb78fa 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,39 @@ package main +import ( + "bytes" + "encoding/json" + "io/ioutil" + "net/http" +) + // Config hue api config type Config struct { Username string `yaml:name` Password string `yaml:userpassword` } + +// createNewUser will create a new user. This should be called only of there's none in the yaml config. +func (c *Config) createNewUser() { + // TODO: read/create the url + url := "http://192.168.178.46/api" + + var reqBody = []byte(`{"devicetype": "go-hue-interface#Philips hue"}`) + req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBody)) + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + panic(err) + } + defer resp.Body.Close() + + fmt.Println("response Status:", resp.Status) + fmt.Println("response Headers:", resp.Header) + body, _ := ioutil.ReadAll(resp.Body) + fmt.Println("response Body:", string(body)) + + json.Unmarshal([]byte(str), &res) + fmt.Println(res) + fmt.Println(res.Fruits[0]) +} diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..78a28e2 --- /dev/null +++ b/config.yaml @@ -0,0 +1,3 @@ +DeviceAddr: "192.168.178.46" +User: "nX1ye7AMQoQswiiJdxyw-92-RNhIwicXiQRg7AtF" +UserKey: "" \ No newline at end of file diff --git a/main.go b/main.go index 0cc0285..3862437 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,11 @@ package main -import "fmt" +import ( + "fmt" +) const VERSION = "0.1.2" func main() { fmt.Printf("go-hue-interface v. %s \n", VERSION) -} +} \ No newline at end of file