Skip to content

Commit

Permalink
Merge pull request #4 from sib-swiss/3-pagination-missing-in-api-calls
Browse files Browse the repository at this point in the history
fixes #3
  • Loading branch information
GeertvanGeest authored Jan 10, 2025
2 parents 6b7ed74 + 0b14851 commit 8f96f62
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 133 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ data/
glittr_stats_files/
_freeze/
/.quarto/
_site/
_site/
index_files/
*.xlsx
1 change: 1 addition & 0 deletions glittr-stats.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: df482e20-2b83-4652-aee9-f9f2edc68a83

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down
24 changes: 4 additions & 20 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,12 @@ Using the glittr.org REST API to get repository metadata, among which the starga
```{r}
#| code-fold: true
# while loop to loop over all pages
page_list <- list()
page <- 1
has_more_pages <- TRUE
while (has_more_pages) {
# Create and send the request with pagination
response <- request("https://glittr.org/api/repositories") |>
req_url_query(`page[size]` = 100, `page[number]` = page) |>
req_perform() |>
resp_body_json()
# Append the data to the list
page_list <- append(page_list, response$data)
# Check if there are more pages (this logic depends on the API's response structure)
has_more_pages <- length(response$data) > 0 # Adjust this condition based on your API's pagination logic
page <- page + 1
}
response <- request("https://glittr.org/api/repositories") |>
req_perform() |>
resp_body_json()
# extract relevant items as dataframe
repo_info_list <- lapply(page_list, function(x) data.frame(
repo_info_list <- lapply(response$data, function(x) data.frame(
repo = x$name,
author_name = x$author$name,
stargazers = x$stargazers,
Expand Down
Loading

0 comments on commit 8f96f62

Please sign in to comment.