https://docs.bsky.app/docs/api/app-bsky-feed-get-posts
(pds string, token string, items []string)
| 911 | |
| 912 | // https://docs.bsky.app/docs/api/app-bsky-feed-get-posts |
| 913 | func GetPosts(pds string, token string, items []string) ([]*Post, error) { |
| 914 | var results []*Post |
| 915 | |
| 916 | // Parallel fetching for chunks of up to 25 at a time |
| 917 | var wg sync.WaitGroup |
| 918 | var mu sync.Mutex |
| 919 | for i := 0; i < len(items); i += 25 { |
| 920 | end := i + 25 |
| 921 | if end > len(items) { |
| 922 | end = len(items) |
| 923 | } |
| 924 | chunk := items[i:end] |
| 925 | |
| 926 | wg.Add(1) |
| 927 | go func(c []string) { |
| 928 | defer wg.Done() |
| 929 | |
| 930 | url := pds + "/xrpc/app.bsky.feed.getPosts" + "?uris=" + strings.Join(c, "&uris=") |
| 931 | resp, err := SendRequest(&token, http.MethodGet, url, nil) |
| 932 | if err != nil { |
| 933 | fmt.Println(err) |
| 934 | return |
| 935 | } |
| 936 | defer resp.Body.Close() |
| 937 | if resp.StatusCode != http.StatusOK { |
| 938 | bodyBytes, _ := io.ReadAll(resp.Body) |
| 939 | fmt.Println("Response Status:", resp.StatusCode) |
| 940 | fmt.Println("Response Body:", string(bodyBytes)) |
| 941 | return |
| 942 | } |
| 943 | |
| 944 | var posts struct { |
| 945 | Posts []Post `json:"posts"` |
| 946 | } |
| 947 | if err := json.NewDecoder(resp.Body).Decode(&posts); err != nil { |
| 948 | return |
| 949 | } |
| 950 | |
| 951 | mu.Lock() |
| 952 | for _, post := range posts.Posts { |
| 953 | results = append(results, &post) |
| 954 | } |
| 955 | mu.Unlock() |
| 956 | }(chunk) |
| 957 | } |
| 958 | |
| 959 | wg.Wait() |
| 960 | return results, nil |
| 961 | } |
| 962 | |
| 963 | // https://docs.bsky.app/docs/api/app-bsky-graph-get-followers |
| 964 | func GetFollowers(pds string, token string, context string, actor string) (*FollowersTimeline, error) { |
nothing calls this directly
no test coverage detected