Skip to content

Commit

Permalink
✨ add two list_ funs
Browse files Browse the repository at this point in the history
  • Loading branch information
ShixiangWang committed Sep 3, 2019
1 parent bb7ae1d commit 455c110
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Depends:
httr
Imports:
jsonlite,
magrittr
magrittr,
dplyr,
data.table
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Expand Down
53 changes: 41 additions & 12 deletions R/helper_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ parse_user_info = function(response, show = TRUE) {
if (response$status_code != 200) {
stop("Status code: ", response$status_code, ", please check token or internet.", call. = FALSE)
} else {
content = response %>% content()
ct = response %>% content()
ct = ct$data
response = list(
type = content$data$type,
id = content$data$id,
login = content$data$login,
name = content$data$name,
description = content$data$description,
books_count = content$data$books_count,
public_books_count = content$data$public_books_count,
followers_count = content$data$followers_count,
following_count = content$data$following_count,
created_at = content$data$created_at,
updated_at = content$data$updated_at,
type = ct$type,
id = ct$id,
login = ct$login,
name = ct$name,
description = ct$description,
books_count = ct$books_count,
public_books_count = ct$public_books_count,
followers_count = ct$followers_count,
following_count = ct$following_count,
created_at = ct$created_at,
updated_at = ct$updated_at,
limits = response$headers$`x-ratelimit-remaining`
)
}
Expand All @@ -32,3 +33,31 @@ parse_user_info = function(response, show = TRUE) {

response
}


parse_group_info = function(response, verbose = c("less", "all")) {
#// TODO: how to reduce query time?
#// I mean user can use features like ls and ll but only query once
stopifnot(inherits(response, "response"))

if (response$status_code != 200) {
stop("Status code: ", response$status_code, ", please check token or internet.", call. = FALSE)
} else {
ct = response %>% content()
ct = ct$data

}

suppressWarnings(ct <- ct %>% data.table::rbindlist(fill = TRUE))
ct = ct %>%
dplyr::as_tibble()

verbose = match.arg(verbose)
if (verbose == "less") {
message(paste(ct$name, collapse = " "))
} else {

}

ct
}
17 changes: 16 additions & 1 deletion R/list.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# yq_list_* funs
yq_list_groups = function() {
auth = get_auth()
yq("/users/:login/groups", login = auth$login, .token = auth$token)
r = yq("/users/:login/groups", login = auth$login, .token = auth$token)
r = parse_group_info(r)
invisible(r)
}

yq_list_public_groups = function() {
r = yq("/groups")
r = parse_group_info(r)
invisible(r)
}

yq_list_group_info = function(login) {
auth = get_auth()
r = yq("/groups/:login", login = login, .token = auth$token)
# r = parse_group_info(r)
# invisible(r)
}

0 comments on commit 455c110

Please sign in to comment.