Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: Repetitive pattern #31

Closed
chainsawriot opened this issue Nov 7, 2022 · 6 comments
Closed

Refactoring: Repetitive pattern #31

chainsawriot opened this issue Nov 7, 2022 · 6 comments
Assignees
Milestone

Comments

@chainsawriot
Copy link
Collaborator

https://github.com/schochastics/rtoot/blob/2d322706fa8b71e2df37fff6c59421884006b945/R/timelines.R#L49-L52

This dance is getting repetitive for all functions using make_get_request. But in order to refactor it, we need to have tests first. #19

@schochastics
Copy link
Collaborator

agreed. Doing a lot of ctrl+c/ctr+v for the account endpoints atm

@schochastics schochastics added this to the First Release milestone Nov 8, 2022
@chainsawriot
Copy link
Collaborator Author

@schochastics
Copy link
Collaborator

we have this only twice though? Anything I miss what is problematic here?

@chainsawriot
Copy link
Collaborator Author

@schochastics With the poll, now thrice. Not as repetitive as the first dance, though.

@schochastics
Copy link
Collaborator

ah right yeah then we may want to tackle this too

@schochastics
Copy link
Collaborator

testing with this function atm

process_request <- function(token = NULL,
                path,
                instance = NULL,
                params,
                anonymous = FALSE,
                parse = TRUE,
                FUN = identity
){
  output <- make_get_request(token = token,path = path,
                             instance = instance, params = params,
                             anonymous = anonymous)
  if (isTRUE(parse)) {
    header <- attr(output,"headers")
    if(length(output[[1]])==1){ #TODO:fragile?
      output <- FUN(output)
    } else{
      output <- dplyr::bind_rows(lapply(output, FUN))
    }
    attr(output,"headers") <- header
  }
  return(output)
}

this is how the new get functions would look like

get_account_statuses <- function(id,instance = NULL, token = NULL, anonymous = FALSE, parse = TRUE){
  path <- paste0("api/v1/accounts/",id,"/statuses")
  params <- list()
  # output <- make_get_request(token = token,path = path,
  #                            instance = instance, params = params,
  #                            anonymous = anonymous)
  # if (isTRUE(parse)) {
  #   output <- dplyr::bind_rows(lapply(output, parse_status))
  # }
  # return(output)
  process_request(token = token,path = path,instance = instance,
                  params = params, anonymous = anonymous,
                  parse = parse, FUN = parse_status)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants