Skip to content

Commit

Permalink
- fix typo in user msg - set new timeout - fixed upload fcts
Browse files Browse the repository at this point in the history
  • Loading branch information
CIP-RIU committed Jan 24, 2019
1 parent 5f48dea commit 5094439
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 176 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(check_credentials)
export(check_fbapp)
export(fbapp2hidap)
export(fbapp2json)
Expand Down
53 changes: 44 additions & 9 deletions R/check_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ check_fbapp <- function(dfr){


if(nrow(dfr)==0){
msg <- paste("There are not changes in the dataset")
msg <- paste("There have been no changes in the dataset")
status <- "error"
} else if(!is.element("plot_id", fb_headers)){ #Check #1
msg <- paste("The variable 'plot_id' is missing. Must be included in order to upload into the database")
Expand All @@ -39,18 +39,53 @@ check_fbapp <- function(dfr){
msg <- paste("The variable(s)", non_found, "was (were) not found in the database. Refine your file before processing.")
status <- "error"
} else { #Check #3
msg <- paste("Dataset successfully uploaded in SweetPotatoBase!")
msg <- paste("Great! Dataset successfully uploaded in SweetPotatoBase. ")
status <- "success"
}

out<- list(msg= msg, status=status)

}

#
#
# check_upload <- function(){
#
#
#
# }


#' Check credentials from sweetpotatobase users.
#'
#' @param dbname character Database name. Currently, it only works with SOL genomics databases.
#' @param user character User name
#' @param password character Password
#' @param urltoken character \code{BRAPI} call URL to login in Sol Genomic databases.
#
#' @description FieldbookApp data is captured by mobiles phones or tablets. After exporting this information, it should be read in R
#' in order to process, check and curate.
#' @author Omar Benites
#' @export
#'
check_credentials <- function(dbname= "sweetpotatobase", user="obenites", password="dasdfsdgs",
urltoken= "sgn:[email protected]/brapi/v1/token"){

white_list <- brapi::ba_db()
con <- white_list[[dbname]] #get list
con[["user"]] <- user
con[["password"]] <- password
dat<- data.frame(username = con$user, password = con$password,
grant_type = "password", client_id = "", stringsAsFactors = FALSE)
jsondat <- RJSONIO::toJSON(dat)
callurl <- urltoken
resp <- httr::POST(url = callurl,
body = dat,
encode = ifelse(con$bms == TRUE, "json", "form"))
xout <- httr::content(x = resp)

code <- xout$metadata$status[[3]]$code %>% as.numeric()

if(code==200){
msg <- paste("Login credentials are correct.")
status <- "success"
} else {
msg <- paste("Login credentials are incorrect. Please try again.")
status <- "error"
}
out<- list(msg= msg, status=status)
}

Loading

0 comments on commit 5094439

Please sign in to comment.