Tune CheckNotifications for api change (#308)

notification Check now always return json

make fmt relicts

CheckNotifications: one api call is enouth

add getResponseWithStatus to handle Response customized based on Status

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/308
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
6543 2020-04-14 13:29:44 +00:00 committed by Andrew Thornton
parent 2f920dbb01
commit 50efd911c8
3 changed files with 5 additions and 13 deletions

View File

@ -6,7 +6,6 @@ package gitea
import (
"fmt"
"net/http"
"net/url"
"time"
)
@ -67,18 +66,11 @@ func (c *Client) CheckNotifications() (int64, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
return 0, err
}
status, err := c.getStatusCode("GET", "/notifications/new", nil, nil)
if err != nil || status == http.StatusNoContent {
return 0, err
}
new := struct {
New int64 `json:"new"`
}{}
if err := c.getParsedResponse("GET", "/notifications/new", nil, nil, &new); err != nil {
return 0, err
}
return new.New, nil
return new.New, c.getParsedResponse("GET", "/notifications/new", jsonHeader, nil, &new)
}
// GetNotification get notification thread by ID

View File

@ -28,8 +28,8 @@ type ListOauth2Option struct {
// CreateOauth2Option required options for creating an Application
type CreateOauth2Option struct {
Name string `json:"name"`
RedirectURIs []string `json:"redirect_uris"`
Name string `json:"name"`
RedirectURIs []string `json:"redirect_uris"`
}
// CreateOauth2 create an Oauth2 Application and returns a completed Oauth2 object.
@ -56,7 +56,7 @@ func (c *Client) ListOauth2(opt ListOauth2Option) ([]*Oauth2, error) {
}
// DeleteOauth2 delete an Oauth2 application by name
func (c *Client) DeleteOauth2(oauth2id int64) error {
func (c *Client) DeleteOauth2(oauth2id int64) error {
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
return e
}

View File

@ -18,7 +18,7 @@ func TestOauth2(t *testing.T) {
user := createTestUser(t, "oauth2_user", c)
c.SetSudo(user.UserName)
newApp, err := c.CreateOauth2(CreateOauth2Option{Name: "test", RedirectURIs: []string{"http://test/test",}})
newApp, err := c.CreateOauth2(CreateOauth2Option{Name: "test", RedirectURIs: []string{"http://test/test"}})
assert.NoError(t, err)
assert.NotNil(t, newApp)
assert.EqualValues(t, "test", newApp.Name)