view RemotedbConn.R @ 3:f61ce21ed17c draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 476a081c0da66822f4e77070f5ce59d9f14511f4-dirty
author prog
date Thu, 02 Mar 2017 11:07:56 -0500
parents 20d69a062da3
children
line wrap: on
line source

if ( ! exists('RemotedbConn')) {

	#####################
	# CLASS DECLARATION #
	#####################
	
	RemotedbConn <- methods::setRefClass("RemotedbConn", contains = "BiodbConn", fields = list(.scheduler = "UrlRequestScheduler", .token = "character"))

	###############
	# CONSTRUCTOR #
	###############

	RemotedbConn$methods( initialize = function(useragent = NA_character_, scheduler = NULL, token = NA_character_, ...) {

		# Check useragent
		( ! is.null(useragent) && ! is.na(useragent)) || stop("You must specify a valid useragent string (e.g.: \"myapp ; my.email@address\").")

		# Set token
		.token <<- token

		# Set scheduler
		if (is.null(scheduler))
			scheduler <- UrlRequestScheduler$new(n = 3)
		inherits(scheduler, "UrlRequestScheduler") || stop("The scheduler instance must inherit from UrlRequestScheduler class.")
		scheduler$setUserAgent(useragent) # set agent
		.scheduler <<- scheduler
	
		callSuper(...) # calls super-class initializer with remaining parameters
	})

	###########
	# GET URL #
	###########

	RemotedbConn$methods( .get.url = function(url) {
		.self$.print.debug.msg(paste0("Sending URL request '", url, "'..."))
		return(.self$.scheduler$getUrl(url))
	})
	
	###########
	# GET URL #
	###########
	
	RemotedbConn$methods( .set.useragent = function(useragent) {
		.scheduler$setUserAgent(useragent) # set agent
	})

}