...
 
Commits (3)
......@@ -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)
}
......
......@@ -8,7 +8,7 @@ type ClientInfoResult struct {
// GetClient retrieves client object based on the id
// https://pnut.io/docs/api/resources/clients#get-clients-id
func (c *Client) GetClient(id string) (result ClientInfosResult, err error) {
func (c *Client) GetClient(id string) (result ClientInfoResult, err error) {
responseCh := make(chan response)
c.queryQueue <- query{url: ClientAPI + "/" + id, data: &result, method: "GET", responseCh: responseCh}
return result, (<-responseCh).err
......
......@@ -12,6 +12,6 @@ type MarkersResult struct {
// https://pnut.io/docs/api/resources/stream-marker#post-markers
func (c *Client) SetMarker(json string) (result MarkersResult, err error) {
responseCh := make(chan response)
c.queryQueue <- query{url: MarkerAPI, data: &result, method: "PUT", responseCh: responseCh, json: json}
c.queryQueue <- query{url: MarkerAPI, data: &result, method: "POST", responseCh: responseCh, json: json}
return result, (<-responseCh).err
}
......@@ -10,7 +10,7 @@ func TestSetMarker(t *testing.T) {
if err != nil {
t.Error(err)
}
marker := `{"id":"106930","name":"channel:1001"}`
marker := `[{"id":"106930","name":"channel:1001"}]`
client := NewClient(config.ClientID, "")
client.SetAccessToken(config.AccessToken)
res, err := client.SetMarker(marker)
......