From 82e7bf2805db40e67c30974d9c897d255cef3c6a Mon Sep 17 00:00:00 2001 From: eblondel Date: Tue, 29 Nov 2022 23:09:09 +0100 Subject: [PATCH] fix #15 --- DESCRIPTION | 4 ++-- NEWS.md | 8 +++++++- R/StoragehubManager.R | 31 ++++++++++++++++++++----------- man/StoragehubManager.Rd | 21 +++++++++++++++++++++ 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 00bf8e5..cff10df 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: d4storagehub4R -Version: 0.4-1 -Date: 2022-08-19 +Version: 0.4-2 +Date: 2022-11-29 Title: Interface to 'D4Science' 'StorageHub' API Authors@R: c( person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762"))) diff --git a/NEWS.md b/NEWS.md index 2b6dbc0..b49857d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,16 @@ +## [d4storagehub4R 0.4-2](https://cran.r-project.org/package=d4storagehub4R) | [![CRAN_Status_Badge](https://img.shields.io/badge/CRAN-published-blue.svg)](https://cran.r-project.org/package=d4storagehub4R) + +**New features** + +* [#15](https://github.com/eblondel/d4storagehub4R/issues/15) Support `getPublicFileLinkByID` method + ## [d4storagehub4R 0.4-1](https://cran.r-project.org/package=d4storagehub4R) | [![CRAN_Status_Badge](https://img.shields.io/badge/CRAN-published-blue.svg)](https://cran.r-project.org/package=d4storagehub4R) **Enhancements** * [#14](https://github.com/eblondel/d4storagehub4R/issues/14) Upgrade roxygen2 7.2.1 to fix html issues -## [d4storagehub4R 0.4](https://cran.r-project.org/package=d4storagehub4R) | [![CRAN_Status_Badge](https://img.shields.io/badge/CRAN-published-blue.svg)](https://cran.r-project.org/package=d4storagehub4R) +## [d4storagehub4R 0.4](https://cran.r-project.org/src/contrib/Archive/d4storagehub4R/d4storagehub4R_0.4.tar.gz) | [![CRAN_Status_Badge](https://img.shields.io/badge/CRAN-published-blue.svg)](https://cran.r-project.org/src/contrib/Archive/d4storagehub4R/d4storagehub4R_0.4.tar.gz) **Enhancements** diff --git a/R/StoragehubManager.R b/R/StoragehubManager.R index 400476c..82f53d7 100644 --- a/R/StoragehubManager.R +++ b/R/StoragehubManager.R @@ -722,6 +722,25 @@ StoragehubManager <- R6Class("StoragehubManager", self$downloadItem(item = item, wd = wd) }, + #'@description Get public file link by ID + #'@param pathID file item ID + #'@return the public file URL + getPublicFileLinkByID = function(pathID){ + link <- NULL + link_url <- sprintf("%s/items/%s/publiclink?exclude=hl:accounting", private$url_storagehub, pathID) + pl_req <- switch(private$token_type, + "gcube" = { + link_url <-paste0(link_url, "&gcube-token=", self$getToken()) + httr::GET(link_url) + }, + "jwt" = { + httr::GET(link_url, httr::add_headers("Authorization" = paste("Bearer", self$getToken()))) + } + ) + if(!is.null(pl_req)) link <- httr::content(pl_req) + return(link) + }, + #'@description Get public file link #'@param path file path #'@return the public file URL @@ -733,17 +752,7 @@ StoragehubManager <- R6Class("StoragehubManager", self$ERROR(errMsg) stop(errMsg) } - link_url <- sprintf("%s/items/%s/publiclink?exclude=hl:accounting", private$url_storagehub, pathID) - pl_req <- switch(private$token_type, - "gcube" = { - link_url <-paste0(link_url, "&gcube-token=", self$getToken()) - httr::GET(link_url) - }, - "jwt" = { - httr::GET(link_url, httr::add_headers("Authorization" = paste("Bearer", self$getToken()))) - } - ) - if(!is.null(pl_req)) link <- httr::content(pl_req) + link <- self$getPublicFileLinkByID(pathID = pathID) return(link) } diff --git a/man/StoragehubManager.Rd b/man/StoragehubManager.Rd index 8570cdf..7a2d3a5 100644 --- a/man/StoragehubManager.Rd +++ b/man/StoragehubManager.Rd @@ -60,6 +60,7 @@ Emmanuel Blondel \item \href{#method-StoragehubManager-unshareItem}{\code{StoragehubManager$unshareItem()}} \item \href{#method-StoragehubManager-downloadItem}{\code{StoragehubManager$downloadItem()}} \item \href{#method-StoragehubManager-downloadItemByPath}{\code{StoragehubManager$downloadItemByPath()}} +\item \href{#method-StoragehubManager-getPublicFileLinkByID}{\code{StoragehubManager$getPublicFileLinkByID()}} \item \href{#method-StoragehubManager-getPublicFileLink}{\code{StoragehubManager$getPublicFileLink()}} \item \href{#method-StoragehubManager-clone}{\code{StoragehubManager$clone()}} } @@ -556,6 +557,26 @@ Download item by path } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-StoragehubManager-getPublicFileLinkByID}{}}} +\subsection{Method \code{getPublicFileLinkByID()}}{ +Get public file link by ID +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{StoragehubManager$getPublicFileLinkByID(pathID)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{pathID}}{file item ID} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +the public file URL +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-StoragehubManager-getPublicFileLink}{}}} \subsection{Method \code{getPublicFileLink()}}{