make call_cognitive_endpoint a generic

This commit is contained in:
Hong Ooi 2019-09-30 16:03:22 +10:00
Родитель f297aa557a
Коммит d7055d2c40
3 изменённых файлов: 22 добавлений и 7 удалений

Просмотреть файл

@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand
S3method(call_cognitive_endpoint,cognitive_endpoint)
S3method(print,cognitive_endpoint)
export(az_cognitive_service)
export(call_cognitive_endpoint)

Просмотреть файл

@ -73,6 +73,7 @@ print.cognitive_endpoint <- function(x, ...)
#' @param http_verb The HTTP verb for the REST call.
#' @param http_status_handler How to handle a failed REST call. `stop`, `warn` and `message` will call the corresponding `*_for_status` handler in the httr package; `pass` will return the raw response object unchanged. The last one is mostly intended for debugging purposes.
#' @param auth_header The name of the HTTP request header for authentication. Only used if a subscription key is supplied.
#' @param ... Further arguments passed to lower-level functions.
#' @details
#' This function does the low-level work of constructing a HTTP request and then calling the REST endpoint. It is meant to be used by other packages that provide higher-level views of the service functionality.
#'
@ -105,10 +106,18 @@ print.cognitive_endpoint <- function(x, ...)
#'
#' }
#' @export
call_cognitive_endpoint <- function(endpoint, operation, options=list(), headers=list(), body=NULL, encode=NULL,
http_verb=c("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"),
http_status_handler=c("stop", "warn", "message", "pass"),
auth_header="ocp-apim-subscription-key")
call_cognitive_endpoint <- function(endpoint, ...)
{
UseMethod("call_cognitive_endpoint")
}
#' @rdname call_cognitive_endpoint
#' @export
call_cognitive_endpoint.cognitive_endpoint <- function(endpoint, operation,
options=list(), headers=list(), body=NULL, encode=NULL, ...,
http_verb=c("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"),
http_status_handler=c("stop", "warn", "message", "pass"),
auth_header="ocp-apim-subscription-key")
{
url <- endpoint$url
url$path <- file.path(url$path, operation)

Просмотреть файл

@ -2,17 +2,22 @@
% Please edit documentation in R/endpoint.R
\name{call_cognitive_endpoint}
\alias{call_cognitive_endpoint}
\alias{call_cognitive_endpoint.cognitive_endpoint}
\title{Call a Cognitive Service REST endpoint}
\usage{
call_cognitive_endpoint(endpoint, operation, options = list(),
headers = list(), body = NULL, encode = NULL,
http_verb = c("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"),
call_cognitive_endpoint(endpoint, ...)
\method{call_cognitive_endpoint}{cognitive_endpoint}(endpoint, operation,
options = list(), headers = list(), body = NULL, encode = NULL,
..., http_verb = c("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"),
http_status_handler = c("stop", "warn", "message", "pass"),
auth_header = "ocp-apim-subscription-key")
}
\arguments{
\item{endpoint}{An object of class \code{cognitive_endpoint}.}
\item{...}{Further arguments passed to lower-level functions.}
\item{operation}{The operation to perform.}
\item{options}{Any query parameters that the operation takes.}