Updated Auth Token usage

PostBotMessage no longer requires/uses an auth token
This commit is contained in:
densestvoid 2020-08-23 19:28:50 -04:00
parent bd76de2ffe
commit 010fd832ac
13 changed files with 48 additions and 43 deletions

View File

@ -44,7 +44,7 @@ func (c *Client) IndexBlock(userID ID) ([]*Block, error) {
var resp struct {
Blocks []*Block `json:"blocks"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -77,7 +77,7 @@ func (c *Client) BlockBetween(userID, otherUserID ID) (bool, error) {
var resp struct {
Between bool `json:"between"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return false, err
}
@ -111,7 +111,7 @@ func (c *Client) CreateBlock(userID, otherUserID ID) (*Block, error) {
var resp struct {
Block *Block `json:"block"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -142,7 +142,7 @@ func (c *Client) Unblock(userID, otherUserID ID) error {
query.Set("otherUser", otherUserID.String())
URL.RawQuery = query.Encode()
err = c.do(httpReq, nil)
err = c.doWithAuthToken(httpReq, nil)
if err != nil {
return err
}

View File

@ -52,7 +52,7 @@ func (c *Client) CreateBot(bot *Bot) (*Bot, error) {
httpReq.PostForm = data
var resp Bot
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -108,7 +108,7 @@ func (c *Client) IndexBots() ([]*Bot, error) {
}
var resp []*Bot
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -139,5 +139,5 @@ func (c *Client) DestroyBot(botID ID) error {
httpReq.PostForm = data
return c.do(httpReq, nil)
return c.doWithAuthToken(httpReq, nil)
}

View File

@ -51,10 +51,11 @@ func TestBotsAPISuite(t *testing.T) {
}
func botsTestRouter() *mux.Router {
router := mux.NewRouter().Queries("token", "").Subrouter()
router := mux.NewRouter()
authRouter := router.Queries("token", "").Subrouter()
// Create
router.Path("/bots").
authRouter.Path("/bots").
Methods("POST").
Name("CreateBot").
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
@ -84,7 +85,7 @@ func botsTestRouter() *mux.Router {
})
// Index
router.Path("/bots").
authRouter.Path("/bots").
Methods("GET").
Name("IndexBots").
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
@ -108,7 +109,7 @@ func botsTestRouter() *mux.Router {
})
// Destroy
router.Path("/bots/destroy").
authRouter.Path("/bots/destroy").
Methods("POST").
Name("DestroyBot").
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {

View File

@ -52,7 +52,7 @@ func (c *Client) IndexChats(req *IndexChatsQuery) ([]*Chat, error) {
URL.RawQuery = query.Encode()
var resp []*Chat
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}

View File

@ -59,11 +59,6 @@ func (r response) UnmarshalJSON(bs []byte) error {
}
func (c Client) do(req *http.Request, i interface{}) error {
URL := req.URL
query := URL.Query()
query.Set("token", c.authorizationToken)
URL.RawQuery = query.Encode()
getResp, err := c.httpClient.Do(req)
if err != nil {
return err
@ -95,3 +90,12 @@ func (c Client) do(req *http.Request, i interface{}) error {
return nil
}
func (c Client) doWithAuthToken(req *http.Request, i interface{}) error {
URL := req.URL
query := URL.Query()
query.Set("token", c.authorizationToken)
URL.RawQuery = query.Encode()
return c.do(req, i)
}

View File

@ -83,7 +83,7 @@ func (c *Client) IndexDirectMessages(otherUserID ID, req *IndexDirectMessagesQue
}
var resp IndexDirectMessagesResponse
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return IndexDirectMessagesResponse{}, err
}
@ -136,7 +136,7 @@ func (c *Client) CreateDirectMessage(m *Message) (*Message, error) {
var resp struct {
*Message `json:"message"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}

View File

@ -105,7 +105,7 @@ func (c *Client) IndexGroups(req *GroupsQuery) ([]*Group, error) {
URL.RawQuery = query.Encode()
var resp []*Group
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -127,7 +127,7 @@ func (c *Client) FormerGroups() ([]*Group, error) {
}
var resp []*Group
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -154,7 +154,7 @@ func (c *Client) ShowGroup(groupID ID) (*Group, error) {
}
var resp Group
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -195,7 +195,7 @@ func (c *Client) CreateGroup(gs GroupSettings) (*Group, error) {
httpReq.PostForm = data
var resp Group
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -241,7 +241,7 @@ func (c *Client) UpdateGroup(groupID ID, gs GroupSettings) (*Group, error) {
httpReq.PostForm = data
var resp Group
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -269,7 +269,7 @@ func (c *Client) DestroyGroup(groupID ID) error {
return err
}
return c.do(httpReq, nil)
return c.doWithAuthToken(httpReq, nil)
}
///// Join /////
@ -292,7 +292,7 @@ func (c *Client) JoinGroup(groupID ID, shareToken string) (*Group, error) {
}
var resp Group
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -321,7 +321,7 @@ func (c *Client) RejoinGroup(groupID ID) (*Group, error) {
httpReq.PostForm = data
var resp Group
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -357,7 +357,7 @@ func (c *Client) ChangeGroupOwner(reqs ChangeOwnerRequest) (ChangeOwnerResult, e
Results []ChangeOwnerResult `json:"results"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return ChangeOwnerResult{}, err
}

View File

@ -60,7 +60,7 @@ func (c *Client) IndexLeaderboard(groupID ID, p period) ([]*Message, error) {
var resp struct {
Messages []*Message `json:"messages"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -90,7 +90,7 @@ func (c *Client) MyLikesLeaderboard(groupID ID) ([]*Message, error) {
var resp struct {
Messages []*Message `json:"messages"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -120,7 +120,7 @@ func (c *Client) MyHitsLeaderboard(groupID ID) ([]*Message, error) {
var resp struct {
Messages []*Message `json:"messages"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}

View File

@ -37,7 +37,7 @@ func (c *Client) CreateLike(conversationID, messageID ID) error {
return err
}
return c.do(httpReq, nil)
return c.doWithAuthToken(httpReq, nil)
}
// Destroy
@ -59,5 +59,5 @@ func (c *Client) DestroyLike(conversationID, messageID ID) error {
return err
}
return c.do(httpReq, nil)
return c.doWithAuthToken(httpReq, nil)
}

View File

@ -66,7 +66,7 @@ func (c *Client) AddMembers(groupID ID, members ...*Member) (string, error) {
ResultsID string `json:"result_id"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return "", err
}
@ -104,7 +104,7 @@ func (c *Client) AddMembersResults(groupID ID, resultID string) ([]*Member, erro
Members []*Member `json:"members"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -133,7 +133,7 @@ func (c *Client) RemoveMember(groupID, membershipID ID) error {
return err
}
return c.do(httpReq, nil)
return c.doWithAuthToken(httpReq, nil)
}
///// Update /////
@ -165,7 +165,7 @@ func (c *Client) UpdateMember(groupID ID, nickname string) (*Member, error) {
var resp Member
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}

View File

@ -110,7 +110,7 @@ func (c *Client) IndexMessages(groupID ID, req *IndexMessagesQuery) (IndexMessag
URL.RawQuery = query.Encode()
var resp IndexMessagesResponse
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return IndexMessagesResponse{}, err
}
@ -165,7 +165,7 @@ func (c *Client) CreateMessage(groupID ID, m *Message) (*Message, error) {
var resp struct {
*Message `json:"message"`
}
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}

View File

@ -50,7 +50,7 @@ func (c *Client) CreateSMSMode(duration int, registrationID *ID) error {
httpReq.PostForm = data
err = c.do(httpReq, nil)
err = c.doWithAuthToken(httpReq, nil)
if err != nil {
return err
}
@ -73,5 +73,5 @@ func (c *Client) DeleteSMSMode() error {
return err
}
return c.do(httpReq, nil)
return c.doWithAuthToken(httpReq, nil)
}

View File

@ -39,7 +39,7 @@ func (c *Client) MyUser() (*User, error) {
}
var resp User
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}
@ -96,7 +96,7 @@ func (c *Client) UpdateMyUser(us UserSettings) (*User, error) {
httpReq.PostForm = data
var resp User
err = c.do(httpReq, &resp)
err = c.doWithAuthToken(httpReq, &resp)
if err != nil {
return nil, err
}