Skip to content

Commit 6de191b

Browse files
authored
Merge pull request #1 from eea/develop
Stable version
2 parents 7bd3b08 + 8d2b9f7 commit 6de191b

28 files changed

+2737
-2
lines changed

.Rbuildignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
.lintr
4+
^doc$
5+
^Meta$

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata
5+
.Renviron
6+
hdar.Rproj
7+
inst/doc
8+
/Meta/
9+
/doc/

.lintr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters: linters_with_defaults(
2+
line_length_linter(156),
3+
commented_code_linter = NULL
4+
)

DESCRIPTION

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Package: hdar
2+
Type: Package
3+
Title: REST API Client for Accessing Data on WEkEO HDA V2
4+
Version: 1.0.0
5+
URL: https://www.wekeo.eu/
6+
BugReports: https://github.com/eea/hdar/issues
7+
Authors@R: person("Matteo", "Mattiuzzi", email = "matteo@mattiuzzi.com", role = c("aut", "cre"))
8+
Maintainer: Matteo Mattiuzzi <matteo@mattiuzzi.com>
9+
Description: Download Copernicus data from WEkEO by means of HTTPS REST queries.
10+
License: EUPL (>= 1.2) | file LICENSE
11+
Encoding: UTF-8
12+
RoxygenNote: 7.3.1
13+
Imports:
14+
R6,
15+
httr2,
16+
jsonlite,
17+
magrittr,
18+
htmltools,
19+
stringr,
20+
humanize
21+
Depends:
22+
R (>= 2.10),
23+
Suggests:
24+
knitr,
25+
rmarkdown
26+
VignetteBuilder: knitr

NAMESPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(Auth)
4+
export(Client)
5+
export(SearchResults)
6+
importFrom(R6,R6Class)
7+
importFrom(htmltools,HTML)
8+
importFrom(htmltools,html_print)
9+
importFrom(htmltools,tagAppendChild)
10+
importFrom(htmltools,tagList)
11+
importFrom(htmltools,tags)
12+
importFrom(httr2,req_body_json)
13+
importFrom(httr2,req_method)
14+
importFrom(httr2,req_url_query)
15+
importFrom(httr2,request)
16+
importFrom(jsonlite,toJSON)
17+
importFrom(magrittr,"%>%")
18+
importFrom(stringr,str_detect)

R/auth.R

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#' @title Auth Class
2+
#'
3+
#' @description
4+
#' Authorization
5+
#'
6+
#' @importFrom R6 R6Class
7+
#' @importFrom magrittr %>%
8+
#' @export
9+
Auth <- R6::R6Class("Auth", # nolint: object_name_linter.
10+
public = list(
11+
12+
#' @description
13+
#' This function initializes a new instance of the `Auth` class with the specified parameters.
14+
#'
15+
#' @param user A character string representing the username for authentication.
16+
#' @param password A character string representing the password for authentication.
17+
#'
18+
#' @return An instance of the `Auth` class.
19+
#' @export
20+
initialize = function(user = NULL, password = NULL) {
21+
private$user <- user
22+
private$password <- password
23+
},
24+
25+
#' @description
26+
#' This function retrieves a previously generated token.
27+
#'
28+
#' @return A character string representing the retrieved token.
29+
#' @export
30+
token = function() {
31+
if (is.null(private$token_value)) {
32+
self$get_token()
33+
}
34+
private$token_value
35+
},
36+
37+
#' @description
38+
#' This function generates a unique token for authentication or other purposes.
39+
#'
40+
#' @return A character string representing the generated token.
41+
#' @export
42+
get_token = function() {
43+
url <- paste0(private$apiUrl, "/gettoken")
44+
45+
params <- list(
46+
"username" = private$user,
47+
"password" = private$password
48+
)
49+
req <- httr2::request(url) %>%
50+
httr2::req_method("POST") %>%
51+
httr2::req_body_json(params)
52+
53+
try(req %>% httr2::req_perform())
54+
resp <- httr2::last_response()
55+
56+
if (resp$status_code == 200) {
57+
resp_body <- resp %>% httr2::resp_body_json()
58+
private$token_value <- resp_body$access_token
59+
return(private$token_value)
60+
}
61+
62+
private$token_value <- NULL
63+
stop(resp$detail)
64+
}
65+
),
66+
private = list(
67+
apiUrl = "https://gateway.prod.wekeo2.eu/hda-broker",
68+
token_value = NULL,
69+
user = NULL,
70+
password = NULL
71+
)
72+
)

0 commit comments

Comments
 (0)