-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile-images.go
47 lines (41 loc) · 932 Bytes
/
profile-images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package api
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
//RetrieveProfileImage retrieve a user or organization
//profile image information by its corresponding username
// API PATH: /profile_images
// Method: GET
func RetrieveProfileImage(ctx context.Context, username string) (*ProfileImageResponse, error) {
client := &http.Client{}
url := fmt.Sprintf("%s%s", baseURL, pathProfileImage)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
req.URL.Path += "/" + username
response, err := client.Do(req)
if err != nil {
return nil, err
}
defer response.Body.Close()
b, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
err = extractError(b)
if err != nil {
return nil, err
}
data := new(ProfileImageResponse)
err = json.Unmarshal(b, data)
if err != nil {
return nil, err
}
return data, nil
}