Mercurial > repos > prog > lcmsmatching
comparison RemotedbConn.R @ 2:20d69a062da3 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
| author | prog |
|---|---|
| date | Thu, 02 Mar 2017 08:55:00 -0500 |
| parents | 253d531a0193 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:253d531a0193 | 2:20d69a062da3 |
|---|---|
| 1 if ( ! exists('RemotedbConn')) { | 1 if ( ! exists('RemotedbConn')) { |
| 2 | |
| 3 source('BiodbConn.R') | |
| 4 source(file.path('UrlRequestScheduler.R'), chdir = TRUE) | |
| 5 | 2 |
| 6 ##################### | 3 ##################### |
| 7 # CLASS DECLARATION # | 4 # CLASS DECLARATION # |
| 8 ##################### | 5 ##################### |
| 9 | 6 |
| 10 RemotedbConn <- setRefClass("RemotedbConn", contains = "BiodbConn", fields = list(.scheduler = "UrlRequestScheduler")) | 7 RemotedbConn <- methods::setRefClass("RemotedbConn", contains = "BiodbConn", fields = list(.scheduler = "UrlRequestScheduler", .token = "character")) |
| 11 | 8 |
| 12 ############### | 9 ############### |
| 13 # CONSTRUCTOR # | 10 # CONSTRUCTOR # |
| 14 ############### | 11 ############### |
| 15 | 12 |
| 16 RemotedbConn$methods( initialize = function(useragent = NA_character_, scheduler = NULL, ...) { | 13 RemotedbConn$methods( initialize = function(useragent = NA_character_, scheduler = NULL, token = NA_character_, ...) { |
| 17 | 14 |
| 18 # Check useragent | 15 # Check useragent |
| 19 ( ! is.null(useragent) && ! is.na(useragent)) || stop("You must specify a valid useragent string (e.g.: \"myapp ; my.email@address\").") | 16 ( ! is.null(useragent) && ! is.na(useragent)) || stop("You must specify a valid useragent string (e.g.: \"myapp ; my.email@address\").") |
| 17 | |
| 18 # Set token | |
| 19 .token <<- token | |
| 20 | 20 |
| 21 # Set scheduler | 21 # Set scheduler |
| 22 if (is.null(scheduler)) | 22 if (is.null(scheduler)) |
| 23 scheduler <- UrlRequestScheduler$new(n = 3) | 23 scheduler <- UrlRequestScheduler$new(n = 3) |
| 24 inherits(scheduler, "UrlRequestScheduler") || stop("The scheduler instance must inherit from UrlRequestScheduler class.") | 24 inherits(scheduler, "UrlRequestScheduler") || stop("The scheduler instance must inherit from UrlRequestScheduler class.") |
| 26 .scheduler <<- scheduler | 26 .scheduler <<- scheduler |
| 27 | 27 |
| 28 callSuper(...) # calls super-class initializer with remaining parameters | 28 callSuper(...) # calls super-class initializer with remaining parameters |
| 29 }) | 29 }) |
| 30 | 30 |
| 31 ########### | |
| 32 # GET URL # | |
| 33 ########### | |
| 34 | |
| 35 RemotedbConn$methods( .get.url = function(url) { | |
| 36 .self$.print.debug.msg(paste0("Sending URL request '", url, "'...")) | |
| 37 return(.self$.scheduler$getUrl(url)) | |
| 38 }) | |
| 39 | |
| 40 ########### | |
| 41 # GET URL # | |
| 42 ########### | |
| 43 | |
| 44 RemotedbConn$methods( .set.useragent = function(useragent) { | |
| 45 .scheduler$setUserAgent(useragent) # set agent | |
| 46 }) | |
| 47 | |
| 31 } | 48 } |
