From 4b6916d59146904e6e58e36d6f4c337f12c6e6a0 Mon Sep 17 00:00:00 2001 From: JBGruber Date: Fri, 1 Mar 2024 10:03:37 +0100 Subject: [PATCH] fixes #14 --- NEWS.md | 2 ++ R/actors.r | 21 +++++++++++++-------- tests/testthat/test-actors.R | 9 ++++++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 658a5e0..29ca604 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * link preview cards are automatically added to posts (can be turned off) * unified approach to parsing actor data +* new function: skeet_shot (high quality screenshots of skeets) +* properly paginate get_user_info (#14) # atrrr 0.0.2 diff --git a/R/actors.r b/R/actors.r index 0ab1e75..c4aa6a9 100644 --- a/R/actors.r +++ b/R/actors.r @@ -93,14 +93,19 @@ get_user_info <- function(actor, parse = TRUE, .token = NULL) { - res <- do.call( - what = app_bsky_actor_get_profiles, - args = list( - actor, - .token = .token, - .return = "json" - )) |> - purrr::pluck("profiles") + actor_l <- split(actor, ceiling(seq_along(actor) / 25L)) + + res <- list() + for (actor_i in actor_l) { + res <- append(res, do.call( + what = app_bsky_actor_get_profiles, + args = list( + actor_i, + .token = .token, + .return = "json" + )) |> + purrr::pluck("profiles")) + } if (parse) { res <- parse_actors(res) diff --git a/tests/testthat/test-actors.R b/tests/testthat/test-actors.R index a70d1ec..83af9ac 100644 --- a/tests/testthat/test-actors.R +++ b/tests/testthat/test-actors.R @@ -4,8 +4,15 @@ test_that("search actors", { expect_gte(nrow(search_user("JBGruber")), 1L) }) -test_that("use info", { +test_that("user info", { expect_type(get_user_info("benguinaudeau.bsky.social", parse = FALSE), "list") expect_s3_class(get_user_info("jbgruber.bsky.social"), "tbl_df") expect_gte(nrow(get_user_info("favstats.bsky.social")), 1L) }) + +test_that("user info pagination", { + actors <- rep(c("jbgruber.bsky.social", + "benguinaudeau.bsky.social", + "favstats.bsky.social"), 25) + expect_equal(nrow(get_user_info(actor = actors)), 75L) +})