R/nih_api.R

# FireCloud
#
# FireCloud API 
#
# The version of the OpenAPI document: 0.1
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title NIH operations
#' @description openapi.NIH
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ NIHCallback } \emph{ Updates a user's NIH link from a JWT }
#' 
#'
#' \itemize{
#' \item \emph{ @param } jwt \link{JWTWrapper}
#' \item \emph{ @returnType } \link{NihStatus} \cr
#'
#'
#' \item status code : 200 | Successfully updated NIH link
#'
#' \item return type : NihStatus 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid or malformed JWT
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 401 | Unauthorized
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 500 | Internal server error saving NIH link to profile
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ NIHStatus } \emph{ Retrieves info about a user's NIH link }
#' 
#'
#' \itemize{
#' \item \emph{ @returnType } \link{NihStatus} \cr
#'
#'
#' \item status code : 200 | Successfully retrieved NIH status
#'
#' \item return type : NihStatus 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | linkedNihUsername key missing from status
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 500 | Internal server error retrieving NIH status
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  NIHCallback  ####################
#'
#' library(openapi)
#' var.jwt <- JWTWrapper$new() # JWTWrapper | JWT from NIH login
#'
#' #Updates a user's NIH link from a JWT
#' api.instance <- NIHApi$new()
#'
#' # Configure OAuth2 access token for authorization: googleoauth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$NIHCallback(var.jwt)
#'
#'
#' ####################  NIHStatus  ####################
#'
#' library(openapi)
#'
#' #Retrieves info about a user's NIH link
#' api.instance <- NIHApi$new()
#'
#' # Configure OAuth2 access token for authorization: googleoauth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$NIHStatus()
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
NIHApi <- R6::R6Class(
  'NIHApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    NIHCallback = function(jwt, ...){
      apiResponse <- self$NIHCallbackWithHttpInfo(jwt, ...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        apiResponse$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        apiResponse
      }
    },

    NIHCallbackWithHttpInfo = function(jwt, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      if (missing(`jwt`)) {
        stop("Missing required parameter `jwt`.")
      }

      if (!missing(`jwt`)) {
        body <- `jwt`$toJSONString()
      } else {
        body <- NULL
      }

      urlPath <- "/api/nih/callback"
      # OAuth token
      headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")

      resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "POST",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "NihStatus", loadNamespace("openapi")),
          error = function(e){
             stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    },
    NIHStatus = function(...){
      apiResponse <- self$NIHStatusWithHttpInfo(...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        apiResponse$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        apiResponse
      }
    },

    NIHStatusWithHttpInfo = function(...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      body <- NULL
      urlPath <- "/api/nih/status"
      # OAuth token
      headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")

      resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "NihStatus", loadNamespace("openapi")),
          error = function(e){
             stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    }
  )
)
vjcitn/terraClientR documentation built on Dec. 23, 2021, 4:07 p.m.