~thrrgilag/woodstock

13b37a0e305f52091b10e7fcd3cabefe77f35cc6 — Morgan McMillian 2 years ago 6023731
implemented UploadAvatar and UploadCover
closes #2 and #4
4 files changed, 54 insertions(+), 47 deletions(-)

A avatar.jpeg
A cover.jpg
M users.go
M users_test.go
A avatar.jpeg => avatar.jpeg +0 -0
A cover.jpg => cover.jpg +0 -0
M users.go => users.go +11 -20
@@ 1,6 1,7 @@
package woodstock

import (
	"io"
	"net/url"
	"strconv"
	"strings"


@@ 101,17 102,12 @@ func (c *Client) GetAvatarURL(id string, v ...url.Values) (url string, err error
}

// UploadAvatar updates a user avatar
// this func will be updated
// https://pnut.io/docs/api/resources/users/profile#post-users-me-avatar
func (c *Client) UploadAvatar(avatar []byte) (result UserResult, err error) {
	return result, notSupported()
}

// UploadAvatarFromURL updates a users avatar from a URL
// this func will be updated
// https://pnut.io/docs/api/resources/users/profile#post-users-me-avatar
func (c *Client) UploadAvatarFromURL(url string) (result UserResult, err error) {
	return result, notSupported()
func (c *Client) UploadAvatar(params map[string]string, reader io.Reader) (result UserResult, err error) {
	params["field"] = "avatar"
	responseCh := make(chan response)
	c.queryQueue <- query{url: UserMeAPI + "/avatar", params: params, reader: reader, data: &result, method: "POST", responseCh: responseCh}
	return result, (<-responseCh).err
}

// GetCoverURL retireves a cover URL


@@ 131,17 127,12 @@ func (c *Client) GetCoverURL(id string, v ...url.Values) (url string, err error)
}

// UploadCover updates a cover image
// this func will be updated
// https://pnut.io/docs/api/resources/users/profile#post-users-me-cover
func (c *Client) UploadCover(cover []byte) (result UserResult, err error) {
	return result, notSupported()
}

// UploadCoverFromURL updates a cover image from URL
// this func will be updated
// https://pnut.io/docs/api/resources/users/profile#post-users-me-cover
func (c *Client) UploadCoverFromURL(url string) (result UserResult, err error) {
	return result, notSupported()
func (c *Client) UploadCover(params map[string]string, reader io.Reader) (result UserResult, err error) {
	params["field"] = "cover"
	responseCh := make(chan response)
	c.queryQueue <- query{url: UserMeAPI + "/cover", params: params, reader: reader, data: &result, method: "POST", responseCh: responseCh}
	return result, (<-responseCh).err
}

// GetFollowing retrieve following list

M users_test.go => users_test.go +43 -27
@@ 1,6 1,7 @@
package woodstock

import (
	"os"
	"testing"
	"time"
)


@@ 106,25 107,27 @@ func TestGetAvatarURL(t *testing.T) {
}

func TestUploadAvatar(t *testing.T) {
	// TODO verify test
	t.Logf("Not yet supported")
	// file, ferr := ioutil.ReadFile("avatar.png")
	// if ferr != nil {
	// 	t.Error(ferr)
	// }
	// client := NewClient(config.ClientID, "")
	// client.SetAccessToken(config.AccessToken)
	// user, err := client.UploadAvatar(file)
	// if err != nil {
	// 	t.Error(err)
	// }
	// t.Log(user.Data.Content.AvatarImage.Link)
	time.Sleep(Delay)
}

func TestUploadAvatarFromURL(t *testing.T) {
	// TODO implement test
	t.Logf("Not yet supported")
	config, err := GetConfig()
	if err != nil {
		t.Error(err)
	}
	fileName := "avatar.jpeg"
	filereader, err := os.Open(fileName)
	if err != nil {
		t.Error(err)
	}
	defer filereader.Close()
	params := map[string]string{
		"name":     fileName,
		"mimetype": "image/jpeg",
	}
	client := NewClient(config.ClientID, "")
	client.SetAccessToken(config.AccessToken)
	user, err := client.UploadAvatar(params, filereader)
	if err != nil {
		t.Error(err)
	}
	t.Logf(user.Data.Content.AvatarImage.Link)
	time.Sleep(Delay)
}



@@ 145,14 148,27 @@ func TestGetCoverURL(t *testing.T) {
}

func TestUploadCover(t *testing.T) {
	// TODO implement test
	t.Logf("Not yet supported")
	time.Sleep(Delay)
}

func TestUploadCoverFromURL(t *testing.T) {
	// TODO implement test
	t.Logf("Not yet supported")
	config, err := GetConfig()
	if err != nil {
		t.Error(err)
	}
	fileName := "cover.jpg"
	filereader, err := os.Open(fileName)
	if err != nil {
		t.Error(err)
	}
	defer filereader.Close()
	params := map[string]string{
		"name":     fileName,
		"mimetype": "image/jpeg",
	}
	client := NewClient(config.ClientID, "")
	client.SetAccessToken(config.AccessToken)
	user, err := client.UploadCover(params, filereader)
	if err != nil {
		t.Error(err)
	}
	t.Logf(user.Data.Content.CoverImage.Link)
	time.Sleep(Delay)
}