Request | R Documentation |
Class Request.
Class Request.
This class represents a Request object that can be used with the Request Scheduler.
new()
Initializer.
Request$new( url, method = c("get", "post"), header = NULL, body = NULL, encoding = NULL )
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.
Nothing.
# 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"]}')
getUrl()
Gets the URL.
Request$getUrl()
The URL of this Request object as a sched::URL object.
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the stored URL object print(request$getUrl())
getMethod()
Gets the method.
Request$getMethod()
The method as a character value.
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the stored method print(request$getMethod())
getEncoding()
Gets the encoding.
Request$getEncoding()
The encoding.
# 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())
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.
Request$getCurlOptions(useragent = NULL)
useragent
The user agent as a character value, or NULL.
An RCurl::CURLOptions object.
# 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')
getUniqueKey()
Gets a unique key to identify this request.
The key is an MD5 sum computed from the string representation of this request.
Request$getUniqueKey()
A unique key as an MD5 sum.
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the MD5 sum of this request print(request$getUniqueKey())
getHeaderAsSingleString()
Gets the HTTP header as a string, concatenating all its information into a single string.
Request$getHeaderAsSingleString()
The header as a single character value.
# 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())
getBody()
Gets the body.
Request$getBody()
The body as a single character value.
# 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())
print()
Displays information about this instance.
Request$print()
self as invisible.
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Print the Request object print(request)
toString()
Gets a string representation of this instance.
Request$toString()
A single string giving a representation of this instance.
# Create a GET request request <- sched::Request$new(sched::URL$new('https://peakforest.org/')) # Get the string representation of this request print(request$toString())
clone()
The objects of this class are cloneable with this method.
Request$clone(deep = FALSE)
deep
Whether to make a deep clone.
# 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())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.