Client | R Documentation |
Class to use to make authenticated API requests for Hakai data
api_root
The api_root you are logged in to
new()
Log into Google to gain credential access to the API
Client$new( api_root = "https://hecate.hakai.org/api", login_page = "https://hecate.hakai.org/api-client-login" )
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"
A client instance
try( client <- Client$new() )
get()
Send a GET request to the API
Client$get(endpoint_url, col_types = NULL)
endpoint_url
The full API url to fetch data from
col_types
a readr type specification
A dataframe of the requested data
try(client$get("https://hecate.hakai.org/api/aco/views/projects"))
post()
Send a POST request to the API
Client$post(endpoint_url, rec_data)
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
post request response status code and description
put()
Send a PUT request to the API
Client$put(endpoint_url, rec_data)
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
PUT request response status code and description
patch()
Send a PATCH request to the API
Client$patch(endpoint_url, rec_data)
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
PATCH request response status code and description
remove_credentials()
Remove your cached login credentials to logout of the client
Client$remove_credentials()
try( client$remove_credentials() )
clone()
The objects of this class are cloneable with this method.
Client$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run:
# Initialize a new client
try(
client <- Client$new()
)
# Follow authorization prompts to log in
# Retrieve some data. See <https://hakaiinstitute.github.io/hakai-api/> for options.
try(
url <- paste0(client$api_root, "/aco/views/projects?project_year=2020&fields=project_name")
)
try(
projects_2020 <- client$get(url)
)
try(
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
# ...
## End(Not run)
## ------------------------------------------------
## Method `Client$new`
## ------------------------------------------------
try(
client <- Client$new()
)
## ------------------------------------------------
## Method `Client$get`
## ------------------------------------------------
try(client$get("https://hecate.hakai.org/api/aco/views/projects"))
## ------------------------------------------------
## Method `Client$remove_credentials`
## ------------------------------------------------
try(
client$remove_credentials()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.