|
@ -92,6 +92,10 @@ func (c *Client) UpdateResource(ctx context.Context, link ResourceLink, update R |
|
|
return c.put(ctx, link.Path(), update, nil) |
|
|
return c.put(ctx, link.Path(), update, nil) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Client) DeleteResource(ctx context.Context, link ResourceLink) error { |
|
|
|
|
|
return c.delete(ctx, link.Path(), nil) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (c *Client) LegacyDiscover(ctx context.Context, kind string) error { |
|
|
func (c *Client) LegacyDiscover(ctx context.Context, kind string) error { |
|
|
return c.legacyPost(ctx, kind, nil, nil) |
|
|
return c.legacyPost(ctx, kind, nil, nil) |
|
|
} |
|
|
} |
|
@ -268,6 +272,36 @@ func (c *Client) post(ctx context.Context, path string, body interface{}, target |
|
|
return json.NewDecoder(res.Body).Decode(&target) |
|
|
return json.NewDecoder(res.Body).Decode(&target) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Client) delete(ctx context.Context, path string, target interface{}) error { |
|
|
|
|
|
select { |
|
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
|
return ctx.Err() |
|
|
|
|
|
case <-c.ch: |
|
|
|
|
|
defer func() { |
|
|
|
|
|
c.ch <- struct{}{} |
|
|
|
|
|
}() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("PUT", fmt.Sprintf("https://%s/%s", c.host, path), nil) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
req.Header.Set("hue-application-key", c.token) |
|
|
|
|
|
|
|
|
|
|
|
res, err := httpClient.Do(req.WithContext(ctx)) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
defer res.Body.Close() |
|
|
|
|
|
|
|
|
|
|
|
if target == nil { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return json.NewDecoder(res.Body).Decode(&target) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (c *Client) legacyPost(ctx context.Context, resource string, body interface{}, target interface{}) error { |
|
|
func (c *Client) legacyPost(ctx context.Context, resource string, body interface{}, target interface{}) error { |
|
|
select { |
|
|
select { |
|
|
case <-ctx.Done(): |
|
|
case <-ctx.Done(): |
|
|