7
// The Root type provides the entrance for the Launchpad API.
12
// Me returns the Person authenticated into Lauchpad in the current session.
13
func (root *Root) Me() (*Person, error) {
14
me, err := root.Location("/people/+me").Get(nil)
18
return &Person{me}, nil
21
// Member returns the Team or Person with the provided name or username.
22
func (root *Root) Member(name string) (Member, error) {
23
v, err := root.Location("/~" + url.QueryEscape(name)).Get(nil)
27
if v.BoolField("is_team") {
30
return &Person{v}, nil
33
// FindPeople returns a PersonList containing all Person accounts whose
34
// Name, DisplayName or email address match text.
35
func (root *Root) FindPeople(text string) (*PersonList, error) {
36
v, err := root.Location("/people").Get(Params{"ws.op": "findPerson", "text": text})
40
return &PersonList{v}, nil
43
// FindTeams returns a TeamList containing all Team accounts whose
44
// Name, DisplayName or email address match text.
45
func (root *Root) FindTeams(text string) (*TeamList, error) {
46
v, err := root.Location("/people").Get(Params{"ws.op": "findTeam", "text": text})
50
return &TeamList{v}, nil
53
// FindMembers returns a MemberList containing all Person or Team accounts
54
// whose Name, DisplayName or email address match text.
55
func (root *Root) FindMembers(text string) (*MemberList, error) {
56
v, err := root.Location("/people").Get(Params{"ws.op": "find", "text": text})
60
return &MemberList{v}, nil
63
// The MemberList type encapsulates a mixed list containing Person and Team
64
// elements for iteration.
65
type MemberList struct {
69
// For iterates over the list of people and teams and calls f for each one.
70
// If f returns a non-nil error, iteration will stop and the error will be
71
// returned as the result of For.
72
func (list *MemberList) For(f func(v Member) error) error {
73
return list.Value.For(func(v *Value) error {
74
if v.BoolField("is_team") {
81
// The PersonList type encapsulates a list of Person elements for iteration.
82
type PersonList struct {
86
// For iterates over the list of people and calls f for each one. If f
87
// returns a non-nil error, iteration will stop and the error will be
88
// returned as the result of For.
89
func (list *PersonList) For(f func(p *Person) error) error {
90
return list.Value.For(func(v *Value) error {
95
// The TeamList type encapsulates a list of Team elements for iteration.
96
type TeamList struct {
100
// For iterates over the list of teams and calls f for each one. If f
101
// returns a non-nil error, iteration will stop and the error will be
102
// returned as the result of For.
103
func (list *TeamList) For(f func(t *Team) error) error {
104
return list.Value.For(func(v *Value) error {
109
// Member is an interface implemented by both Person and Team.
110
type Member interface {
114
SetDisplayName(name string)
119
// Member is a marker function for types satisfying the
120
// the Member interface. This is necessary for now because
121
// the methods above are fairly common across several types,
122
// but this will likely be dropped in the future.
126
// The Person type represents a person in Launchpad.
131
var _ Member = (*Person)(nil)
133
// Member is a marker method so Person satisfies the Member interface.
134
func (person *Person) Member() {}
136
// DisplayName returns the person's name as it would be displayed
137
// throughout Launchpad. Most people use their full name.
138
func (person *Person) DisplayName() string {
139
return person.StringField("display_name")
142
// SetDisplayName changes the person's name as it would be displayed
143
// throughout Launchpad. Most people use their full name.
144
// Patch must be called to commit all changes.
145
func (person *Person) SetDisplayName(name string) {
146
person.SetField("display_name", name)
149
// Name returns the person's short unique name, beginning with a
150
// lower-case letter or number, and containing only letters, numbers,
151
// dots, hyphens, or plus signs.
152
func (person *Person) Name() string {
153
return person.StringField("name")
156
// SetName changes the person's short unique name.
157
// The name must begin with a lower-case letter or number, and
158
// contain only letters, numbers, dots, hyphens, or plus signs.
159
func (person *Person) SetName(name string) {
160
person.SetField("name", name)
163
// WebPage returns the URL for accessing this person's page in a browser.
164
func (person *Person) WebPage() string {
165
return person.StringField("web_link")
168
// PreferredEmail returns the Person's preferred email. If the user
169
// disabled public access to email addresses, this method returns an
170
// *Error with StatusCode of 404.
171
func (person *Person) PreferredEmail() (string, error) {
173
e, err := person.Link("preferred_email_address_link").Get(nil)
177
return e.StringField("email"), nil
180
// IRCNicks returns a list of all IRC nicks for the person.
181
func (person *Person) IRCNicks() (nicks []*IRCNick, err error) {
182
list, err := person.Link("irc_nicknames_collection_link").Get(nil)
186
list.For(func(v *Value) error {
187
nicks = append(nicks, &IRCNick{v})
193
type IRCNick struct {
197
// Nick returns the person's nick on an IRC network.
198
func (nick *IRCNick) Nick() string {
199
return nick.StringField("nickname")
202
// SetNick changes the person's nick on an IRC network.
203
// Patch must be called to commit all changes.
204
func (nick *IRCNick) SetNick(n string) {
205
nick.SetField("nickname", n)
208
// Network returns the IRC network this nick is associated to.
209
func (nick *IRCNick) Network() string {
210
return nick.StringField("network")
213
// SetNetwork changes the IRC network this nick is associated to.
214
// Patch must be called to commit all changes.
215
func (nick *IRCNick) SetNetwork(n string) {
216
nick.SetField("network", n)
219
// The Team type encapsulates access to details about a team in Launchpad.
224
var _ Member = (*Team)(nil)
226
// Member is a marker method so Team satisfies the Member interface.
227
func (team *Team) Member() {}
229
// Name returns the team's name. This is a short unique name, beginning with a
230
// lower-case letter or number, and containing only letters, numbers, dots,
231
// hyphens, or plus signs.
232
func (team *Team) Name() string {
233
return team.StringField("name")
236
// SetName changes the team's name. This is a short unique name, beginning
237
// with a lower-case letter or number, and containing only letters, numbers,
238
// dots, hyphens, or plus signs. Patch must be called to commit all changes.
239
func (team *Team) SetName(name string) {
240
team.SetField("name", name)
243
// DisplayName returns the team's name as it would be displayed
244
// throughout Launchpad.
245
func (team *Team) DisplayName() string {
246
return team.StringField("display_name")
249
// SetDisplayName changes the team's name as it would be displayed
250
// throughout Launchpad. Patch must be called to commit all changes.
251
func (team *Team) SetDisplayName(name string) {
252
team.SetField("display_name", name)
255
// WebPage returns the URL for accessing this team's page in a browser.
256
func (team *Team) WebPage() string {
257
return team.StringField("web_link")