LufthansaR
is an API wrapper package for R. It enables programmers to access to Lufthansa Open API from R environment.
This document introduces you to LufthansaR's basic set of tools, and show how to use them. Once you have installed the package, read vignette("LufthansaR")
to learn more.
To have access to Lufthansa Open API, one has to sign in to Mashery, Lufthansa's developer platform, and apply for a key. Please visit here. Once you are registered, you will be given:
- a key and
- a secret
These two values can be exchanged for a short-lived access token. A valid access token must be sent with every API request while accessing any Lufthansa's API. In other words, every Lufthansa API requires you to pass Oauth token when getting the data from it.
You can install LufthansaR
development version from GitHub
devtools::install_github("peter0083/LufthansaR")
CRAN version of the package will be scheduled to be added in the next version.
You can install LufthansaR
development version from GitHub
devtools::install_github("peter0083/LufthansaR")
You can load LufthansaR
as follows.
library(LufthansaR)
This will load the core lufthansaR
functions.
Setup your API key and secret in the environment.
Use the get_token()
function to create an access token.
LufthansaR::get_token()
You can store your client ID and secret in a ~/.Renviron
file. R loads this file as
a system variable in each new session. The package uses these variables to request
new keys if needed. The .Renviron
file should contain the lines
LUFTHANSA_API_CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxx'
LUFTHANSA_API_CLIENT_SECRET = 'xxxxxxxxxx'
which specify the key and secret pair. This package does not remember the id or the secret.
NOTE: The name of the variables should be EXACTLY:
LUFTHANSA_API_CLIENT_ID
LUFTHANSA_API_CLIENT_SECRET
Because tokens last for 1.5 days and to prevent the abuse of continuously requesting
new tokens, the package by default stores the token and its expiry in a file in the
working directory called .lufthansa-token
. Caching the token provides a way of
using it across R sessions until it expires. Functions in the package use the get_token()
command to access the API. For more information about the function, see help(get_token)
.
Caching the token can be turned off by setting the following R option through
options(lufthansar_token_cache = FALSE)
Alternately, one can choose where to cache the token by using a filename instead
options(lufthansar_token_cache = 'path/to/.token-cache')
Users can see the token being used and its expiry by calling
LufthansaR::get_creds_from_env()
LufthansaR
has four core functions:
-
get_flight_status()
provides on the status of a given flight and day -
get_flight_status_arrival()
provides information about all flights arriving at a given airport on a given day -
get_flight_status_departure()
provides information about all flights departing from a given airport on a given day -
airport()
provides general information about a given airport
To learn how to use these LufthansaR
functions, refer to the LufthansaR Vignette.
The mobile-friendly LufthansaR Vignette is hosted on Wordpress.
To uninstall LufthansaR
, simply run:
remove.packages('LufthansaR')
The MIT License: see LICENSE
If you have trouble with this package, you can get help us improve by creating an issue in this repo. Please use the template provided to ensure we have all the information needed to help solve the issue
If you are interested in being a contributor to LufthansaR
, consult our contributing policies, and send us a pull request!
Dependencies:
httr,
glue (>= 1.2.0),
lubridate,
tidyverse
RoxygenNote: 6.0.1
testthat,
knitr,
rmarkdown