Skip to content

Commit

Permalink
Merge pull request #141 from rladies/pro fix #118 #112
Browse files Browse the repository at this point in the history
rewrite PRO functions to query GraphQL
  • Loading branch information
drmowinckels authored Oct 1, 2022
2 parents cd999d7 + 8acc117 commit c479c55
Show file tree
Hide file tree
Showing 33 changed files with 931 additions and 11,345 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
^~/\.local/share/meetupr/meetupr-token\.rds$
^codecov\.yml$
^LICENSE\.md$
^~/Library/Application Support/meetupr/meetupr-token\.rds$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ vignettes/*.html
docs
tests/testthat/.meetup_token.rds
~/.local/share/meetupr/meetupr-token.rds
~/Library/Application Support/meetupr/meetupr-token.rds
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Imports:
purrr,
gh,
progress,
tibble,
rlang,
rappdirs,
glue,
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(find_groups)
export(get_boards)
export(get_event_attendees)
export(get_event_comments)
export(get_event_rsvps)
export(get_events)
export(get_members)
export(get_pro_events)
export(get_pro_groups)
export(meetup_auth)
export(meetup_deauth)
export(meetup_query)
Expand Down
5 changes: 3 additions & 2 deletions R/find_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#' @param lat Latitude. An integer
#' @param lon Longitutde. An integer
#' @param radius Radius. An integer
#' @param extra_graphql A graphql object. Extra objects to return
#' @param token Meetup token
#' @param ... Should be empty. Used for parameter expansion
#' @template extra_graphql
#' @template token
#' @importFrom anytime anytime
#' @export
find_groups <- function(
Expand Down
82 changes: 41 additions & 41 deletions R/get_boards.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
#' Get the discussion boards from a meetup group
#'
#' @template urlname
#' @template verbose
#' @return A tibble with the following columns:
#' * id
#' * name
#' * description
#' * created
#' * updated
#' * post_count
#' * discussion_count
#' * latest_reply_created
#' * latest_reply_member_name
#' * resource
#'
#' @references
#' \url{https://www.meetup.com/meetup_api/docs/:urlname/boards/}
#'@examples
#' \dontrun{
#' urlname <- "rladies-nashville"
#' meetup_boards <- get_boards(urlname = urlname)
#'}
#' @export
get_boards <- function(urlname,
verbose = meetupr_verbose()) {
api_path <- paste0(urlname, "/boards")
res <- .fetch_results(api_path = api_path, verbose = verbose)
tibble::tibble(
id = purrr::map_int(res, "id"),
name = purrr::map_chr(res, "name"),
description = purrr::map_chr(res, "description"),
created = .date_helper(purrr::map_dbl(res, "created")),
updated = .date_helper(purrr::map_dbl(res, "updated")),
post_count = purrr::map_int(res, "post_count", .default = NA),
discussion_count = purrr::map_int(res, "discussion_count", .default = NA),
latest_reply_created = .date_helper(purrr::map_dbl(res, c("latest_reply", "created"), .default = NA)),
latest_reply_member_name = purrr::map_chr(res, c("latest_reply", "member", "name"), .default = NA),
resource = res
)
}
#' #' Get the discussion boards from a meetup group
#' #'
#' #' @template urlname
#' #' @template verbose
#' #' @return A tibble with the following columns:
#' #' * id
#' #' * name
#' #' * description
#' #' * created
#' #' * updated
#' #' * post_count
#' #' * discussion_count
#' #' * latest_reply_created
#' #' * latest_reply_member_name
#' #' * resource
#' #'
#' #' @references
#' #' \url{https://www.meetup.com/meetup_api/docs/:urlname/boards/}
#' #'@examples
#' #' \dontrun{
#' #' urlname <- "rladies-nashville"
#' #' meetup_boards <- get_boards(urlname = urlname)
#' #'}
#' #' @export
#' get_boards <- function(urlname,
#' verbose = meetupr_verbose()) {
#' api_path <- paste0(urlname, "/boards")
#' res <- .fetch_results(api_path = api_path, verbose = verbose)
#' tibble::tibble(
#' id = purrr::map_int(res, "id"),
#' name = purrr::map_chr(res, "name"),
#' description = purrr::map_chr(res, "description"),
#' created = .date_helper(purrr::map_dbl(res, "created")),
#' updated = .date_helper(purrr::map_dbl(res, "updated")),
#' post_count = purrr::map_int(res, "post_count", .default = NA),
#' discussion_count = purrr::map_int(res, "discussion_count", .default = NA),
#' latest_reply_created = .date_helper(purrr::map_dbl(res, c("latest_reply", "created"), .default = NA)),
#' latest_reply_member_name = purrr::map_chr(res, c("latest_reply", "member", "name"), .default = NA),
#' resource = res
#' )
#' }
4 changes: 2 additions & 2 deletions R/get_event_attendees.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#'
#' @param id Required event ID
#' @param ... Should be empty. Used for parameter expansion
#' @param extra_graphql A graphql object. Extra objects to return
#' @param token Meetup token
#' @template extra_graphql
#' @template token
#' @return A tibble with the following columns:
#' * id
#' * name
Expand Down
6 changes: 3 additions & 3 deletions R/get_event_comments.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Get the comments for a specified event
#'
#' @param id Required event ID
#' @template id
#' @param ... Should be empty. Used for parameter expansion
#' @param extra_graphql A graphql object. Extra objects to return
#' @param token Meetup token
#' @template extra_graphql
#' @template token
#' @return A tibble with the following columns:
#' * id
#' * comment
Expand Down
6 changes: 3 additions & 3 deletions R/get_events.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Get the events from a meetup group
#'
#' @param urlname Required urlname of the Meetup group
#' @template urlname
#' @param ... Should be empty. Used for parameter expansion
#' @param extra_graphql A graphql object. Extra objects to return
#' @param token Meetup token
#' @template extra_graphql
#' @template token
#' @export
get_events <- function(
urlname,
Expand Down
6 changes: 3 additions & 3 deletions R/get_members.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Get the current meetup members from a meetup group
#'
#' @param urlname Required urlname of the Meetup group
#' @template urlname
#' @param ... Should be empty. Used for parameter expansion
#' @param extra_graphql A graphql object. Extra objects to return
#' @param token Meetup token
#' @template extra_graphql
#' @template token
#' @return A tibble with the following columns:
#' * id
#' * name
Expand Down
165 changes: 90 additions & 75 deletions R/get_pro.R
Original file line number Diff line number Diff line change
@@ -1,81 +1,96 @@
#' #' Meetup pro functions
#' #'
#' #' The pro functions only work if the querying users
#' #' had a meetup pro account.
#' #'
#' #' \describe{
#' #' \item{get_pro_groups}{Get the current meetup members from a pro meetup group}
#' #' \item{get_pro_events}{Get pro group events for the enxt 30 days}
#' #' }
#' #'
#' #' @template urlname
#' #' @template verbose
#' #'
#' #' @references
#' #' \url{https://www.meetup.com/meetup_api/docs/pro/:urlname/groups/}
#' #' \url{https://www.meetup.com/meetup_api/docs/:urlname/events/#list}
#' #'
#' #' @examples
#' #' \dontrun{
#' #' urlname <- "rladies"
#' #' members <- get_pro_groups(urlname)
#' #'
#' #' past_events <- get_events(urlname = urlname,
#' #' event_status = "past")
#' #' upcoming_events <- get_events(urlname = urlname,
#' #' event_status = "upcoming")
#' #'}
#' #'
#' #' @return A tibble with meetup information
#' Meetup pro functions
#'
#' The pro functions only work if the querying users
#' had a meetup pro account.
#'
#' #' @rdname meetup_pro
#' #' @export
#' #' @importFrom purrr map_int map_chr map_dbl
#' #' @importFrom tibble tibble
#' get_pro_groups <- function(
#' urlname,
#' ...,
#' extra_graphql = NULL,
#' token = meetup_token()
#' ) {
#' ellipsis::check_dots_empty()
#' @template urlname
#' @param ... Should be empty. Used for parameter expansion
#' @template extra_graphql
#' @template token
#' @param status Which status the events should have.
#'
#' dt <- gql_events(
#' urlname = urlname,
#' .extra_graphql = extra_graphql,
#' .token = token
#' )
#' @references
#' \url{https://www.meetup.com/api/schema/#ProNetwork}
#'
#' tibble(
#' group_sorter(res),
#' created = .date_helper(map_dbl(res, "founded_date")),
#' members = map_chr(res, "member_count"),
#' upcoming_events = map_int(res, "upcoming_events"),
#' past_events = map_int(res, "past_events"),
#' res = res
#' )
#' }
#'
#'
#' #' @rdname meetup_pro
#' #' @importFrom tibble tibble
#' #' @export
#' get_pro_events <- function(urlname,
#' verbose = meetupr_verbose()
#' ){
#'
#' api_path <- sprintf("pro/%s/events", urlname)
#' res <- .fetch_results(api_path = api_path, verbose = verbose)
#'
#' group <- lapply(res, function(x) x[["chapter"]])
#' group <- tibble(group_sorter(group), res = group)
#' names(group) <- paste0("group_", names(group))
#'
#' events <- lapply(res, function(x) x[[1]])
#' @examples
#' \dontrun{
#' urlname <- "rladies"
#' members <- get_pro_groups(urlname)
#'
#' tibble(
#' event_sorter(events),
#' group
#' )
#' past_events <- get_pro_events(urlname = urlname,
#' status = "PAST")
#' upcoming_events <- get_pro_events(urlname = urlname,
#' status = "UPCOMING")
#' all_events <- get_pro_events(urlname = urlname)
#' }
#' @name meetup_pro
#' @return A tibble with meetup pro information
NULL

#' Get pro groups information
#' @export
#' @describeIn meetup_pro retrieve groups in a pro network
get_pro_groups <- function(
urlname,
...,
extra_graphql = NULL,
token = meetup_token()
) {
ellipsis::check_dots_empty()

dt <- gql_get_pro_groups(
urlname = urlname,
.extra_graphql = extra_graphql,
.token = token
)
dt <- rename(dt,
created = foundedDate,
members = memberships.count,
join_mode = joinMode,
category_id = category.id,
category_name = category.name,
country = country_name,
past_events_count = pastEvents.count,
upcoming_events_count = upcomingEvents.count,
membership_status = membershipMetadata.status,
is_private = isPrivate

)

dt$created <- anytime::anytime(dt$created)
dt
}

#' Get pro events information
#' @export
#' @describeIn meetup_pro retrieve events from a pro network
get_pro_events <- function(
urlname,
status = NULL,
...,
extra_graphql = NULL,
token = meetup_token()
) {
ellipsis::check_dots_empty()

dt <- gql_get_pro_events(
urlname = urlname,
status = status,
.extra_graphql = extra_graphql,
.token = token
)
if(nrow(dt) == 0) return(NULL)

# replace dot with underscore
names(dt) <- gsub("\\.", "_", names(dt))

dt <- rename(dt,
link = eventUrl,
event_type = eventType,
venue_zip = venue_postalCode
)
dt$time <- anytime::anytime(dt$dateTime)

remove(dt,
dateTime)
}
Loading

0 comments on commit c479c55

Please sign in to comment.