|
38 | 38 | #' will be created. |
39 | 39 | #' @param csrf The CSRF token of your session, received with |
40 | 40 | #' \code{\link{get_csrf}}. |
41 | | -#' @param wikibase_session An optional list that contains any of the values of |
42 | | -#' parameters \code{qid_equivalence_property}, \code{language}, |
43 | | -#' \code{wikibase_api_url}, \code{data_curator},\code{log_path} and |
44 | | -#' \code{csrf} (for repeated use in a session.) |
| 41 | +#' @param wikibase_session An optional named list of default values to reuse |
| 42 | +#' across multiple function calls. If any of the main parameters (such as |
| 43 | +#' \code{language}, \code{data_curator}, \code{log_file_name}, |
| 44 | +#' \code{equivalence_propeert}, \code{classification_property} |
| 45 | +#' \code{wikibase_api_url}, or \code{csrf}) are missing from the function |
| 46 | +#' call, their values will be taken from this list if available. This is |
| 47 | +#' useful in interactive workflows or scripts where the same context is |
| 48 | +#' reused. |
45 | 49 | #' @importFrom assertthat assert_that |
46 | 50 | #' @importFrom utils person |
47 | 51 | #' @return Returns a \code{\link[dataset]{dataset_df}} object. |
@@ -78,48 +82,22 @@ copy_wikidata_item <- function( |
78 | 82 | log_file_name = NULL, |
79 | 83 | csrf, |
80 | 84 | wikibase_session = NULL) { |
81 | | - if (!is.null(wikibase_session)) { |
82 | | - # For repeated queries you can add your variables directly or in a list |
83 | | - |
84 | | - if (!is.null(wikibase_session$qid_equivalence_property)) { |
85 | | - qid_equivalence_property <- wikibase_session$qid_equivalence_property |
86 | | - } |
87 | | - |
88 | | - if (!is.null(wikibase_session$classification_property)) { |
89 | | - classification_property <- wikibase_session$classification_property |
90 | | - } |
91 | | - |
92 | | - if (!is.null(wikibase_session$language)) { |
93 | | - # overwrite session default if it does not exist |
94 | | - if (is.null(language)) language <- wikibase_session$language |
95 | | - } |
96 | | - |
97 | | - if (!is.null(wikibase_session$data_curator)) { |
98 | | - # overwrite session default if it does not exist |
99 | | - if (is.null(data_curator)) data_curator <- wikibase_session$data_curator |
100 | | - } |
101 | | - |
102 | | - if (!is.null(wikibase_session$wikibase_api_url)) { |
103 | | - wikibase_api_url <- wikibase_session$wikibase_api_url |
104 | | - } |
105 | | - |
106 | | - if (!is.null(wikibase_session$log_file_name)) { |
107 | | - log_file_name <- wikibase_session$log_file_name |
108 | | - } |
109 | | - |
110 | | - if (!is.null(wikibase_session$csrf)) { |
111 | | - csrf <- wikibase_session$csrf |
112 | | - } |
113 | | - } |
114 | | - |
115 | | - # Assertions for correct inputs ------------------------------------------------ |
116 | | - |
117 | | - if (is.null(data_curator)) data_curator <- person("Jane", "Doe") |
118 | | - if (is.null(log_file_name)) log_file_name <- "" |
119 | | - |
120 | | - assertthat::assert_that( |
121 | | - inherits(data_curator, "person"), |
122 | | - msg = 'copy_wikidata_item(..., data_curator): data_curator must be a person, like person("Jane, "Doe").' |
| 85 | + language <- resolve_from_session("language", language, wikibase_session) |
| 86 | + data_curator <- resolve_from_session("data_curator", data_curator, wikibase_session) |
| 87 | + log_file_name <- resolve_from_session("log_file_name", log_file_name, wikibase_session) |
| 88 | + wikibase_api_url <- resolve_from_session("wikibase_api_url", wikibase_api_url, wikibase_session) |
| 89 | + equivalence_property <- resolve_from_session("wikibase_api_url", equivalence_property, wikibase_session) |
| 90 | + classification_property <- resolve_from_session("wikibase_api_url", classification_property, wikibase_session) |
| 91 | + csrf <- resolve_from_session("csrf", csrf, wikibase_session) |
| 92 | + |
| 93 | + validate_create_entity_args( |
| 94 | + language = language, |
| 95 | + wikibase_api_url = wikibase_api_url, |
| 96 | + equivalence_property = equivalence_property, |
| 97 | + equivalence_id = equivalence_id, |
| 98 | + csrf = csrf, |
| 99 | + data_curator = data_curator, |
| 100 | + validated_action = "copy_wikidata_property()" |
123 | 101 | ) |
124 | 102 |
|
125 | 103 | if (is.null(qid_equivalence_property)) qid_equivalence_property <- NA_character_ |
@@ -313,10 +291,10 @@ copy_wikidata_item <- function( |
313 | 291 | ## See get_csrf, get_csrf_token. |
314 | 292 | csrf_token <- get_csrf_token(csrf) |
315 | 293 |
|
316 | | - assertthat::assert_that(!is.null(csrf_token), |
317 | | - msg = "You do not have a CSRF token; perhaps your session has expired. |
318 | | - Try get_csrf() with your credentials." |
319 | | - ) |
| 294 | + |
| 295 | + if (!is_valid_csrf(csrf_token)) { |
| 296 | + stop(validated_action, ": the csrf appears to be invalid.") |
| 297 | + } |
320 | 298 |
|
321 | 299 | # Posting the new item --------------------------------------------------- |
322 | 300 | new_item <- httr::POST( |
|
0 commit comments