Permalink
Browse files

try to DRY; THX to @daroczig for the hints!

	modified:   R4CouchDB/DESCRIPTION
	modified:   R4CouchDB/R/cdbAddAttachment.R
	modified:   R4CouchDB/R/cdbAddDoc.R
	modified:   R4CouchDB/R/cdbDeleteDoc.R
	modified:   R4CouchDB/R/cdbGetConfig.R
	modified:   R4CouchDB/R/cdbGetDoc.R
	modified:   R4CouchDB/R/cdbGetList.R
	modified:   R4CouchDB/R/cdbGetUuid.R
	modified:   R4CouchDB/R/cdbGetUuidS.R
	modified:   R4CouchDB/R/cdbGetView.R
	modified:   R4CouchDB/R/cdbIni.R
	modified:   R4CouchDB/R/cdbListDB.R
	modified:   R4CouchDB/R/cdbMakeDB.R
	modified:   R4CouchDB/R/cdbRemoveDB.R
	modified:   R4CouchDB/R/cdbUpdateDoc.R
	modified:   README.md
	modified:   example/example.R
  • Loading branch information...
wactbprot committed Oct 1, 2012
1 parent 1813088 commit b90df77f8750c769fe1197924882ec05b53b0500
View
@@ -1,14 +1,14 @@
Package: R4CouchDB
Type: Package
Title: Collection of R functions for CouchDB access
-Version: 0.09
-Date: 2011/09/10
+Version: 0.1
+Date: 2012/10/01
Author: wactbprot
Maintainer: <thsteinbock@web.de>
Description: The R4CouchDB package provides a collection of functions for
basic database and document management operations such as add and
delete. Every cdbFunction() gets and emits a list containing the
- connection set up.
+ connection set up. Such a list can be generated by cdbIni().
License: BSD
LazyLoad: yes
Depends: R (>= 2.7.0), bitops, RCurl(>= 1.6), RJSONIO (>= 0.95)
@@ -1,34 +1,17 @@
cdbAddAttachment <- function( cdb){
-
- if(cdb$serverName == ""){
- cdb$error <- paste(cdb$error," no cdb$serverName given ")
- }
-
- if(cdb$DBName ==""){
- cdb$error <- paste(cdb$error, " no cdb$DBName given ", sep=" ")
- }
-
- if( !(file.exists(cdb$fileName))){
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
- cdb$error <- paste(cdb$error,
- " no cdb$fileName given or ",
- cdb$fileName,
- " does not exist",
- sep=" ")
- }
-
if(cdb$error == ""){
-
- tmpN <- length(tmpFn <- unlist(strsplit(cdb$fileName,"\\.")))
-
+ tmpN <- length(tmpFn <- unlist(strsplit(cdb$fileName,"\\.")))
noOfBytes <- file.info(cdb$fileName)$size
- con <- file(cdb$fileName, "rb")
- data <- readBin(con,n=noOfBytes,raw())
+ con <- file(cdb$fileName, "rb")
+ data <- readBin(con,n=noOfBytes,raw())
close(con)
- cdb$rev <- cdbGetDoc(cdb)$res$'_rev'
-
+ cdb$rev <- cdbGetDoc(cdb)$res$'_rev'
adrString <- paste(cdb$baseUrl(cdb),
cdb$DBName,"/",
cdb$id,"/",
View
@@ -1,37 +1,27 @@
cdbAddDoc <- function( cdb){
- if(cdb$serverName == ""){
- cdb$error <- paste(cdb$error," no cdb$serverName given")
- }
-
- if(cdb$DBName == ""){
- cdb$error <- paste(cdb$error, " no cdb$DBName given ", sep=" ")
- }
-
- if( (length(cdb$dataList) < 1)){
- cdb$error <- paste(cdb$error, " no cdb$dataList given ", sep=" ")
- }
-
- if(cdb$id == ""){
- cdb <- cdbGetUuid(cdb)
- }
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
if(cdb$error == ""){
-
+ if(cdb$id == ""){
+ cdb <- cdbGetUuid(cdb)
+ }
+
adrString <- paste(cdb$baseUrl(cdb),
cdb$DBName,"/",
cdb$id,
sep="")
-
+
res <- getURL(adrString,
customrequest = "PUT",
curl=cdb$curl,
postfields = cdb$toJSON(cdb$dataList),
httpheader=c('Content-Type: application/json'),
.opts =cdb$opts(cdb))
-
+
res <- cdb$fromJSON( res )
-
+
if(length(res$ok) > 0){
cdb$dataList$'_id' <- res$id
cdb$dataList$'_rev' <- res$rev
@@ -41,6 +31,7 @@ cdbAddDoc <- function( cdb){
cdb$error <- paste(cdb$error, res$error)
}
}
+
if(!(cdb$error == "")){
stop( cdb$error )
}
View
@@ -1,17 +1,12 @@
cdbDeleteDoc <- function( cdb ){
- if(cdb$serverName == ""){
- cdb$error <- paste(cdb$error," no cdb$serverName given")
- }
- if(cdb$DBName ==""){
- cdb$error <- paste(cdb$error, " no cdb$DBName given ")
- }
- if(cdb$id ==""){
- cdb$error <- paste(cdb$error, " no cdb$id given ")
- }
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
+
if(cdb$error == ""){
- cdb <- cdbGetDoc(cdb)
+ cdb <- cdbGetDoc(cdb)
cdb$rev <- cdb$res$'_rev'
-
+
adrString <- paste(cdb$baseUrl(cdb),
cdb$DBName,"/",
cdb$id,
View
@@ -1,15 +1,17 @@
cdbGetConfig <- function(cdb){
- if(cdb$serverName == ""){
- cdb$error <- paste(cdb$error," no cdb$serverName given")
- }
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
+
if (cdb$error ==""){
+
adrString <- paste(cdb$baseUrl(cdb),
"_config",
sep="")
- res <- getURL(adrString,
- customrequest = "GET",
- curl=cdb$curl
- )
+ res <- getURL(adrString,
+ customrequest = "GET",
+ curl=cdb$curl
+ )
return(cdb$checkRes(cdb,res))
}else{
View
@@ -1,13 +1,8 @@
cdbGetDoc <- function(cdb){
-
- if(cdb$serverName == ""){
- cdb$error <- paste(cdb$error," no cdb$serverName given")
- }
-
- if( cdb$id == ""){
- cdb$error <- paste( cdb$error, " no cdb$id given ")
- }
-
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
+
if(cdb$error == ""){
adrString <- paste(cdb$baseUrl(cdb),
cdb$DBName,"/",
View
@@ -1,25 +1,14 @@
cdbGetList <- function( cdb ){
-
- if(cdb$design == "") {
- cdb$error <- paste(cdb$error, "no cdb$design given"
- , sep=" ")
- }
-
- if(cdb$view == "") {
- cdb$error <- paste(cdb$error,
- "no cdb$view given", sep=" ")
- }
-
- if(cdb$list == "") {
- cdb$error <- paste(cdb$error,
- "no cdb$list given", sep=" ")
- }
-
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
+
if(cdb$error ==""){
if(cdb$queryParam == ""){
queryString <- ""
}else{
+ ## todo: let usr specify list(a=b, c=d) ...
queryString <- paste("?",cdb$queryParam, sep="")
}
@@ -33,10 +22,10 @@ cdbGetList <- function( cdb ){
queryString,
sep="")
- res <- getURL(adrString,
+ res <- getURL(utils::URLencode(adrString),
customrequest = "GET",
- curl=cdb$curl
- )
+ curl=cdb$curl)
+
return(cdb$checkRes(cdb,res))
}else{
View
@@ -1,8 +1,7 @@
cdbGetUuid <- function(cdb){
-
- if(cdb$serverName == ""){
- cdb$error <- paste(cdb$error," no cdb$serverName given")
- }
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
if (cdb$error ==""){
View
@@ -1,26 +1,28 @@
cdbGetUuidS <- function(cdb){
- if(cdb$serverName == ""){
- cdb$error <- paste(cdb$error," no cdb$serverName given")
- }
+
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
+
if (cdb$error == ""){
+
if(cdb$queryParam == ""){
queryString <- ""
}else{
queryString <- paste("?",cdb$queryParam, sep="")
}
- adrString <- paste(cdb$baseUrl(cdb),
- "_uuids",
- queryString,
- sep="")
+ adrString <- paste(cdb$baseUrl(cdb),
+ "_uuids",
+ queryString,
+ sep="")
- res <- getURL(adrString,
+ res <- getURL(utils::URLencode(adrString),
customrequest = "GET",
curl=cdb$curl
)
return(cdb$checkRes(cdb,res))
}else{
- stop(cdb$error)
- }
+ stop(cdb$error)
+ }
}
View
@@ -1,14 +1,7 @@
cdbGetView <- function( cdb ){
- if(cdb$design == "") {
- cdb$error <- paste(cdb$error, "no cdb$design given"
- , sep=" ")
- }
-
- if(cdb$view == "") {
- cdb$error <- paste(cdb$error,
- "no cdb$design given", sep=" ")
- }
+ fname <- deparse(match.call()[[1]])
+ cdb <- cdb$checkCdb(cdb,fname)
if(cdb$error ==""){
@@ -27,7 +20,7 @@ cdbGetView <- function( cdb ){
queryString,
sep="")
- res <- getURL(adrString,
+ res <- getURL(utils::URLencode(adrString),
customrequest = "GET",
curl=cdb$curl
)
Oops, something went wrong.

0 comments on commit b90df77

Please sign in to comment.