Package 'hakaiApi'

Title: Authenticated HTTP Request Client for the 'Hakai' API
Description: Initializes a class that obtains API credentials and provides a method to use those credentials to make GET requests to the 'Hakai' API server. Usage instructions are documented at <https://hakaiinstitute.github.io/hakai-api/>.
Authors: Taylor Denouden [aut, cre], Brett Johnson [aut], Nate Rosenstock [ctb], Chris Davis [ctb]
Maintainer: Taylor Denouden <[email protected]>
License: MIT + file LICENSE
Version: 1.0.2
Built: 2025-02-16 02:45:18 UTC
Source: https://github.com/hakaiinstitute/hakai-api-client-r

Help Index


The Hakai API Client Class

Description

Class to use to make authenticated API requests for Hakai data

Public fields

api_root

The api_root you are logged in to

Methods

Public methods


Method new()

Log into Google to gain credential access to the API

Usage
Client$new(
  api_root = "https://hecate.hakai.org/api",
  login_page = "https://hecate.hakai.org/api-client-login"
)
Arguments
api_root

Optional API base url to fetch data. Defaults to "https://hecate.hakai.org/api"

login_page

Optional API login page url to display to user. Defaults to "https://hecate.hakai.org/api-client-login"

Returns

A client instance

Examples
client <- Client$new()

Method get()

Send a GET request to the API

Usage
Client$get(endpoint_url)
Arguments
endpoint_url

The full API url to fetch data from

Returns

A dataframe of the requested data

Examples
client$get("https://hecate.hakai.org/api/aco/views/projects")

Method post()

Send a POST request to the API

Usage
Client$post(endpoint_url, rec_data)
Arguments
endpoint_url

The full API url to fetch data from

rec_data

dataframe, list, or other R data structure to send as part of the post request payload

Returns

post request response status code and description


Method put()

Send a PUT request to the API

Usage
Client$put(endpoint_url, rec_data)
Arguments
endpoint_url

The full API url to fetch data from

rec_data

dataframe, list, or other R data structure to send as part of the post request payload

Returns

PUT request response status code and description


Method patch()

Send a PATCH request to the API

Usage
Client$patch(endpoint_url, rec_data)
Arguments
endpoint_url

The full API url to fetch data from

rec_data

dataframe, list, or other R data structure to send as part of the post request payload

Returns

PATCH request response status code and description


Method remove_credentials()

Remove your cached login credentials to logout of the client

Usage
Client$remove_credentials()
Examples
client$remove_credentials()

Method clone()

The objects of this class are cloneable with this method.

Usage
Client$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# Initialize a new client
client <- Client$new()
# Follow authorization prompts to log in

# Retrieve some data. See <https://hakaiinstitute.github.io/hakai-api/> for options.
url <- paste0(client$api_root, "/aco/views/projects?project_year=2020&fields=project_name")
projects_2020 <- client$get(url)

print(projects_2020)
# # A tibble: 20 x 1
#    project_name
#    <chr>
#  1 Fountain FN
#  2 Haig Glacier
#  3 Fraser River - Chimney Creek West William Canyon
#  4 Cruickshank WS
#  ...

## ------------------------------------------------
## Method `Client$new`
## ------------------------------------------------

client <- Client$new()

## ------------------------------------------------
## Method `Client$get`
## ------------------------------------------------

client$get("https://hecate.hakai.org/api/aco/views/projects")

## ------------------------------------------------
## Method `Client$remove_credentials`
## ------------------------------------------------

client$remove_credentials()