func (a *App) getPostByID(user *frf.User, postID string) (*frf.Post, error) { v := &frf.OnePostResponse{} err := user.SendRequest("GET", "https://"+a.apiHost+"/v1/posts/"+postID, nil, v) if err != nil { return nil, err } return v.GetPost(), nil }
func (a *App) getAllPosts(user *frf.User) ([]*frf.Post, error) { v := &frf.DirectChannelResponse{} err := user.SendRequest("GET", "https://"+a.apiHost+"/v1/timelines/filter/directs?offset=0", nil, v) if err != nil { return nil, err } return v.AllPosts(), nil }
func (a *App) sendDirect(user *frf.User, addressees []string, text string) (string, error) { postBody := &frf.NewPostRequest{} postBody.Meta.Feeds = addressees postBody.Post.Body = text v := &frf.PostResponse{} if err := user.SendRequest("POST", "https://"+a.apiHost+"/v1/posts", postBody, v); err != nil { return "", err } return v.Posts.ID, nil }
func (a *App) getContacts(user *frf.User) ([]string, error) { tasks := [](*contactTask){ {Url: "https://" + a.apiHost + "/v1/users/" + user.Name + "/subscribers"}, {Url: "https://" + a.apiHost + "/v1/users/" + user.Name + "/subscriptions"}, } wg := new(sync.WaitGroup) wg.Add(len(tasks)) for _, task := range tasks { go func(task *contactTask) { defer wg.Done() v := &frf.SubscrResponse{} err := user.SendRequest("GET", task.Url, nil, v) if err != nil { task.Err = err return } task.List = make([]string, len(v.Subscr)) for i, u := range v.Subscr { task.List[i] = u.UserName } }(task) } wg.Wait() umap := make(map[string]int) names := []string{} for _, t := range tasks { if t.Err != nil { return nil, t.Err } for _, n := range t.List { umap[n] = umap[n] + 1 if umap[n] == len(tasks) { names = append(names, n) } } } sort.Strings(names) return names, nil }