This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
98 lines (93 loc) · 2.58 KB
/
user.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package slideshare
import (
"encoding/xml"
"io/ioutil"
"net/http"
"strconv"
)
// GetUserFavorites needs username of user whose Favorites are being requested.
func (s *Service) GetUserFavorites(username_for string) (UserFavorites, error) {
args := make(map[string]string)
args["username_for"] = username_for
url := s.generateUrl("get_user_favorites", args)
resp, err := http.Get(url)
if err != nil {
return UserFavorites{}, err
}
favorites := UserFavorites{}
responseBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err == nil {
xml.Unmarshal([]byte(responseBody), &favorites)
}
return favorites, err
}
// GetUserContacts needs username of user whose Contacts are being requested.
// You can 1 additional parameter int to specify number of items to return.
func (s *Service) GetUserContacts(username_for string, limitOffset ...int) (UserContacts, error) {
args := make(map[string]string)
if limitOffset != nil {
switch len(limitOffset) {
case 1:
args["limit"] = strconv.Itoa(limitOffset[0])
break
case 2:
args["limit"] = strconv.Itoa(limitOffset[0])
args["offset"] = strconv.Itoa(limitOffset[1])
break
default:
}
}
args["username_for"] = username_for
url := s.generateUrl("get_user_contacts", args)
resp, err := http.Get(url)
if err != nil {
return UserContacts{}, err
}
contacts := UserContacts{}
responseBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err == nil {
xml.Unmarshal([]byte(responseBody), &contacts)
}
return contacts, err
}
// GetUserTags needs username and password of the requesting user.
func (s *Service) GetUserTags(username string, password string) (Tags, error) {
args := make(map[string]string)
args["username"] = username
args["password"] = password
url := s.generateUrl("get_user_tags", args)
resp, err := http.Get(url)
if err != nil {
return Tags{}, err
}
tags := Tags{}
responseBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err == nil {
xml.Unmarshal([]byte(responseBody), &tags)
}
return tags, err
}
/*
// Returns user groups
// username_for required, username of user whose groups are being requested
func (s *Service) GetUserGroups(username_for string, additionalParams ...string) (Groups, error) {
args := make(map[string]string)
args["username_for"] = username_for
url := s.generateUrl("get_user_groups", args)
resp, err := http.Get(url)
if err != nil {
return Groups{}, err
}
groups := Groups{}
responseBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err == nil {
fmt.Println(responseBody)
//xml.Unmarshal([]byte(responseBody), &groups)
}
return groups, err
}
*/