Commit c1a41f59 authored by Morgan McMillian's avatar Morgan McMillian

change CreateMessage to post json fixes issue #8 and #9

parent 01186e41
......@@ -23,6 +23,10 @@ type createChannel struct {
ACL ACL `json:"acl"`
}
type createMessage struct {
Text string `json:"text"`
}
// GetChannel retrieves the channel object from the channel ID
// https://pnut.io/docs/api/resources/channels/lookup#get-channels-id
func (c *Client) GetChannel(id string) (result ChannelResult, err error) {
......@@ -152,11 +156,15 @@ func (c *Client) GetMessagesOfChannel(id string) (result PostsResult, err error)
// CreateMessage creates a new message
// https://pnut.io/docs/api/resources/messages/lifecycle#post-channels-id-messages
func (c *Client) CreateMessage(id string, text string) (result PostResult, err error) {
v := url.Values{}
v.Set("text", text)
var message createMessage
message.Text = text
json, err := json.Marshal(message)
if err != nil {
return
}
responseCh := make(chan response)
c.queryQueue <- query{url: ChannelAPI + "/" + id + "/messages", form: v, data: &result, method: "POST", responseCh: responseCh}
c.queryQueue <- query{url: ChannelAPI + "/" + id + "/messages", data: &result, method: "POST", responseCh: responseCh, json: string(json)}
return result, (<-responseCh).err
}
......
......@@ -281,12 +281,15 @@ func TestDeleteMessage(t *testing.T) {
if err != nil {
t.Error(err)
}
// TODO need to put creaet into this when fixed
channelID := "178"
messageID := "106947"
channelID := "1001"
text := "golang rocks!"
client := NewClient(config.ClientID, "")
client.SetAccessToken(config.AccessToken)
message, err := client.DeleteMessage(channelID, messageID)
newmessage, err := client.CreateMessage(channelID, text)
if err != nil {
t.Error(err)
}
message, err := client.DeleteMessage(channelID, newmessage.Data.ID)
if err != nil {
t.Error(err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment