53 if errorResult.Text != "" { |
53 if errorResult.Text != "" { |
54 return nil, fmt.Errorf("%s", errorResult.Text) |
54 return nil, fmt.Errorf("%s", errorResult.Text) |
55 } |
55 } |
56 } |
56 } |
57 |
57 |
|
58 // Not an error reply; let's unmarshal the data |
58 var account Account |
59 var account Account |
59 // Not an error reply; let's unmarshal the data |
|
60 err = json.Unmarshal([]byte(r.Body), &account) |
60 err = json.Unmarshal([]byte(r.Body), &account) |
61 if err != nil { |
61 if err != nil { |
62 return nil, fmt.Errorf("getAccount (%s) API: %s", target, err.Error()) |
62 return nil, fmt.Errorf("getAccount (%s) API: %s", target, err.Error()) |
63 } |
63 } |
64 return &account, nil |
64 return &account, nil |
86 default: |
86 default: |
87 return nil, ErrInvalidParameter |
87 return nil, ErrInvalidParameter |
88 } |
88 } |
89 |
89 |
90 req := g.prepareRequest(endPoint) |
90 req := g.prepareRequest(endPoint) |
|
91 |
|
92 // Handle target-specific query parameters |
91 if target == "search" { |
93 if target == "search" { |
92 req.QueryParams["q"] = opts.Q |
94 req.QueryParams["q"] = opts.Q |
93 if opts.Limit > 0 { |
95 if opts.Limit > 0 { |
94 req.QueryParams["limit"] = strconv.Itoa(opts.Limit) |
96 req.QueryParams["limit"] = strconv.Itoa(opts.Limit) |
95 } |
97 } |
96 } |
98 } |
|
99 |
97 r, err := rest.API(req) |
100 r, err := rest.API(req) |
98 if err != nil { |
101 if err != nil { |
99 return nil, fmt.Errorf("getAccount (%s): %s", target, err.Error()) |
102 return nil, fmt.Errorf("getAccount (%s): %s", target, err.Error()) |
100 } |
103 } |
101 |
104 |
106 if errorResult.Text != "" { |
109 if errorResult.Text != "" { |
107 return nil, fmt.Errorf("%s", errorResult.Text) |
110 return nil, fmt.Errorf("%s", errorResult.Text) |
108 } |
111 } |
109 } |
112 } |
110 |
113 |
|
114 // Not an error reply; let's unmarshal the data |
111 var accounts []Account |
115 var accounts []Account |
112 // Not an error reply; let's unmarshal the data |
|
113 err = json.Unmarshal([]byte(r.Body), &accounts) |
116 err = json.Unmarshal([]byte(r.Body), &accounts) |
114 if err != nil { |
117 if err != nil { |
115 return nil, fmt.Errorf("getAccount (%s) API: %s", target, err.Error()) |
118 return nil, fmt.Errorf("getAccount (%s) API: %s", target, err.Error()) |
116 } |
119 } |
117 return accounts, nil |
120 return accounts, nil |
201 if errorResult.Text != "" { |
204 if errorResult.Text != "" { |
202 return nil, fmt.Errorf("%s", errorResult.Text) |
205 return nil, fmt.Errorf("%s", errorResult.Text) |
203 } |
206 } |
204 } |
207 } |
205 |
208 |
|
209 // Not an error reply; let's unmarshal the data |
206 var account Account |
210 var account Account |
207 // Not an error reply; let's unmarshal the data |
|
208 err = json.Unmarshal([]byte(r.Body), &account) |
211 err = json.Unmarshal([]byte(r.Body), &account) |
209 if err != nil { |
212 if err != nil { |
210 return nil, fmt.Errorf("FollowRemoteAccount API: %s", err.Error()) |
213 return nil, fmt.Errorf("FollowRemoteAccount API: %s", err.Error()) |
211 } |
214 } |
212 if account.ID == 0 { |
215 if account.ID == 0 { |
286 } |
289 } |
287 |
290 |
288 // GetAccountRelationships returns a list of relationship entities for the given accounts |
291 // GetAccountRelationships returns a list of relationship entities for the given accounts |
289 // NOTE: Currently it doesn't seem to work with several items. |
292 // NOTE: Currently it doesn't seem to work with several items. |
290 func (g *Client) GetAccountRelationships(accountIDs []int) ([]Relationship, error) { |
293 func (g *Client) GetAccountRelationships(accountIDs []int) ([]Relationship, error) { |
291 var rl []Relationship |
|
292 |
|
293 if len(accountIDs) < 1 { |
294 if len(accountIDs) < 1 { |
294 return rl, ErrInvalidID |
295 return nil, ErrInvalidID |
295 } |
296 } |
296 |
297 |
297 req := g.prepareRequest("accounts/relationships") |
298 req := g.prepareRequest("accounts/relationships") |
298 |
299 |
299 if len(accountIDs) > 1 { // XXX |
300 if len(accountIDs) > 1 { // XXX |
300 return rl, fmt.Errorf("accounts/relationships currently does not work with more than 1 ID") |
301 return nil, fmt.Errorf("accounts/relationships currently does not work with more than 1 ID") |
301 } |
302 } |
302 req.QueryParams["id"] = strconv.Itoa(accountIDs[0]) |
303 req.QueryParams["id"] = strconv.Itoa(accountIDs[0]) |
303 /* |
304 /* |
304 for i, id := range accountIDList { |
305 for i, id := range accountIDList { |
305 qID := fmt.Sprintf("id[%d]", i+1) |
306 qID := fmt.Sprintf("id[%d]", i+1) |
307 } |
308 } |
308 */ |
309 */ |
309 |
310 |
310 r, err := rest.API(req) |
311 r, err := rest.API(req) |
311 if err != nil { |
312 if err != nil { |
312 return rl, fmt.Errorf("GetAccountRelationships: %s", err.Error()) |
313 return nil, fmt.Errorf("GetAccountRelationships: %s", err.Error()) |
313 } |
314 } |
314 |
315 |
315 // Check for error reply |
316 // Check for error reply |
316 var errorResult Error |
317 var errorResult Error |
317 if err := json.Unmarshal([]byte(r.Body), &errorResult); err == nil { |
318 if err := json.Unmarshal([]byte(r.Body), &errorResult); err == nil { |
318 // The empty object is not an error |
319 // The empty object is not an error |
319 if errorResult.Text != "" { |
320 if errorResult.Text != "" { |
320 return nil, fmt.Errorf("%s", errorResult.Text) |
321 return nil, fmt.Errorf("%s", errorResult.Text) |
321 } |
322 } |
322 } |
323 } |
323 |
324 |
324 // Not an error reply; let's unmarshal the data |
325 // Not an error reply; let's unmarshal the data |
|
326 var rl []Relationship |
325 err = json.Unmarshal([]byte(r.Body), &rl) |
327 err = json.Unmarshal([]byte(r.Body), &rl) |
326 if err != nil { |
328 if err != nil { |
327 return nil, fmt.Errorf("accounts/relationships API: %s", err.Error()) |
329 return nil, fmt.Errorf("accounts/relationships API: %s", err.Error()) |
328 } |
330 } |
329 return rl, nil |
331 return rl, nil |
330 } |
332 } |
|
333 |
|
334 // GetAccountStatuses returns a list of status entities for the given account |
|
335 // If onlyMedia is true, returns only statuses that have media attachments. |
|
336 // If excludeReplies is true, skip statuses that reply to other statuses. |
|
337 func (g *Client) GetAccountStatuses(accountID int, onlyMedia, excludeReplies bool) ([]Status, error) { |
|
338 if accountID < 1 { |
|
339 return nil, ErrInvalidID |
|
340 } |
|
341 |
|
342 endPoint := "accounts/" + strconv.Itoa(accountID) + "/" + "statuses" |
|
343 req := g.prepareRequest(endPoint) |
|
344 |
|
345 if onlyMedia { |
|
346 req.QueryParams["only_media"] = "true" |
|
347 } |
|
348 if excludeReplies { |
|
349 req.QueryParams["exclude_replies"] = "true" |
|
350 } |
|
351 |
|
352 r, err := rest.API(req) |
|
353 if err != nil { |
|
354 return nil, fmt.Errorf("GetAccountStatuses: %s", err.Error()) |
|
355 } |
|
356 |
|
357 // Check for error reply |
|
358 var errorResult Error |
|
359 if err := json.Unmarshal([]byte(r.Body), &errorResult); err == nil { |
|
360 // The empty object is not an error |
|
361 if errorResult.Text != "" { |
|
362 return nil, fmt.Errorf("%s", errorResult.Text) |
|
363 } |
|
364 } |
|
365 |
|
366 // Not an error reply; let's unmarshal the data |
|
367 var sl []Status |
|
368 err = json.Unmarshal([]byte(r.Body), &sl) |
|
369 if err != nil { |
|
370 return nil, fmt.Errorf("accounts/statuses API: %s", err.Error()) |
|
371 } |
|
372 return sl, nil |
|
373 } |