#' Login
#'
#' Logs user into betfair exchange for a session
#'
#' @param username Betfair exchange username (email)
#' @param password Betfair exchange password
#' @param api_token API token
#'
#' @return The Login authentification output
#' @export
login <- function(username, password, api_token){
stopifnot(is.character(username))
stopifnot(is.character(password))
stopifnot(is.character(api_token))
credentials <- paste0("username=", username, "&password=", password)
head <- headers_login(api_token)
login_call <- httr::POST("https://identitysso.betfair.com/api/login",
query = credentials,
httr::add_headers("Accept" = "application/json",
"X-Application" = head$`X-Application`))
login_return <- httr::content(login_call)
if(login_return$status == "FAIL"){
stop(login_return$error)
}
login_output <- headers(api_token, authentification_token = login_return$token)
return(login_output)
}
#' Create headers for login
#'
#' Creates headers required for form submission for initial login
#'
#' @inheritParams login
#'
#' @return Login headers list
headers_login <- function(api_token){
list('Accept' = 'application/json', 'X-Application' = api_token)
}
#' Create headers
#'
#' Creates headers required for form submission
#'
#' @inheritParams login
#' @param authentification_token The session key (from login)
#'
#' @return Headers list
headers <- function(api_token, authentification_token){
list('Accept' = 'application/json', 'X-Application' = api_token,
'X-Authentication' = authentification_token, 'Content-Type' = 'application/json')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.