Skip to content

Commit

Permalink
#2 push existing WFS client (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Feb 15, 2018
1 parent 4779bc3 commit 3a966fb
Show file tree
Hide file tree
Showing 23 changed files with 1,723 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
language: R
sudo: required
cache: packages

services:
- docker

before_install:
- docker pull kartoza/postgis
- docker run -d --name="postgis" kartoza/postgis
- docker pull oscarfonts/geoserver
- docker run --link postgis:postgis -d -p 8080:8080 oscarfonts/geoserver

r:
- oldrel
- release
- devel

r_binary_packages:
- rgdal

r_packages:
- R6
- httr
- XML
- testthat
- covr

r_check_args: --as-cran

after_script:
- ./travis-tool.sh dump_logs

after_success:
- Rscript -e 'library(covr); codecov()'

notifications:
email:
on_success: change
on_failure: change
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Version: 0.1
Date: 2018-02-14
Title: interface to OGC Web-Services (OWS)
Authors@R: c(person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com"),
person("Norbert", "Billet", role = c("ctb"), email = "norbert.billet@ird.fr"))
person("Norbert", "Billet", role = c("ctb")))
Maintainer: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
Depends: R (>= 2.15)
Imports: R6, httr, XML (>= 3.96-1.1), sp, rgdal
Expand Down
16 changes: 16 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# Generated by roxygen2: do not edit by hand

export(OWSClient)
export(OWSRequest)
export(OWSServiceIdentification)
export(OWSUtils)
export(OWSUtilsInternal)
export(WFSCapabilities)
export(WFSClient)
export(WFSDescribeFeatureType)
export(WFSFeatureType)
export(WFSFeatureTypeElement)
export(WFSGetFeature)
import(XML)
import(httr)
import(rgdal)
import(sp)
importFrom(R6,R6Class)
141 changes: 141 additions & 0 deletions R/OWSClient.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#' OWSClient
#'
#' @docType class
#' @importFrom R6 R6Class
#' @import httr
#' @import XML
#' @import sp
#' @import rgdal
#' @export
#' @keywords OGC Common OWS
#' @return Object of \code{\link{R6Class}} with methods for interfacing
#' a Common OGC web-service.
#' @format \code{\link{R6Class}} object.
#'
#' @examples
#' \dontrun{
#' OWSClient$new("http://localhost:8080/geoserver/ows", version = "1.1.0")
#' }
#'
#' @field loggerType the type of logger
#' @field verbose.info if basic logs have to be printed
#' @field verbose.debug if verbose logs have to be printed
#' @field url the Base url of OWS service
#' @field version the version of OWS service
#'
#' @section Methods:
#' \describe{
#' \item{\code{new(url, version, user, pwd, logger)}}{
#' This method is used to instantiate a OWSClient with the \code{url} of the
#' OGC service. Authentication (\code{user}/\code{pwd}) is not yet supported and will
#' be added with the support of service transactional modes. By default, the \code{logger}
#' argument will be set to \code{NULL} (no logger). This argument accepts two possible
#' values: \code{INFO}: to print only \pkg{ows4R} logs, \code{DEBUG}: to print more verbose logs
#' }
#' \item{\code{logger(type, text)}}{
#' Basic logger to report logs. Used internally
#' }
#' \item{\code{INFO(text)}}{
#' Logger to report information. Used internally
#' }
#' \item{\code{WARN(text)}}{
#' Logger to report warnings. Used internally
#' }
#' \item{\code{ERROR(text)}}{
#' Logger to report errors. Used internally
#' }
#' \item{\code{getUrl()}}{
#' Get the service URL
#' }
#' \item{\code{getVersion()}}{
#' Get the service version
#' }
#' \item{\code{getCapabilities()}}{
#' Get the service capabilities
#' }
#' \item{\code{getClassName()}}{
#' Retrieves the name of the class instance
#' }
#' }
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
OWSClient <- R6Class("OWSClient",

lock_objects = FALSE,

#TODO for support of transactional operations
#TODO provider specific formatter to prevent these fields to be printable
private = list(
user = NA,
pwd = NA
),

public = list(
#logger
verbose.info = FALSE,
verbose.debug = FALSE,
loggerType = NULL,
logger = function(type, text){
if(self$verbose.info){
cat(sprintf("[ows4R][%s] %s \n", type, text))
}
},
INFO = function(text){self$logger("INFO", text)},
WARN = function(text){self$logger("WARN", text)},
ERROR = function(text){self$logger("ERROR", text)},

#fields
url = NA,
version = NA,
capabilities = NA,

#initialize
initialize = function(url, version, user = NULL, pwd = NULL, logger = NULL) {

#logger
if(!missing(logger)){
if(!is.null(logger)){
self$loggerType <- toupper(logger)
if(!(self$loggerType %in% c("INFO","DEBUG"))){
stop(sprintf("Unknown logger type '%s", logger))
}
if(self$loggerType == "INFO"){
self$verbose.info = TRUE
}else if(self$loggerType == "DEBUG"){
self$verbose.info = TRUE
self$verbose.debug = TRUE
}
}
}

#fields
if (!missing(url)) self$url <- url
if (substring(self$url, nchar(self$url)) != "?"){
self$url <- paste(self$url, "?", sep = "")
}
if (!missing(version)) self$version <- version
},

#getUrl
getUrl = function(){
return(self$url)
},

#getVersion
getVersion = function(){
return(self$version)
},

#getCapabilities
getCapabilities = function() {
return(self$capabilities)
},

#getClassName
getClassName = function(){
return(class(self)[1])
}
)
)

39 changes: 39 additions & 0 deletions R/OWSRequest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @export
OWSRequest <- R6Class("OWSRequest",
#private methods
private = list(
#buildRequest
buildRequest = function(baseUrl, namedParams, mimeType){
params <- paste(names(namedParams), namedParams, sep = "=", collapse = "&")
request <- paste(baseUrl, "&", params, sep = "")
message("Fetching ", request)
r <- GET(request)
responseContent <- NULL
if(is.null(mimeType)){
responseContent <- content(r)
}else{
if(regexpr("xml",mimeType)>0){
responseContent <- xmlParse(content(r, type = "text"))
}else{
responseContent <- content(r, type = mimeType)
}
}
response <- list(request = request, status = status_code(r), response = responseContent)
return(response)
}
),
#public methods
public = list(
request = NA,
status = NA,
response = NA,
#initialize
initialize = function(baseUrl, namedParams, mimeType = "text/xml") {
req <- private$buildRequest(baseUrl, namedParams, mimeType)
self$request <- req$request
self$status <- req$status
self$response <- req$response
}
),

)
Loading

0 comments on commit 3a966fb

Please sign in to comment.