Request {sched} | R Documentation |
Class Request.
Description
Class Request.
Class Request.
Details
This class represents a Request object that can be used with the Request Scheduler.
Methods
Public methods
Method new()
Initializer.
Usage
Request$new( url, method = c("get", "post"), header = NULL, body = NULL, encoding = NULL )
Arguments
url
A
sched::URL
object.method
HTTP method. Either "get" or "post".
header
The header of the POST method as a named character vector. The names are the fields of the header.
body
The body as a character single value.
encoding
The encoding to use. A valid integer or string as required by RCurl.
Returns
Nothing.
Examples
# Create a GET request for the getCompleteEntity webservice of ChEBI # database request <- sched::Request$new( sched::URL$new( 'https://www.ebi.ac.uk/webservices/chebi/2.0/test/getCompleteEntity', params=c(chebiId=15440))) # Create a POST Request object for the records-batch-post webservice of # ChemSpider database request <- sched::Request$new( url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records', 'batch')), method='post', header=c('Content-Type'="", apikey='my-token'), body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}')
Method getUrl()
Gets the URL.
Usage
Request$getUrl()
Returns
The URL of this Request object as a sched::URL object.
Examples
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the stored URL object print(request$getUrl())
Method getMethod()
Gets the method.
Usage
Request$getMethod()
Returns
The method as a character value.
Examples
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the stored method print(request$getMethod())
Method getEncoding()
Gets the encoding.
Usage
Request$getEncoding()
Returns
The encoding.
Examples
# Create a GET request request <- sched::Request$new(sched::URL$new('https://my.site.fr/'), encoding='UTF-8') # Get the stored encoding print(request$getEncoding())
Method getCurlOptions()
Gets the options object to pass to cURL library.
Make a RCurl::CURLOptions object by calling RCurl::curlOptions() function. Useragent, header and body are passed as options if not NULL.
Usage
Request$getCurlOptions(useragent = NULL)
Arguments
useragent
The user agent as a character value, or NULL.
Returns
An RCurl::CURLOptions object.
Examples
# Create a POST Request object for the records-batch-post webservice of # ChemSpider database request <- sched::Request$new( url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records', 'batch')), method='post', header=c('Content-Type'="", apikey='my-token'), body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}') # Get the associated RCurl options object rcurl_opts <- request$getCurlOptions('myapp ; me@my.address')
Method getUniqueKey()
Gets a unique key to identify this request.
The key is an MD5 sum computed from the string representation of this request.
Usage
Request$getUniqueKey()
Returns
A unique key as an MD5 sum.
Examples
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the MD5 sum of this request print(request$getUniqueKey())
Method getHeaderAsSingleString()
Gets the HTTP header as a string, concatenating all its information into a single string.
Usage
Request$getHeaderAsSingleString()
Returns
The header as a single character value.
Examples
# Create a POST Request object for the records-batch-post webservice of # ChemSpider database request <- sched::Request$new( url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records', 'batch')), method='post', header=c('Content-Type'="", apikey='my-token'), body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}') # Get back the POST header as a single string print(request$getHeaderAsSingleString())
Method getBody()
Gets the body.
Usage
Request$getBody()
Returns
The body as a single character value.
Examples
# Create a POST Request object for the records-batch-post webservice of # ChemSpider database request <- sched::Request$new( url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records', 'batch')), method='post', header=c('Content-Type'="", apikey='my-token'), body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}') # Get back the POST body print(request$getBody())
Method print()
Displays information about this instance.
Usage
Request$print()
Returns
self as invisible.
Examples
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Print the Request object print(request)
Method toString()
Gets a string representation of this instance.
Usage
Request$toString()
Returns
A single string giving a representation of this instance.
Examples
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the string representation of this request print(request$toString())
Method clone()
The objects of this class are cloneable with this method.
Usage
Request$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
# Create a GET request for the getCompleteEntity webservice of ChEBI database
request <- sched::Request$new(
sched::URL$new(
'https://www.ebi.ac.uk/webservices/chebi/2.0/test/getCompleteEntity',
params=c(chebiId=15440)))
# Get an MD5 key, unique to this request
key <- request$getUniqueKey()
# Print the request
print(request)
## ------------------------------------------------
## Method `Request$new`
## ------------------------------------------------
# Create a GET request for the getCompleteEntity webservice of ChEBI
# database
request <- sched::Request$new(
sched::URL$new(
'https://www.ebi.ac.uk/webservices/chebi/2.0/test/getCompleteEntity',
params=c(chebiId=15440)))
# Create a POST Request object for the records-batch-post webservice of
# ChemSpider database
request <- sched::Request$new(
url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records',
'batch')),
method='post', header=c('Content-Type'="", apikey='my-token'),
body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}')
## ------------------------------------------------
## Method `Request$getUrl`
## ------------------------------------------------
# Create a GET request
request <- sched::Request$new(sched::URL$new('https://peakforest.org/'))
# Get the stored URL object
print(request$getUrl())
## ------------------------------------------------
## Method `Request$getMethod`
## ------------------------------------------------
# Create a GET request
request <- sched::Request$new(sched::URL$new('https://peakforest.org/'))
# Get the stored method
print(request$getMethod())
## ------------------------------------------------
## Method `Request$getEncoding`
## ------------------------------------------------
# Create a GET request
request <- sched::Request$new(sched::URL$new('https://my.site.fr/'),
encoding='UTF-8')
# Get the stored encoding
print(request$getEncoding())
## ------------------------------------------------
## Method `Request$getCurlOptions`
## ------------------------------------------------
# Create a POST Request object for the records-batch-post webservice of
# ChemSpider database
request <- sched::Request$new(
url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records',
'batch')),
method='post', header=c('Content-Type'="", apikey='my-token'),
body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}')
# Get the associated RCurl options object
rcurl_opts <- request$getCurlOptions('myapp ; me@my.address')
## ------------------------------------------------
## Method `Request$getUniqueKey`
## ------------------------------------------------
# Create a GET request
request <- sched::Request$new(sched::URL$new('https://peakforest.org/'))
# Get the MD5 sum of this request
print(request$getUniqueKey())
## ------------------------------------------------
## Method `Request$getHeaderAsSingleString`
## ------------------------------------------------
# Create a POST Request object for the records-batch-post webservice of
# ChemSpider database
request <- sched::Request$new(
url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records',
'batch')),
method='post', header=c('Content-Type'="", apikey='my-token'),
body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}')
# Get back the POST header as a single string
print(request$getHeaderAsSingleString())
## ------------------------------------------------
## Method `Request$getBody`
## ------------------------------------------------
# Create a POST Request object for the records-batch-post webservice of
# ChemSpider database
request <- sched::Request$new(
url=sched::URL$new(c('https://api.rsc.org/compounds/v1/', 'records',
'batch')),
method='post', header=c('Content-Type'="", apikey='my-token'),
body='{"recordIds": [2], "fields": ["SMILES","Formula","InChI"]}')
# Get back the POST body
print(request$getBody())
## ------------------------------------------------
## Method `Request$print`
## ------------------------------------------------
# Create a GET request
request <- sched::Request$new(sched::URL$new('https://peakforest.org/'))
# Print the Request object
print(request)
## ------------------------------------------------
## Method `Request$toString`
## ------------------------------------------------
# Create a GET request
request <- sched::Request$new(sched::URL$new('https://peakforest.org/'))
# Get the string representation of this request
print(request$toString())