# sunagriAPI
#
# An instance of OpenSILEX WebService
#
# OpenAPI spec version: 3.3.0
#
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' @title Brapiv1studiesSearch operations
#' @description phisWSClientRTools.Brapiv1studiesSearch
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' get_studies_search Retrieve studies information
#'
#'
#' post_studies_search search studies
#'
#' }
#'
#' @export
Brapiv1studiesSearchApi <- R6::R6Class(
'Brapiv1studiesSearchApi',
public = list(
userAgent = "Swagger-Codegen/3.3.0/r",
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
get_studies_search = function(study_db_id,common_crop_name,season_db_id,active,sort_by,sort_order,page_size,page,...){
args <- list(...)
queryParams <- list()
headerParams <- character()
self$apiClient$basePath = sub("/$", "",get("BASE_PATH",opensilexWSClientR:::configWS))
if(self$apiClient$basePath == ""){
stop("Wrong you must first connect with connectToPHISWS")
}
#if (!missing(`authorization`)) {
# headerParams['Authorization'] <- authorization
#}
if (!missing(`study_db_id`)) {
queryParams['studyDbId'] <- study_db_id
}
if (!missing(`common_crop_name`)) {
queryParams['commonCropName'] <- common_crop_name
}
if (!missing(`season_db_id`)) {
queryParams['seasonDbId'] <- season_db_id
}
if (!missing(`active`)) {
queryParams['active'] <- active
}
if (!missing(`sort_by`)) {
queryParams['sortBy'] <- sort_by
}
if (!missing(`sort_order`)) {
queryParams['sortOrder'] <- sort_order
}
if (!missing(`page_size`)) {
queryParams['pageSize'] <- page_size
}
if (!missing(`page`)) {
queryParams['page'] <- page
}
urlPath <- "/brapi/v1/studies-search"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
method = "GET"
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
if(method == "GET"){
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
data <- json$result$data
returnedOjects = list()
for(i in 1:nrow(data)){
row <- data[i,]
returnObject <- StudyDTO$new()
returnObject$fromJSONObject(row)
returnedOjects = c(returnedOjects,returnObject)
}
return(Response$new(json$metadata,returnedOjects, resp, TRUE))
}
if(method == "POST" || method == "PUT"){
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
return(Response$new(json$metadata, json$result$datafiles, resp, TRUE))
}
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
return(Response$new(json$metadata, json, resp, FALSE))
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
return(Response$new(json$metadata, json, resp, FALSE))
}
},
post_studies_search = function(body,...){
args <- list(...)
queryParams <- list()
headerParams <- character()
self$apiClient$basePath = sub("/$", "",get("BASE_PATH",opensilexWSClientR:::configWS))
if(self$apiClient$basePath == ""){
stop("Wrong you must first connect with connectToPHISWS")
}
#if (!missing(`authorization`)) {
# headerParams['Authorization'] <- authorization
#}
if (!missing(`body`)) {
if(is.list(`body`)){
bodyList <- lapply(`body`, function(x){x$toJSONString()})
bodyListPaste <- paste(bodyList, collapse=', ' )
body <- paste('[',bodyListPaste,']')
}else{
body <- paste('[',`body`$toJSONString(),']')
}
} else {
body <- NULL
}
urlPath <- "/brapi/v1/studies-search"
resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
method = "POST",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
method = "POST"
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
if(method == "GET"){
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
data <- json$result$data
returnedOjects = list()
for(i in 1:nrow(data)){
row <- data[i,]
returnObject <- ResponseFormPOST$new()
returnObject$fromJSONObject(row)
returnedOjects = c(returnedOjects,returnObject)
}
return(Response$new(json$metadata,returnedOjects, resp, TRUE))
}
if(method == "POST" || method == "PUT"){
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
return(Response$new(json$metadata, json$result$datafiles, resp, TRUE))
}
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
return(Response$new(json$metadata, json, resp, FALSE))
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
json <- jsonlite::fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
return(Response$new(json$metadata, json, resp, FALSE))
}
}
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.