2016-04-19 04:40:49 +00:00
|
|
|
package bitbucketserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"crypto/md5"
|
2016-04-19 05:07:03 +00:00
|
|
|
"encoding/hex"
|
2016-04-20 18:59:47 +00:00
|
|
|
"fmt"
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
2016-04-19 04:40:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func avatarLink(email string) (url string) {
|
2016-04-19 05:07:03 +00:00
|
|
|
hasher := md5.New()
|
|
|
|
hasher.Write([]byte(strings.ToLower(email)))
|
|
|
|
emailHash := fmt.Sprintf("%v", hex.EncodeToString(hasher.Sum(nil)))
|
2016-04-20 18:59:47 +00:00
|
|
|
avatarURL := fmt.Sprintf("https://www.gravatar.com/avatar/%s.jpg", emailHash)
|
2016-04-19 04:40:49 +00:00
|
|
|
log.Info(avatarURL)
|
|
|
|
return avatarURL
|
|
|
|
}
|
|
|
|
|
|
|
|
func doPut(client *http.Client, url string, body []byte) {
|
|
|
|
request, err := http.NewRequest("PUT", url, bytes.NewBuffer(body))
|
2016-04-20 18:59:47 +00:00
|
|
|
request.Header.Add("Content-Type", "application/json")
|
2016-04-19 04:40:49 +00:00
|
|
|
response, err := client.Do(request)
|
|
|
|
if err != nil {
|
2016-04-19 16:47:02 +00:00
|
|
|
log.Error(err)
|
2016-04-19 04:40:49 +00:00
|
|
|
} else {
|
|
|
|
defer response.Body.Close()
|
|
|
|
contents, err := ioutil.ReadAll(response.Body)
|
|
|
|
if err != nil {
|
2016-04-19 16:47:02 +00:00
|
|
|
log.Error(err)
|
2016-04-19 04:40:49 +00:00
|
|
|
}
|
|
|
|
fmt.Println("The calculated length is:", len(string(contents)), "for the url:", url)
|
|
|
|
fmt.Println(" ", response.StatusCode)
|
|
|
|
hdr := response.Header
|
|
|
|
for key, value := range hdr {
|
|
|
|
fmt.Println(" ", key, ":", value)
|
|
|
|
}
|
|
|
|
fmt.Println(string(contents))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func doDelete(client *http.Client, url string) {
|
|
|
|
request, err := http.NewRequest("DELETE", url, nil)
|
|
|
|
response, err := client.Do(request)
|
|
|
|
if err != nil {
|
2016-04-19 16:47:02 +00:00
|
|
|
log.Error(err)
|
2016-04-19 04:40:49 +00:00
|
|
|
} else {
|
|
|
|
defer response.Body.Close()
|
|
|
|
contents, err := ioutil.ReadAll(response.Body)
|
|
|
|
if err != nil {
|
2016-04-19 16:47:02 +00:00
|
|
|
log.Error(err)
|
2016-04-19 04:40:49 +00:00
|
|
|
}
|
|
|
|
fmt.Println("The calculated length is:", len(string(contents)), "for the url:", url)
|
|
|
|
fmt.Println(" ", response.StatusCode)
|
|
|
|
hdr := response.Header
|
|
|
|
for key, value := range hdr {
|
|
|
|
fmt.Println(" ", key, ":", value)
|
|
|
|
}
|
|
|
|
fmt.Println(string(contents))
|
|
|
|
}
|
|
|
|
}
|