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_v2
KoboClient session for v2 of the API
session_v1
KoboClient
session 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_v2
character. The base URL of the API version 2 (known as /api/v2). For example: https://kobo.correlaid.org.
base_url_v1
character. 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_token
character. The API token. Defaults to requesting the systen environment
KBTBR_TOKEN
.session_v2
KoboClient To pass directly a KoboClient instance for the API version v2.
session_v1
KoboClient 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
path
character. Path component of the endpoint.
query
list. A named list which is parsed to the query component. The order is not hierarchical.
version
character. Indicates on which API version the request should be executed (available:
v1
,v2
). Defaults tov2
.format
character. the format to request from the server. either 'json' or 'csv'. defaults to 'json'
parse
whether or not to parse the HTTP response. defaults to TRUE.
Method post()
Wrapper for the POST method of internal session objects.
Arguments
path
character. Path component of the endpoint.
body
R list. A data payload to be sent to the server.
version
character. 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_from
character. UID of the asset to be cloned.
new_name
character. Name of the new asset.
asset_type
character. 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
name
character. Name of the new asset.
file_path
character. 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
name
character. Name of the new asset.
asset_type
character. Type of the new asset. Can be "block", "question", "survey", "template".
description
character. Optional.
sector
A list with elements
label
andvalue
. Optional. Corresponding labels and values can be found here.country
A list with elements
label
andvalue
. Optional. Corresponding labels and values can be found here.share_metadata
boolean. Optional.
Returns
Returns an object of class crul::HttpResponse
.