rladies / meetupr

R interface to the meetup.com API
https://rladies.github.io/meetupr
MIT License
76 stars 25 forks source link

Add fields argument to find_groups() to retrieve optional fields #46

Closed benubah closed 3 years ago

benubah commented 5 years ago

Add fields argument to find_groups() to retrieve optional fields from the response. I am using this package to work on a project this summer and found out that I needed a count of past events for each R-Ladies group. Thankfully, past_event_count is an optional field within the response of find/groups API method.

For now, I suggest just adding fields to find_groups() and the call to .fetch_results() as shown below:

find_groups <- function(text = NULL, topic_id = NULL, radius = "global", 
                                            fields = NULL, api_key = NULL) {
  api_method <- "find/groups"
  res <- .fetch_results(api_method = api_method,
                        api_key = api_key,
                        text = text,
                        topic_id = topic_id,
                        fields = fields,
                        radius = radius)

An example usage could be:

# add 'past_event_count' and 'upcoming_event_count' to the query parameters using 'fields' argument; 
#these two are among several optional fields provided by the API: https://www.meetup.com/meetup_api/docs/find/groups/
all_rladies_groups <- find_groups(text = "r-ladies",
                       fields="past_event_count, upcoming_event_count", api_key = "key here")

# Cleanup
rladies_groups <- all_rladies_groups[grep(pattern = "rladies|r-ladies|r ladies", 
                                          x = all_rladies_groups$name,
                                          ignore.case = TRUE), ]

#for now, we could easily retrieve the values for these two fields with:
pastevent_count <- purrr::map_dbl(rladies_groups$resource, "past_event_count", .default = 0)
upcomingevent_count <-  purrr::map_dbl(rladies_groups$resource, "upcoming_event_count", .default = 0)
benubah commented 5 years ago

A pull request for this has been submitted for your review here: https://github.com/rladies/meetupr/pull/48

maelle commented 3 years ago

Since the PR has been merged, I am closing this issue.