Commit bb92b322 authored by Dorchies David's avatar Dorchies David
Browse files

refactor: clean code

Refs #1
parent f675149a
......@@ -5,7 +5,7 @@ export(get_user_id)
export(jump_to_mon_calendrier)
export(jump_to_pointage)
export(login)
export(set_cookie)
import(magrittr)
importFrom(httr,POST)
importFrom(httr,set_cookies)
importFrom(httr,user_agent)
......@@ -37,14 +37,13 @@ add_temps <- function(
POST(
paste(cfg$url_post_add, cfg$param_add, sep = "?"),
#user_agent(cfg$user_agent),
set_cookies(.cookies = cookies),
body = list(
date = date,
type_regulation = type_regulation,
commentaire = commentaire,
user_id = attr(session, "user_id"),
id_form = "form_add_regul",
id_form = cfg$form_add,
duree = duree
)
)
......
#' Convert Cookie string into a key value [character] [vector]
#'
#' @param cookies [character] in format "Cookie: key1=value1; key2=value2..."
#'
#' @return Named [character] [vector] with cookies
#' @export
#'
#' @examples
#' set_cookie("Cookie: SERVERID=6df7a8ae; PHPSESSID=nvda6b0h1; OSCONTROL=u3bmeg9hjfvr5")
set_cookie <- function(cookies) {
if(substr(cookies, 1, 8) != "Cookie: ") {
stop("`cookies` should be a string beginning by \"Cookie: \"")
}
lCookies <- strsplit(strsplit(substring(cookies, 9), "; ")[[1]], "=")
vCookies <- sapply(lCookies, function(x) x[2])
names(vCookies) <- sapply(lCookies, function(x) x[1])
class(vCookies) <- c("HatataCookie", class(vCookies))
return(vCookies)
}
......@@ -3,14 +3,4 @@ default:
url_pointage: https://temps-activites.inra.fr/temps/index.php?controller=Pointage/Feuille&action=showTempsTheorique&date_debut=%s&date_fin=%s&user_id=%s
url_post_add: https://temps-activites.inrae.fr/temps/index.php
param_add: controller=Regulation&action=add
user_agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0
headers:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
headers_login:
Content-Type: application/x-www-form-urlencoded
Origin: https://idp.inra.fr
Referer: https://idp.inra.fr/cas/login
form_add: form_add_regul
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/set_cookie.R
\name{set_cookie}
\alias{set_cookie}
\title{Convert Cookie string into a key value \link{character} \link{vector}}
\usage{
set_cookie(cookies)
}
\arguments{
\item{cookies}{\link{character} in format "Cookie: key1=value1; key2=value2..."}
}
\value{
Named \link{character} \link{vector} with cookies
}
\description{
Convert Cookie string into a key value \link{character} \link{vector}
}
\examples{
set_cookie("Cookie: SERVERID=6df7a8ae; PHPSESSID=nvda6b0h1; OSCONTROL=u3bmeg9hjfvr5")
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment