Title: | Easily Import Data from Your 'ODK-X Sync Endpoint' |
Version: | 0.1.0 |
Description: | Provides helper functions for authenticating and retrieving data from your 'ODK-X Sync Endpoint'. This is an early release intended for testing and feedback. |
License: | MIT + file LICENSE |
Depends: | R (≥ 4.2.0) |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Suggests: | knitr, rmarkdown, tidyverse, magrittr, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
Imports: | dplyr, httr, jsonlite, purrr, tidyr, rlang |
NeedsCompilation: | no |
Packaged: | 2025-02-20 13:43:59 UTC; emil |
Author: | Emil Rossing [aut, cre] |
Maintainer: | Emil Rossing <hello@sapiens-solutions.com> |
Repository: | CRAN |
Date/Publication: | 2025-02-20 14:00:01 UTC |
Download attachments for table rows
Description
This function downloads attachments for the specified table rows and saves them in a structured directory. Each row with attachments will have a dedicated folder under the table-specific subdirectory.
Usage
download_attachments(
rows,
table_meta,
save_to_directory,
skip_if_instance_folder_exists = FALSE
)
Arguments
rows |
A tibble or data frame containing the table rows to download attachments for. |
table_meta |
List. Metadata for the table, as returned by |
save_to_directory |
String. The parent directory where attachments will be saved. A subdirectory with the name of the table will be created, and each row with attachments will have its own subfolder under this directory. |
skip_if_instance_folder_exists |
Logical. If |
Value
Invisibly returns NULL
. Downloads the attachments as a side effect.
Retrieve all rows from a table
Description
This function retrieves all rows for a given table from the ODK-X Sync Endpoint and tries to parse known types based on the table's schema definition.
Usage
get_all_rows(table_name)
Arguments
table_name |
String. The name of the table from which to retrieve rows. |
Value
A tibble containing all rows.
Retrieve API Credentials
Description
This function fetches the stored API credentials from environment variables.
Usage
get_credentials()
Value
A list containing username, password, and server_url.
Get Table Metadata
Description
Retrieves metadata for a given table from the ODK-X Sync Endpoint.
Usage
get_table_metadata(table_name)
Arguments
table_name |
A character string specifying the table name. |
Details
This function calls the ODK-X Sync Endpoint to fetch metadata
about a specific table. If the dataUri
field is missing in the response,
an error is thrown.
Value
A list containing table metadata.
Retrieve Tables from ODK-X Sync Endpoint
Description
This function retrieves the list of tables from the ODK-X Sync Endpoint by making a paginated GET request to
(<server_url>)/odktables/default/tables
. It uses BASIC authentication with the credentials stored via
rockx::set_username_and_password()
.
Usage
get_tables()
Value
A tibble containing the list of found tables.
Verifies the user has sufficient permissions to download data
Description
Before calling this function, first set username, password, and host with:
rockx::set_username_and_password()
.
Usage
has_access()
Value
TRUE or FALSE
Set Username, Password, and Server URL for API Authentication
Description
This function sets the environment variables ROCKX_USERNAME
, ROCKX_PASSWORD
, and ROCKX_SERVER_URL
for authentication and specifying the ODK-X Sync Endpoint.
Usage
set_username_and_password(username, password, server_url)
Arguments
username |
A character string containing the API username. |
password |
A character string containing the API password. |
server_url |
A character string containing the URL of the ODK-X sync endpoint (e.g., "https://my.sync-endpoint.com"). |
Value
A message confirming that credentials and server URL have been set.
Examples
rockx::set_username_and_password("my_user", "my_password", "https://my.sync-endpoint.com")