R/FacilityApi.r

# Altana Atlas API
#
# Altana Atlas for Regulatory Risk and Trade Compliance
#
# OpenAPI spec version: {{ version or \"v0.0.1\" }}
# Contact: engineering@altanatech.com
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' @title Facility operations
#' @description swagger.Facility
#'
#' @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_facility_by_id Facility ID
#'
#'
#' get_facility_products Facility Products
#'
#'
#' get_facility_trading_partners Facility Trading Partners
#'
#'
#' match_facility Facility Match
#'
#'
#' search_facility Facility Search
#'
#' }
#'
#' @export
FacilityApi <- R6::R6Class(
  'FacilityApi',
  public = list(
    userAgent = "Swagger-Codegen/1.0.0/r",
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    get_facility_by_id = function(facility_id, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      urlPath <- "/facility/id/{facility_id}"
      if (!missing(`facility_id`)) {
        urlPath <- gsub(paste0("\\{", "facility_id", "\\}"), `facility_id`, urlPath)
      }

      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) {
        returnObject <- Facility$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_facility_products = function(facility_id, trade_direction, page, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`trade_direction`)) {
        queryParams['trade_direction'] <- trade_direction
      }

      if (!missing(`page`)) {
        queryParams['page'] <- page
      }

      urlPath <- "/facility/id/{facility_id}/products"
      if (!missing(`facility_id`)) {
        urlPath <- gsub(paste0("\\{", "facility_id", "\\}"), `facility_id`, urlPath)
      }

      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) {
        returnObject <- Products$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_facility_trading_partners = function(facility_id, page, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`page`)) {
        queryParams['page'] <- page
      }

      urlPath <- "/facility/id/{facility_id}/trading-partners"
      if (!missing(`facility_id`)) {
        urlPath <- gsub(paste0("\\{", "facility_id", "\\}"), `facility_id`, urlPath)
      }

      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) {
        returnObject <- FacilityTradingPartners$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    match_facility = function(company_name, full_address, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`company_name`)) {
        queryParams['company_name'] <- company_name
      }

      if (!missing(`full_address`)) {
        queryParams['full_address'] <- full_address
      }

      urlPath <- "/facility/match"
      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) {
        returnObject <- Facility$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    search_facility = function(full_address, company_name, page, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`full_address`)) {
        queryParams['full_address'] <- full_address
      }

      if (!missing(`company_name`)) {
        queryParams['company_name'] <- company_name
      }

      if (!missing(`page`)) {
        queryParams['page'] <- page
      }

      urlPath <- "/facility/search"
      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) {
        returnObject <- Facilities$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    }
  )
)
altana-tech/atlas-api-r-sdk documentation built on Dec. 19, 2021, 1:36 a.m.