From 9f20f2011df1c71c9ffaf020870f142d02efbef2 Mon Sep 17 00:00:00 2001
From: Mathieu Loiseau <mathieu.loiseau@univ-grenoble-alpes.fr>
Date: Fri, 7 Dec 2018 09:38:54 +0100
Subject: [PATCH] Batchator load template & content

---
 R/class.R | 34 ++++++++++++++++++++++++++++++++--
 README.md |  4 +---
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/R/class.R b/R/class.R
index 987b1b3..8096931 100644
--- a/R/class.R
+++ b/R/class.R
@@ -7,6 +7,7 @@ library(httr)
 #'@importFrom R6 R6Class
 #'@importFrom httr POST
 #'@importFrom httr stop_for_status
+#'@importFrom httr upload_file
 #'@importFrom httr content
 #'@export
 #'@keywords mediawiki
@@ -231,30 +232,59 @@ Mediawikir <- R6Class("Mediawikir",
  )
 )
 
+library(stringr)
 
 #'Batchator: Batch input to mediawiki based on a csv and a template
 #'
 #'@docType class
 #'@export
+#'@importFrom stringr str_replace_all
 #'@keywords mediawiki
 #'@description Uses mediawikir to create a batch of pages
 Batchator <- R6Class("Batchator",
   public = list(
     author = NULL,
     wiki = NULL,
-    prefix ="",
+    page_prefix ="",
+    template = NULL,
+    content = NULL,
+
     ######
     # initialize
     ######
     initialize = function (wiki,author,pass,prefix){
       tryCatch({
         self$wiki <- Mediawikir$new(wiki, author, pass)
-        self$prefix <- prefix
+        self$page_prefix <- prefix
       },
       error = function(e){
         print(e$message)
         self <- FALSE
       })
+    },
+
+    ######
+    # loadTemplate
+    ######
+    loadTemplate = function(file_path){
+      tryCatch({
+        self$template <- readChar(file_path, file.info(file_path)$size)
+      },
+      error = function(e){
+        print(paste(e$message, "No template loaded"))
+      })
+    },
+
+    ######
+    # loadContent
+    ######
+    loadContent = function(file_path){
+      tryCatch({
+        self$content <- read.csv(file=file_path, header = FALSE)
+      },
+      error = function(e){
+        print(paste(e$message, "No content loaded"))
+      })
     }
   )
 )
diff --git a/README.md b/README.md
index 180f63d..282f34f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,4 @@
 mediawikir
 =========
 
-Un package R pour connecter la sortie d'un script R à une instance de [MediaWiki](https://www.mediawiki.org/wiki/Download)
-
-Pour plus de détails voir la documentation R associée
\ No newline at end of file
+An R package to connect an R script to a [MediaWiki](https://www.mediawiki.org/wiki/Download) instance. This also provides a class to perform batch page creation.
-- 
GitLab