work on #7 and #8

This commit is contained in:
Unknwon 2015-10-22 17:42:42 -04:00
parent 717e04de1e
commit 8068507b50
2 changed files with 13 additions and 1 deletions

View file

@ -14,7 +14,7 @@ import (
)
func Version() string {
return "0.0.2"
return "0.0.4"
}
// Client represents a Gogs API client.
@ -33,6 +33,11 @@ func NewClient(url, token string) *Client {
}
}
// SetHTTPClient replaces default http.Client with user given one.
func (c *Client) SetHTTPClient(client *http.Client) {
c.client = client
}
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) {
req, err := http.NewRequest(method, c.url+"/api/v1"+path, body)
if err != nil {

View file

@ -70,6 +70,13 @@ func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, e
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo)
}
// GetRepo returns information of a repository of given owner.
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
repo := new(Repository)
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame),
http.Header{"content-type": []string{"application/json"}}, nil, repo)
}
// DeleteRepo deletes a repository of user or organization.
func (c *Client) DeleteRepo(owner, repo string) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil)