Package 'rockx'

Title: Easily Import Data from Your 'ODK-X Sync Endpoint'
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.
Authors: Emil Rossing [aut, cre]
Maintainer: Emil Rossing <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2025-02-20 15:25:33 UTC
Source: CRAN

Help Index


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 get_table_metadata(table_name).

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 TRUE, rows with an existing instance folder will be skipped to avoid re-downloading attachments. Defaults to FALSE.

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")