R/bulk_api.R

# GraphSense API
#
# GraphSense API provides programmatic access to various ledgers' addresses, entities, blocks, transactions and tags for automated and highly efficient forensics tasks.
#
# The version of the OpenAPI document: 1.0.1
# Contact: contact@ikna.io
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title Bulk operations
#' @description graphsense.Bulk
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ BulkCsv } \emph{ Get data as CSV in bulk }
#' 
#'
#' \itemize{
#' \item \emph{ @param } currency character
#' \item \emph{ @param } operation Enum < [get_block, list_block_txs, get_address, list_address_txs, list_tags_by_address, list_address_neighbors, get_address_entity, list_address_links, get_entity, list_address_tags_by_entity, list_entity_neighbors, list_entity_txs, list_entity_links, list_entity_addresses, get_tx, get_tx_io, get_exchange_rates] > 
#' \item \emph{ @param } num.pages integer
#' \item \emph{ @param } body object
#'
#'
#' \item status code : 200 | OK
#'
#' \item return type : character 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ BulkJson } \emph{ Get data as JSON in bulk }
#' 
#'
#' \itemize{
#' \item \emph{ @param } currency character
#' \item \emph{ @param } operation Enum < [get_block, list_block_txs, get_address, list_address_txs, list_tags_by_address, list_address_neighbors, get_address_entity, list_address_links, get_entity, list_address_tags_by_entity, list_entity_neighbors, list_entity_txs, list_entity_links, list_entity_addresses, get_tx, get_tx_io, get_exchange_rates] > 
#' \item \emph{ @param } num.pages integer
#' \item \emph{ @param } body object
#' \item \emph{ @returnType } list( \link{map} ) \cr
#'
#'
#' \item status code : 200 | OK
#'
#' \item return type : array[map(object)] 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  BulkCsv  ####################
#'
#' library(graphsense)
#' var.currency <- 'btc' # character | The cryptocurrency code (e.g., btc)
#' var.operation <- 'get_block' # character | The operation to execute in bulk
#' var.num.pages <- 1 # integer | Number of pages to retrieve for operations with list response
#' var.body <- {"height":[1,2,3]} # object | Map of the operation's parameter names to (arrays of) values
#'
#' #Get data as CSV in bulk
#' api.instance <- BulkApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['Authorization'] <- 'WRITE_YOUR_API_KEY_HERE';
#'
#' result <- api.instance$BulkCsv(var.currency, var.operation, var.num.pages, var.body)
#'
#'
#' ####################  BulkJson  ####################
#'
#' library(graphsense)
#' var.currency <- 'btc' # character | The cryptocurrency code (e.g., btc)
#' var.operation <- 'get_block' # character | The operation to execute in bulk
#' var.num.pages <- 1 # integer | Number of pages to retrieve for operations with list response
#' var.body <- NULL # object | Map of the operation's parameter names to (arrays of) values
#'
#' #Get data as JSON in bulk
#' api.instance <- BulkApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['Authorization'] <- 'WRITE_YOUR_API_KEY_HERE';
#'
#' result <- api.instance$BulkJson(var.currency, var.operation, var.num.pages, var.body)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
BulkApi <- R6::R6Class(
  'BulkApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    BulkCsv = function(currency, operation, num.pages, body, ...){
      apiResponse <- self$BulkCsvWithHttpInfo(currency, operation, num.pages, body, ...)
      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
      }
    },

    BulkCsvWithHttpInfo = function(currency, operation, num.pages, body, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

      queryParams['num_pages'] <- num.pages

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

      urlPath <- "/{currency}/bulk.csv/{operation}"
      if (!missing(`currency`)) {
        urlPath <- gsub(paste0("\\{", "currency", "\\}"), URLencode(as.character(`currency`), reserved = TRUE), urlPath)
      }

      if (!missing(`operation`)) {
        urlPath <- gsub(paste0("\\{", "operation", "\\}"), URLencode(as.character(`operation`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("Authorization" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["Authorization"]) > 0) {
        headerParams['Authorization'] <- paste(unlist(self$apiClient$apiKeys["Authorization"]), collapse='')
      }

      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, "character", loadNamespace("graphsense")),
          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)
      }
    },
    BulkJson = function(currency, operation, num.pages, body, ...){
      apiResponse <- self$BulkJsonWithHttpInfo(currency, operation, num.pages, body, ...)
      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
      }
    },

    BulkJsonWithHttpInfo = function(currency, operation, num.pages, body, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

      queryParams['num_pages'] <- num.pages

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

      urlPath <- "/{currency}/bulk.json/{operation}"
      if (!missing(`currency`)) {
        urlPath <- gsub(paste0("\\{", "currency", "\\}"), URLencode(as.character(`currency`), reserved = TRUE), urlPath)
      }

      if (!missing(`operation`)) {
        urlPath <- gsub(paste0("\\{", "operation", "\\}"), URLencode(as.character(`operation`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("Authorization" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["Authorization"]) > 0) {
        headerParams['Authorization'] <- paste(unlist(self$apiClient$apiKeys["Authorization"]), collapse='')
      }

      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, "array[map(object)]", loadNamespace("graphsense")),
          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)
      }
    }
  )
)
graphsense/rgraphsense documentation built on Sept. 2, 2022, 1:45 p.m.