Title: | R Wrapper for 'Airly' API |
---|---|
Description: | Get information about air quality using 'Airly' <https://airly.eu/> API through R. |
Authors: | Piotr Janus [cre, aut] |
Maintainer: | Piotr Janus <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-19 03:13:46 UTC |
Source: | https://github.com/piotrekjanus/airly |
Return base url of Airly API v2
.base_url()
.base_url()
Get apikey that was set by user
.get_apikey()
.get_apikey()
apikey value of set api key
Sends a request to the specified url and retrieves it's content.
.send_request(request_url, apikey, query = NULL)
.send_request(request_url, apikey, query = NULL)
request_url |
url to be used |
apikey |
airly apikey |
query |
Default value is NULL. Optional argument if you want to add query to request |
parsed content of the response object
Adds the json extension to the given url
add_json_extension(url)
add_json_extension(url)
url |
base url to which the json extension should be added |
url with the json extension added
Adds the given path to the given url
add_path(url, path)
add_path(url, path)
url |
base url to which the path should be added |
path |
path that should be added to the url |
url with the given path added
Asserts a given expression and throws an error if it returns FALSE
assert(expression, error)
assert(expression, error)
expression |
R expression to be evaluated |
error |
message to be displayed when the expression is not fulfilled |
Checks whether apikey is correctly set
assert_apikey(key)
assert_apikey(key)
key |
airly apikey |
Checks whether apikey is correctly set
assert_coordinates(lat, lng)
assert_coordinates(lat, lng)
lat |
latitude as decimal degree |
lng |
longitude as decimal degree |
Checks whether ids are correctly defined. If not throws an error
assert_ids(ids)
assert_ids(ids)
ids |
maximum number of ids to retrieve |
Creates an object representing Airly measurement
build_current_df(item)
build_current_df(item)
item |
list returned by Airly API |
object representing a airly_measurement
Creates object containing information about history data for given API response
build_forecast_df(item)
build_forecast_df(item)
item |
list returned by Airly API |
tibble representing a airly_measurement with time, measures and indexes fields
Creates object containing information about history data for given API response
build_history_df(item)
build_history_df(item)
item |
list returned by Airly API |
tibble representing a airly_measurement with time, measures and indexes fields
Creates an object representing a response from the Airly API. Also every API call return information about current limits What is used to assign variables in pkg.env
create_airly_api_response(response)
create_airly_api_response(response)
response |
response object |
object representing a response from the Airly API
Creates an object representing Airly location
create_airly_location(item)
create_airly_location(item)
item |
list returned by Airly API |
tibble representing an airly_location
Creates an object representing Airly measurement
create_airly_measurement(item)
create_airly_measurement(item)
item |
list returned by Airly API |
object representing a airly_measurement
Creates a data.frame representing Airly meta
create_airly_meta(item)
create_airly_meta(item)
item |
list returned by Airly API |
data.frame representing an airly_meta
Creates a request url based on the given base url and passed paths. The json extensions is added automatically.
create_request_url(url, paths, add_json_ext = TRUE)
create_request_url(url, paths, add_json_ext = TRUE)
url |
base url of the request |
paths |
vector of paths that should be added to the url |
add_json_ext |
boolean indicating if include ".json" at the end of request |
request url with added paths and the json extension
Retrieves the response content
get_content(x)
get_content(x)
x |
airly_api_response object to retrieve content from |
content of the given airly_api_response object
Endpoint returns a list of all the index types supported in the API along with lists of levels defined per each index type.
get_indexes()
get_indexes()
object of airly_meta class
get_indexes()
get_indexes()
Endpoint returns single installation metadata, given by id
get_installation_by_id(id)
get_installation_by_id(id)
id |
integer |
airly_location item
get_installation_by_id(2137)
get_installation_by_id(2137)
Endpoint returns measurements for concrete installation given by installation Id
get_installation_measurements(id)
get_installation_measurements(id)
id |
integer, installation identifier |
object of airly_measurements class
get_installation_measurements(8077)
get_installation_measurements(8077)
Endpoint returns list of all the measurement types supported in the API along with their names and units.
get_measurements_info()
get_measurements_info()
data.frame with measure names and units
get_measurements_info()
get_measurements_info()
Endpoint returns list of installations which are closest to a given point, sorted by distance to that point.
get_nearest_installations(lat, lng, max_distance = NULL, max_results = NULL)
get_nearest_installations(lat, lng, max_distance = NULL, max_results = NULL)
lat |
latitude as decimal degree |
lng |
longitude as decimal degree |
max_distance |
default value 3.0. All the returned installations must be located within this limit from the given point (in km). Negative value means no limit |
max_results |
default value 1. Maximum number of installations to return. Negative value means no limit |
data.frame of airly_location items
get_nearest_installations(50.11670, 19.91429, max_distance = 20)
get_nearest_installations(50.11670, 19.91429, max_distance = 20)
Endpoint returns measurements for an installation closest to a given location
get_nearest_measurements(lat, lng, max_distance = NULL)
get_nearest_measurements(lat, lng, max_distance = NULL)
lat |
latitude as decimal degree |
lng |
longitude as decimal degree |
max_distance |
default value 3.0. All the returned installations must be located within this limit from the given point (in km). Negative value means no limit |
data.frame of airly_measurements items
get_nearest_measurements(50.11670, 19.91429, max_distance = 10)
get_nearest_measurements(50.11670, 19.91429, max_distance = 10)
Endpoint returns measurements for any geographical location
get_point_measurements(lat, lng)
get_point_measurements(lat, lng)
lat |
latitude as decimal degree |
lng |
longitude as decimal degree |
object of airly_measurements class
get_point_measurements(50.11670, 19.91429)
get_point_measurements(50.11670, 19.91429)
Checks whether the given object is of the class airly_api_response
is_airly_api_response(x)
is_airly_api_response(x)
x |
object to test if it is of the class airly_api_response |
TRUE if the object is of the class airly_api_response
Checks whether the given object is of the class airly_location
is_airly_location(x)
is_airly_location(x)
x |
object to test if it is of the class airly_location |
TRUE if the object is of the class airly_location
Checks whether the given object is of the class airly_measurement
is_airly_measurement(x)
is_airly_measurement(x)
x |
object to test if it is of the class airly_measurement |
TRUE if the object is of the class airly_measurement
Parses a json response
parse_json(response)
parse_json(response)
response |
response object to parse |
parsed content of the given response
Print for "airly_measurement" type objects
## S3 method for class 'airly_measurement' print(x, ...)
## S3 method for class 'airly_measurement' print(x, ...)
x |
"airly_measurement" type list |
... |
further arguments passed to or from other methods |
Default rate limit per apikey is 100 API requests per day for all users. In order to get information, user has to make at least one request.
remaining_requests()
remaining_requests()
list containing information about remaining requests and daily limit
# Make any request before calling this function remaining_requests()
# Make any request before calling this function remaining_requests()
Replaces NULL with NA for nested lists. Useful when NULL value leads to error while object casting
replace_null(x)
replace_null(x)
x |
nested list |
same list with NULL replaced with NA
On a free plan, API consumer is required to use our API only in non-commercial projects. More details are available in under https://airly.eu/docs/tos-en.pdf.
set_apikey(key)
set_apikey(key)
key |
string. Get your api key https://developer.airly.eu/ |
set_apikey("abctest")
set_apikey("abctest")
Checks if the given response is not empty and that it did not return an error http code.
validate_airly_api_response(airly_api_response)
validate_airly_api_response(airly_api_response)
airly_api_response |
airly_api_response object to be checked |
Checks whether the given object is correctly defined airly_location class
validate_airly_location(airly_location)
validate_airly_location(airly_location)
airly_location |
tibble airly_location |
Checks whether the given object is correctly defined airly_measurement class
validate_airly_measurement(airly_measurement)
validate_airly_measurement(airly_measurement)
airly_measurement |
object of the class airly_measurement |
Checks whether the given object is correctly correctly defined
validate_airly_meta(airly_meta)
validate_airly_meta(airly_meta)
airly_meta |
object of the class airly_meta |