Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose s.request as s.RequestRaw so one can send JSON directly #1560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ func (s *Session) RequestWithBucketID(method, urlStr string, data interface{}, b
}
}

return s.request(method, urlStr, "application/json", body, bucketID, 0, options...)
return s.RequestRaw(method, urlStr, "application/json", body, bucketID, 0, options...)
}

// request makes a (GET/POST/...) Requests to Discord REST API.
// RequestRaw makes a (GET/POST/...) Requests to Discord REST API.
// Preferably use the other Request* methods but this lets you send JSON directly if that's what you have.
// Sequence is the sequence number, if it fails with a 502 it will
// retry with sequence+1 until it either succeeds or sequence >= session.MaxRestRetries
func (s *Session) request(method, urlStr, contentType string, b []byte, bucketID string, sequence int, options ...RequestOption) (response []byte, err error) {
func (s *Session) RequestRaw(method, urlStr, contentType string, b []byte, bucketID string, sequence int, options ...RequestOption) (response []byte, err error) {
if bucketID == "" {
bucketID = strings.SplitN(urlStr, "?", 2)[0]
}
Expand Down Expand Up @@ -1012,7 +1013,7 @@ func (s *Session) GuildMemberRoleRemove(guildID, userID, roleID string, options
// guildID : The ID of a Guild.
func (s *Session) GuildChannels(guildID string, options ...RequestOption) (st []*Channel, err error) {

body, err := s.request("GET", EndpointGuildChannels(guildID), "", nil, EndpointGuildChannels(guildID), 0, options...)
body, err := s.RequestRaw("GET", EndpointGuildChannels(guildID), "", nil, EndpointGuildChannels(guildID), 0, options...)
if err != nil {
return
}
Expand Down Expand Up @@ -1713,7 +1714,7 @@ func (s *Session) ChannelMessageSendComplex(channelID string, data *MessageSend,
if encodeErr != nil {
return st, encodeErr
}
response, err = s.request("POST", endpoint, contentType, body, endpoint, 0, options...)
response, err = s.RequestRaw("POST", endpoint, contentType, body, endpoint, 0, options...)
} else {
response, err = s.RequestWithBucketID("POST", endpoint, data, endpoint, options...)
}
Expand Down Expand Up @@ -1825,7 +1826,7 @@ func (s *Session) ChannelMessageEditComplex(m *MessageEdit, options ...RequestOp
if encodeErr != nil {
return st, encodeErr
}
response, err = s.request("PATCH", endpoint, contentType, body, EndpointChannelMessage(m.Channel, ""), 0, options...)
response, err = s.RequestRaw("PATCH", endpoint, contentType, body, EndpointChannelMessage(m.Channel, ""), 0, options...)
} else {
response, err = s.RequestWithBucketID("PATCH", endpoint, m, EndpointChannelMessage(m.Channel, ""), options...)
}
Expand Down Expand Up @@ -2362,7 +2363,7 @@ func (s *Session) webhookExecute(webhookID, token string, wait bool, threadID st
return st, encodeErr
}

response, err = s.request("POST", uri, contentType, body, uri, 0, options...)
response, err = s.RequestRaw("POST", uri, contentType, body, uri, 0, options...)
} else {
response, err = s.RequestWithBucketID("POST", uri, data, uri, options...)
}
Expand Down Expand Up @@ -2422,7 +2423,7 @@ func (s *Session) WebhookMessageEdit(webhookID, token, messageID string, data *W
return nil, err
}

response, err = s.request("PATCH", uri, contentType, body, uri, 0, options...)
response, err = s.RequestRaw("PATCH", uri, contentType, body, uri, 0, options...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2642,7 +2643,7 @@ func (s *Session) ForumThreadStartComplex(channelID string, threadData *ThreadSt
return th, encodeErr
}

response, err = s.request("POST", endpoint, contentType, body, endpoint, 0, options...)
response, err = s.RequestRaw("POST", endpoint, contentType, body, endpoint, 0, options...)
} else {
response, err = s.RequestWithBucketID("POST", endpoint, data, endpoint, options...)
}
Expand Down Expand Up @@ -3072,7 +3073,7 @@ func (s *Session) InteractionRespond(interaction *Interaction, resp *Interaction
return err
}

_, err = s.request("POST", endpoint, contentType, body, endpoint, 0, options...)
_, err = s.RequestRaw("POST", endpoint, contentType, body, endpoint, 0, options...)
return err
}

Expand Down
Loading