Qualify package names in added methods (#75)

* Qualify package names in added methods

* Move make_basic_list to a private class method to solve namespacing issues

* Remove roxygen docs for private methods

* update news

Co-authored-by: Hong Ooi <hongooi73@gmail.com>
This commit is contained in:
Rob 2021-08-29 07:30:02 +01:00 коммит произвёл GitHub
Родитель 8cd57b701a
Коммит d4c6a1d5eb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
15 изменённых файлов: 55 добавлений и 82 удалений

Просмотреть файл

@ -11,7 +11,6 @@ export(get_team)
export(list_chats)
export(list_sharepoint_sites)
export(list_teams)
export(make_basic_list)
export(ms_channel)
export(ms_chat)
export(ms_chat_message)

Просмотреть файл

@ -8,6 +8,10 @@
- Fix a bug where attaching a file to a Teams chat/channel message would fail if the file was a type recognised by Microsoft 365 (#73).
## Other
- Changes to allow Microsoft365R to be usable without being on the search list (#72). Among other things, `make_basic_list()` is now a private method, rather than being exported. Thanks to @rob for the PR.
# Microsoft365R 2.3.0
## Outlook

Просмотреть файл

@ -65,6 +65,7 @@ utils::globalVariables(c("self", "private"))
register_graph_class("chat", ms_chat,
function(props) "chatType" %in% names(props))
add_object_methods()
add_graph_methods()
add_user_methods()
add_group_methods()

Просмотреть файл

@ -114,6 +114,18 @@
#' }
NULL
add_object_methods <- function()
{
AzureGraph::ms_object$set("private", "make_basic_list", overwrite=TRUE,
function(op, filter, n, ...)
{
opts <- list(`$filter`=filter)
hdrs <- if(!is.null(filter)) httr::add_headers(consistencyLevel="eventual")
pager <- self$get_list_pager(self$do_operation(op, options=opts, hdrs), ...)
extract_list_values(pager, n)
})
}
add_graph_methods <- function()
{
ms_graph$set("public", "get_sharepoint_site", overwrite=TRUE,
@ -127,21 +139,24 @@ add_graph_methods <- function()
file.path("sites", paste0(site_url$hostname, ":"), site_url$path)
}
else file.path("sites", site_id)
ms_site$new(self$token, self$tenant, self$call_graph_endpoint(op))
Microsoft365R::ms_site$new(self$token, self$tenant,
self$call_graph_endpoint(op))
})
ms_graph$set("public", "get_drive", overwrite=TRUE,
function(drive_id)
{
op <- file.path("drives", drive_id)
ms_drive$new(self$token, self$tenant, self$call_graph_endpoint(op))
Microsoft365R::ms_drive$new(self$token, self$tenant,
self$call_graph_endpoint(op))
})
ms_graph$set("public", "get_team", overwrite=TRUE,
function(team_id)
{
op <- file.path("teams", team_id)
ms_team$new(self$token, self$tenant, self$call_graph_endpoint(op))
Microsoft365R::ms_team$new(self$token, self$tenant,
self$call_graph_endpoint(op))
})
}
@ -150,7 +165,7 @@ add_user_methods <- function()
az_user$set("public", "list_drives", overwrite=TRUE,
function(filter=NULL, n=Inf)
{
make_basic_list(self, "drives", filter, n)
private$make_basic_list(self, "drives", filter, n)
})
az_user$set("public", "get_drive", overwrite=TRUE,
@ -159,13 +174,14 @@ add_user_methods <- function()
op <- if(is.null(drive_id))
"drive"
else file.path("drives", drive_id)
ms_drive$new(self$token, self$tenant, self$do_operation(op))
Microsoft365R::ms_drive$new(self$token, self$tenant,
self$do_operation(op))
})
az_user$set("public", "list_sharepoint_sites", overwrite=TRUE,
function(filter=NULL, n=Inf)
{
lst <- make_basic_list(self, "followedSites", filter, n)
lst <- private$make_basic_list(self, "followedSites", filter, n)
if(!is.null(n))
lapply(lst, function(site) site$sync_fields()) # result from endpoint is incomplete
else lst
@ -174,7 +190,7 @@ add_user_methods <- function()
az_user$set("public", "list_teams", overwrite=TRUE,
function(filter=NULL, n=Inf)
{
lst <- make_basic_list(self, "joinedTeams", filter, n)
lst <- private$make_basic_list(self, "joinedTeams", filter, n)
if(!is.null(n))
lapply(lst, function(team) team$sync_fields()) # result from endpoint only contains ID and displayname
else lst
@ -183,20 +199,20 @@ add_user_methods <- function()
az_user$set("public", "get_outlook", overwrite=TRUE,
function()
{
ms_outlook$new(self$token, self$tenant, self$properties)
Microsoft365R::ms_outlook$new(self$token, self$tenant, self$properties)
})
az_user$set("public", "list_chats", overwrite=TRUE,
function(filter=NULL, n=Inf)
{
make_basic_list(self, "chats", filter, n)
private$make_basic_list(self, "chats", filter, n)
})
az_user$set("public", "get_chat", overwrite=TRUE,
function(chat_id)
{
op <- file.path("chats", chat_id)
ms_chat$new(self$token, self$tenant, self$do_operation(op))
Microsoft365R::ms_chat$new(self$token, self$tenant, self$do_operation(op))
})
}
@ -206,13 +222,13 @@ add_group_methods <- function()
function()
{
res <- self$do_operation("sites/root")
ms_site$new(self$token, self$tenant, res)
Microsoft365R::ms_site$new(self$token, self$tenant, res)
})
az_group$set("public", "list_drives", overwrite=TRUE,
function(filter=NULL, n=Inf)
{
make_basic_list(self, "drives", filter, n)
private$make_basic_list(self, "drives", filter, n)
})
az_group$set("public", "get_drive", overwrite=TRUE,
@ -232,20 +248,22 @@ add_group_methods <- function()
op <- if(is.null(drive_id))
"drive"
else file.path("drives", drive_id)
ms_drive$new(self$token, self$tenant, self$do_operation(op))
Microsoft365R::ms_drive$new(self$token, self$tenant,
self$do_operation(op))
})
az_group$set("public", "get_team", overwrite=TRUE,
function()
{
op <- file.path("teams", self$properties$id)
ms_team$new(self$token, self$tenant, call_graph_endpoint(self$token, op))
Microsoft365R::ms_team$new(self$token, self$tenant,
call_graph_endpoint(self$token, op))
})
az_group$set("public", "list_plans", overwrite=TRUE,
function(filter=NULL, n=Inf)
{
make_basic_list(self, "planner/plans", filter, n)
private$make_basic_list(self, "planner/plans", filter, n)
})
az_group$set("public", "get_plan", overwrite=TRUE,
@ -255,7 +273,7 @@ add_group_methods <- function()
if(!is.null(plan_id))
{
res <- call_graph_endpoint(self$token, file.path("planner/plans", plan_id))
ms_plan$new(self$token, self$tenant, res)
Microsoft365R::ms_plan$new(self$token, self$tenant, res)
}
else
{

Просмотреть файл

@ -1,20 +0,0 @@
#' Create a list of Graph objects
#' @param object An R6 object inheriting from `AzureGraph::ms_object`.
#' @param op A string, the REST operation.
#' @param filter,n Filtering arguments for the list.
#' @param ... Arguments passed to lower-level functions, and ultimately to `AzureGraph::call_graph_endpoint`.
#' @details
#' This function is a basic utility called by various Microsoft365R class methods. It is exported to work around issues in how R6 handles classes that extend across package boundaries. It should not be called by the user.
#' @return
#' If `n` is NULL, an iterator object, of class `AzureGraph::ms_graph_pager`. Otherwise, a list of individual Graph objects.
#' @seealso
#' [`AzureGraph::call_graph_endpoint`], [`AzureGraph::ms_graph_pager`]
#' @export
make_basic_list <- function(object, op, filter, n, ...)
{
opts <- list(`$filter`=filter)
hdrs <- if(!is.null(filter)) httr::add_headers(consistencyLevel="eventual")
pager <- object$get_list_pager(object$do_operation(op, options=opts, hdrs), ...)
extract_list_values(pager, n)
}

Просмотреть файл

@ -119,7 +119,7 @@ public=list(
list_messages=function(filter=NULL, n=50)
{
make_basic_list(self, "messages", filter, n)
private$make_basic_list("messages", filter, n)
},
get_message=function(message_id)
@ -157,7 +157,7 @@ public=list(
list_members=function(filter=NULL, n=Inf)
{
make_basic_list(self, "members", filter, n, parent_id=self$properties$id, parent_type="channel")
private$make_basic_list("members", filter, n, parent_id=self$properties$id, parent_type="channel")
},
get_member=function(name=NULL, email=NULL, id=NULL)

Просмотреть файл

@ -98,7 +98,7 @@ public=list(
list_messages=function(filter=NULL, n=50)
{
make_basic_list(self, "messages", filter, n)
private$make_basic_list("messages", filter, n)
},
get_message=function(message_id)
@ -114,7 +114,7 @@ public=list(
list_members=function(filter=NULL, n=Inf)
{
make_basic_list(self, "members", filter, n, parent_id=self$properties$id, parent_type="chat")
private$make_basic_list("members", filter, n, parent_id=self$properties$id, parent_type="chat")
},
get_member=function(name=NULL, email=NULL, id=NULL)

Просмотреть файл

@ -91,7 +91,7 @@ public=list(
list_replies=function(filter=NULL, n=50)
{
private$assert_not_nested_reply()
make_basic_list(self, "replies", filter, n)
private$make_basic_list("replies", filter, n)
},
get_reply=function(message_id)

Просмотреть файл

@ -161,7 +161,7 @@ public=list(
list_folders=function(filter=NULL, n=Inf)
{
make_basic_list(self, "mailFolders", filter, n, user_id=self$properties$id)
private$make_basic_list("mailFolders", filter, n, user_id=self$properties$id)
},
get_folder=function(folder_name=NULL, folder_id=NULL)

Просмотреть файл

@ -200,7 +200,7 @@ public=list(
list_folders=function(filter=NULL, n=Inf)
{
make_basic_list(self, "childFolders", filter, n, user_id=self$user_id)
private$make_basic_list("childFolders", filter, n, user_id=self$user_id)
},
get_folder=function(folder_name=NULL, folder_id=NULL)

Просмотреть файл

@ -57,7 +57,7 @@ public=list(
list_tasks=function(filter=NULL, n=Inf)
{
make_basic_list(self, "tasks", filter, n)
private$make_basic_list("tasks", filter, n)
},
get_task=function(task_title=NULL, task_id=NULL)
@ -79,7 +79,7 @@ public=list(
list_buckets=function(filter=NULL, n=Inf)
{
make_basic_list(self, "buckets", filter, n)
private$make_basic_list("buckets", filter, n)
},
get_bucket=function(bucket_name=NULL, bucket_id=NULL)

Просмотреть файл

@ -44,7 +44,7 @@ public=list(
list_tasks=function(filter=NULL, n=Inf)
{
make_basic_list(self, "tasks", filter, n)
private$make_basic_list("tasks", filter, n)
},
print=function(...)

Просмотреть файл

@ -57,7 +57,7 @@ public=list(
list_drives=function(filter=NULL, n=Inf)
{
make_basic_list(self, "drives", filter, n)
private$make_basic_list("drives", filter, n)
},
get_drive=function(drive_name=NULL, drive_id=NULL)
@ -81,12 +81,12 @@ public=list(
list_subsites=function(filter=NULL, n=Inf)
{
make_basic_list(self, "sites", filter, n)
private$make_basic_list("sites", filter, n)
},
get_lists=function(filter=NULL, n=Inf)
{
make_basic_list(self, "lists", filter, n)
private$make_basic_list("lists", filter, n)
},
get_list=function(list_name=NULL, list_id=NULL)

Просмотреть файл

@ -70,7 +70,7 @@ public=list(
list_channels=function(filter=NULL, n=Inf)
{
make_basic_list(self, "channels", filter, n, team_id=self$properties$id)
private$make_basic_list("channels", filter, n, team_id=self$properties$id)
},
get_channel=function(channel_name=NULL, channel_id=NULL)
@ -111,7 +111,7 @@ public=list(
list_drives=function(filter=NULL, n=Inf)
{
make_basic_list(self$get_group(), "drives", filter, n)
self$get_group()$list_drives(filter, n)
},
get_drive=function(drive_name=NULL, drive_id=NULL)
@ -146,7 +146,7 @@ public=list(
list_members=function(filter=NULL, n=Inf)
{
make_basic_list(self, "members", filter, n, parent_id=self$properties$id, parent_type="team")
private$make_basic_list("members", filter, n, parent_id=self$properties$id, parent_type="team")
},
get_member=function(name=NULL, email=NULL, id=NULL)

Просмотреть файл

@ -1,29 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/make_basic_list.R
\name{make_basic_list}
\alias{make_basic_list}
\title{Create a list of Graph objects}
\usage{
make_basic_list(object, op, filter, n, ...)
}
\arguments{
\item{object}{An R6 object inheriting from \code{AzureGraph::ms_object}.}
\item{op}{A string, the REST operation.}
\item{filter, n}{Filtering arguments for the list.}
\item{...}{Arguments passed to lower-level functions, and ultimately to \code{AzureGraph::call_graph_endpoint}.}
}
\value{
If \code{n} is NULL, an iterator object, of class \code{AzureGraph::ms_graph_pager}. Otherwise, a list of individual Graph objects.
}
\description{
Create a list of Graph objects
}
\details{
This function is a basic utility called by various Microsoft365R class methods. It is exported to work around issues in how R6 handles classes that extend across package boundaries. It should not be called by the user.
}
\seealso{
\code{\link[AzureGraph:call_graph]{AzureGraph::call_graph_endpoint}}, \code{\link[AzureGraph:ms_graph_pager]{AzureGraph::ms_graph_pager}}
}