ref(client): add a Get method helper

pull/419/head
Adam Reese 9 years ago
parent d91df39cba
commit fa6b34aa6b

@ -98,6 +98,14 @@ func (c *Client) agent() string {
return fmt.Sprintf("helm/%s", version.Version) return fmt.Sprintf("helm/%s", version.Version)
} }
func (c *Client) Get(endpoint string, v interface{}) error {
return c.CallService(endpoint, "GET", &v, nil)
}
func (c *Client) Delete(endpoint string, v interface{}) error {
return c.CallService(endpoint, "DELETE", &v, nil)
}
// CallService is a low-level function for making an API call. // CallService is a low-level function for making an API call.
// //
// This calls the service and then unmarshals the returned data into dest. // This calls the service and then unmarshals the returned data into dest.

@ -102,5 +102,6 @@ func TestUserAgent(t *testing.T) {
} }
}), }),
} }
fc.setup().ListDeployments() var nop struct{}
fc.setup().Get("/", &nop)
} }

@ -32,11 +32,8 @@ import (
// ListDeployments lists the deployments in DM. // ListDeployments lists the deployments in DM.
func (c *Client) ListDeployments() ([]string, error) { func (c *Client) ListDeployments() ([]string, error) {
var l []string var l []string
if err := c.CallService("deployments", "GET", &l, nil); err != nil { err := c.Get("deployments", &l)
return nil, err return l, err
}
return l, nil
} }
// PostChart sends a chart to DM for deploying. // PostChart sends a chart to DM for deploying.
@ -94,19 +91,15 @@ func (c *Client) PostChart(filename, deployname string) (string, error) {
// GetDeployment retrieves the supplied deployment // GetDeployment retrieves the supplied deployment
func (c *Client) GetDeployment(name string) (*common.Deployment, error) { func (c *Client) GetDeployment(name string) (*common.Deployment, error) {
var deployment *common.Deployment var deployment *common.Deployment
if err := c.CallService(fancypath.Join("deployments", name), "GET", &deployment, nil); err != nil { err := c.Get(fancypath.Join("deployments", name), &deployment)
return nil, err return deployment, err
}
return deployment, nil
} }
// DeleteDeployment deletes the supplied deployment // DeleteDeployment deletes the supplied deployment
func (c *Client) DeleteDeployment(name string) (*common.Deployment, error) { func (c *Client) DeleteDeployment(name string) (*common.Deployment, error) {
var deployment *common.Deployment var deployment *common.Deployment
if err := c.CallService(filepath.Join("deployments", name), "DELETE", &deployment, nil); err != nil { err := c.Delete(filepath.Join("deployments", name), &deployment)
return nil, err return deployment, err
}
return deployment, nil
} }
// PostDeployment posts a deployment object to the manager service. // PostDeployment posts a deployment object to the manager service.

Loading…
Cancel
Save