Interface class for the Kobo API that can handle KoboClient instances (sessions) for both API versions. The Class exposes both generic and specific methods for HTTP requests / interactions with the various endpoints.
Public fields
session_v2KoboClient session for v2 of the API
session_v1KoboClientsession for v1 of the API
Methods
Method new()
Initialization method for class "Kobo".
Usage
Kobo$new(
base_url_v2 = NULL,
base_url_v1 = NULL,
kobo_token = Sys.getenv("KBTBR_TOKEN"),
session_v2 = NULL,
session_v1 = NULL
)Arguments
base_url_v2character. The base URL of the API version 2 (known as /api/v2). For example: https://kobo.correlaid.org.
base_url_v1character. The base URL of the API of your KoBoCAT API (also known as /api/v1). Defaults to NULL. For example: https://kc.correlaid.org.
kobo_tokencharacter. The API token. Defaults to requesting the systen environment
KBTBR_TOKEN.session_v2KoboClient To pass directly a KoboClient instance for the API version v2.
session_v1KoboClient In addition to session_v2 one can pass also a KoboClient instance for the API version v1.
Method get()
Wrapper for the GET method of internal session objects.
Usage
Kobo$get(path, query = list(), version = "v2", format = "json", parse = TRUE)Arguments
pathcharacter. Path component of the endpoint.
querylist. A named list which is parsed to the query component. The order is not hierarchical.
versioncharacter. Indicates on which API version the request should be executed (available:
v1,v2). Defaults tov2.formatcharacter. the format to request from the server. either 'json' or 'csv'. defaults to 'json'
parsewhether or not to parse the HTTP response. defaults to TRUE.
Method post()
Wrapper for the POST method of internal session objects.
Arguments
pathcharacter. Path component of the endpoint.
bodyR list. A data payload to be sent to the server.
versioncharacter. Indicates on which API version the request should be executed (available:
v1,v2). Defaults tov2.
Returns
Returns an object of class crul::HttpResponse.
Method clone_asset()
Arguments
clone_fromcharacter. UID of the asset to be cloned.
new_namecharacter. Name of the new asset.
asset_typecharacter. Type of the new asset. Can be "block", "question", "survey", "template".
Returns
Returns an object of class crul::HttpResponse.
Method deploy_asset()
High-level POST request to deploy an asset.
assets/{uid}/deployment/ endpoint (due to
default to v2, no further specification is needed).
Returns
Returns an object of class crul::HttpResponse.
Method import_xls_form()
High-level POST request to import an XLS form. imports endpoint
(due to default to v2, no further specification is needed).
Arguments
namecharacter. Name of the new asset.
file_pathcharacter. The path to the XLS form file.
Returns
Returns an object of class crul::HttpResponse.
Method create_asset()
High-level POST request to create an empty asset. assets/ endpoint
(due to default to v2, no further specification is needed).
Arguments
namecharacter. Name of the new asset.
asset_typecharacter. Type of the new asset. Can be "block", "question", "survey", "template".
descriptioncharacter. Optional.
sectorA list with elements
labelandvalue. Optional. Corresponding labels and values can be found here.countryA list with elements
labelandvalue. Optional. Corresponding labels and values can be found here.share_metadataboolean. Optional.
Returns
Returns an object of class crul::HttpResponse.