Get the correct function to create the API call depending on the data item

get_function(data_item)

Arguments

data_item

character string; data item to be retrieved

Value

function

Examples

get_function("TEMP")
#> function (data_item, api_key, from_date = NULL, to_date = NULL, #> settlement_date = NULL, settlement_period = NULL, bm_unit_id = NULL, #> bm_unit_type = NULL, lead_party_name = NULL, ngc_bm_unit_name = NULL, #> from_cleared_date = NULL, to_cleared_date = NULL, is_two_day_window = NULL, #> from_datetime = NULL, to_datetime = NULL, from_settlement_date = NULL, #> to_settlement_date = NULL, period = NULL, fuel_type = NULL, #> balancing_service_volume = NULL, zone_identifier = NULL, #> start_time = NULL, end_time = NULL, trade_name = NULL, trade_type = NULL, #> api_version = "v1", service_type = "csv") #> { #> request <- list() #> check_data_item(data_item, "Legacy") #> request$url = paste0("https://api.bmreports.com/BMRS/", data_item, #> "/", api_version, "?APIKey=", api_key) #> if (!is.null(from_date)) { #> request$url = paste0(request$url, "&FromDate=", format_date(from_date)) #> } #> if (!is.null(to_date)) { #> request$url = paste0(request$url, "&ToDate=", format_date(to_date)) #> } #> if (!is.null(settlement_date)) { #> request$url = paste0(request$url, "&SettlementDate=", #> format_date(settlement_date)) #> } #> if (!is.null(settlement_period)) { #> if (settlement_period <= 0 | settlement_period > 50) { #> if (settlement_period != "*") { #> stop("invalid settlemet_period value") #> } #> } #> request$url = paste0(request$url, "&SettlementPeriod=", #> settlement_period) #> } #> if (!is.null(bm_unit_id)) { #> request$url = paste0(request$url, "&BMUnitID=", bm_unit_id) #> } #> if (!is.null(bm_unit_type)) { #> request$url = paste0(request$url, "&BMUnitType=", bm_unit_type) #> } #> if (!is.null(lead_party_name)) { #> request$url = paste0(request$url, "&LeadPartName=", lead_party_name) #> } #> if (!is.null(ngc_bm_unit_name)) { #> request$url = paste0(request$url, "&NGCBMUnitName=", #> ngc_bm_unit_name) #> } #> if (!is.null(from_cleared_date)) { #> request$url = paste0(request$url, "&FromClearedDate=", #> format_date(from_cleared_date)) #> } #> if (!is.null(to_cleared_date)) { #> request$url = paste0(request$url, "&ToClearedDate=", #> format_date(to_cleared_date)) #> } #> if (!is.null(is_two_day_window)) { #> request$url = paste0(request$url, "&IsTwoDayWindow=", #> is_two_day_window) #> } #> if (!is.null(from_datetime)) { #> request$url = paste0(request$url, "&FromDateTime=", format_datetime(from_datetime)) #> } #> if (!is.null(to_datetime)) { #> request$url = paste0(request$url, "&ToDateTime=", format_datetime(to_datetime)) #> } #> if (!is.null(from_settlement_date)) { #> request$url = paste0(request$url, "&FromSettlementDate=", #> format_date(from_settlement_date)) #> } #> if (!is.null(to_settlement_date)) { #> request$url = paste0(request$url, "&ToSettlementDate=", #> format_date(to_settlement_date)) #> } #> if (!is.null(period)) { #> if (period <= 0 | period > 50) { #> stop("invalid period value") #> } #> request$url = paste0(request$url, "&Period=", period) #> } #> if (!is.null(fuel_type)) { #> request$url = paste0(request$url, "&FuelType=", fuel_type) #> } #> if (!is.null(balancing_service_volume)) { #> request$url = paste0(request$url, "&BalancingServiceVolume=", #> balancing_service_volume) #> } #> if (!is.null(zone_identifier)) { #> request$url = paste0(request$url, "&ZoneIdentifier=", #> zone_identifier) #> } #> if (!is.null(start_time)) { #> request$url = paste0(request$url, "&StartTime=", format_time(start_time)) #> } #> if (!is.null(end_time)) { #> request$url = paste0(request$url, "&EndTime=", format_time(end_time)) #> } #> if (!is.null(trade_name)) { #> request$url = paste0(request$url, "&TradeName=", trade_name) #> } #> if (!is.null(trade_type)) { #> request$url = paste0(request$url, "&TradeType=", trade_type) #> } #> if (!is.null(service_type)) { #> request$url = paste0(request$url, "&ServiceType=", service_type) #> } #> request$service_type <- service_type #> request$data_item <- data_item #> return(request) #> } #> <bytecode: 0x0bff6398> #> <environment: namespace:BMRSr>