Skip to content

Commit

Permalink
- test cdbAddAttachment()
Browse files Browse the repository at this point in the history
-- chk.doc.exists
-- documentation
-- tests

	modified:   R4CouchDB/DESCRIPTION
	modified:   R4CouchDB/NAMESPACE
	modified:   R4CouchDB/R/cdbAddAttachment.R
	modified:   R4CouchDB/R/cdbIni.R
	modified:   R4CouchDB/man/cdbAddAttachment.Rd
	modified:   R4CouchDB/man/cdbAddDoc.Rd
	modified:   R4CouchDB/man/cdbDeleteDoc.Rd
	modified:   R4CouchDB/man/cdbGetConfig.Rd
	modified:   R4CouchDB/man/cdbGetDoc.Rd
	modified:   R4CouchDB/man/cdbGetList.Rd
	modified:   R4CouchDB/man/cdbGetUuid.Rd
	modified:   R4CouchDB/man/cdbGetUuidS.Rd
	modified:   R4CouchDB/man/cdbGetView.Rd
	modified:   R4CouchDB/man/cdbIni.Rd
	modified:   R4CouchDB/man/cdbListDB.Rd
	modified:   R4CouchDB/man/cdbMakeDB.Rd
	modified:   R4CouchDB/man/cdbRemoveDB.Rd
	modified:   R4CouchDB/man/cdbUpdateDoc.Rd
	modified:   tests/load.r
	modified:   tests/run.r
	new file:   tests/test.pdf
	new file:   tests/testAddAttachment.r
	modified:   tests/testAddDoc.r
	modified:   tests/testGetDoc.r
	modified:   tests/testIni.r
	modified:   tests/testMakeDB.r
	modified:   tests/testRemoveDB.r
	modified:   tests/testUpdateDoc.r
  • Loading branch information
wactbprot committed Aug 11, 2014
1 parent fc7a18b commit 472861c
Show file tree
Hide file tree
Showing 28 changed files with 318 additions and 303 deletions.
15 changes: 0 additions & 15 deletions R4CouchDB/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,3 @@ Depends:
bitops,
RCurl (>= 1.95),
RJSONIO (>= 1.0)
Collate:
'cdbIni.R'
'cdbAddAttachment.R'
'cdbAddDoc.R'
'cdbDeleteDoc.R'
'cdbGetConfig.R'
'cdbGetDoc.R'
'cdbGetList.R'
'cdbGetUuid.R'
'cdbGetUuidS.R'
'cdbGetView.R'
'cdbListDB.R'
'cdbMakeDB.R'
'cdbRemoveDB.R'
'cdbUpdateDoc.R'
23 changes: 15 additions & 8 deletions R4CouchDB/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Export all names
exportPattern(".")
# Generated by roxygen2 (4.0.1): do not edit by hand

# Import all packages listed as Imports or Depends
import(
bitops,
RCurl,
RJSONIO
)
export(cdbAddAttachment)
export(cdbAddDoc)
export(cdbDeleteDoc)
export(cdbGetConfig)
export(cdbGetDoc)
export(cdbGetList)
export(cdbGetUuid)
export(cdbGetUuidS)
export(cdbGetView)
export(cdbIni)
export(cdbListDB)
export(cdbMakeDB)
export(cdbRemoveDB)
export(cdbUpdateDoc)
19 changes: 13 additions & 6 deletions R4CouchDB/R/cdbAddAttachment.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#' Add attachments
#'
#' This function adds attachments to a database document.
#' This function adds attachments to a database document that already
#' exists.
#'
#' The function uses \code{guessMIMEType()} to do exactly this.
#' The function uses the \code{RCurl}- function
#' \code{guessMIMEType()} to do exactly this: guessing the mime type of
#' \code{cdb$fileName}.
#'
#' If the switch \code{cdb$attachmentsWithPath} is set to \code{TRUE}
#' the attachments were saved with path which is the default since version
#' 0.2.5 of R4CouchDB
#' the attachment is saved with the path. This behavior is default
#' since version 0.2.5 of R4CouchDB
#'
#' @usage cdbAddAttachment(cdb)
#' @param cdb The list \code{cdb} has to contain
Expand Down Expand Up @@ -47,8 +51,11 @@ cdbAddAttachment <- function( cdb){

fname <- deparse(match.call()[[1]])
cdb <- cdb$checkCdb(cdb, fname)

if(cdb$error == ""){

cdb$rev <- cdb$getDocRev(cdb)

tmpN <- length(tmpFn <- unlist(strsplit(cdb$fileName,"\\.")))
noOfBytes <- file.info(cdb$fileName)$size
con <- file(cdb$fileName, "rb")
Expand All @@ -62,7 +69,7 @@ cdbAddAttachment <- function( cdb){
fbn <- basename(cdb$fileName)
}
ctp <- toString(guessMIMEType(basename(fbn)))
cdb$rev <- cdbGetDoc(cdb)$res$'_rev'

adrString <- paste(cdb$baseUrl(cdb),
cdb$DBName,
"/",
Expand Down
11 changes: 11 additions & 0 deletions R4CouchDB/R/cdbIni.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ cdbIni <- function(serverName = "localhost",
cdb <- chk.server.name(cdb)
cdb <- chk.id(cdb)
cdb <- chk.db.name(cdb)
cdb <- chk.doc.exists(cdb)
cdb <- chk.file.name(cdb)
}

Expand Down Expand Up @@ -251,6 +252,16 @@ cdbIni <- function(serverName = "localhost",
}

## ----------------------chk.fns-----------------v
chk.doc.exists <- function(cdb){
res <- cdb$getDocRev(cdb)

if(is.na(res)){
cdb$error <- paste(cdb$error,
";document cdb$id does not exist")
}
return(cdb)

}
chk.newdb.name <- function(cdb){
if(cdb$newDBName == ""){
cdb$error <- paste(cdb$error,
Expand Down
27 changes: 16 additions & 11 deletions R4CouchDB/man/cdbAddAttachment.Rd
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{cdbAddAttachment}
\alias{cdbAddAttachment}
\title{Add attachments}
\usage{
cdbAddAttachment(cdb)
cdbAddAttachment(cdb)
}
\arguments{
\item{cdb}{The list \code{cdb} has to contain
\code{cdb$fileName},\code{cdb$serverName},
\code{cdb$DBName} and a \code{cdb$id}.}
\item{cdb}{The list \code{cdb} has to contain
\code{cdb$fileName},\code{cdb$serverName}, \code{cdb$DBName} and a
\code{cdb$id}.}
}
\value{
\item{cdb}{The result is stored in \code{cdb$res} }
\item{cdb}{The result is stored in \code{cdb$res} }
}
\description{
This function adds attachments to a database document.
This function adds attachments to a database document that already
exists.
}
\details{
The function uses \code{guessMIMEType()} to do exactly
this. If the switch \code{cdb$attachmentsWithPath} is set
to \code{TRUE} the attachments were saved with path which
is the default since version 0.2.5 of R4CouchDB
The function uses the \code{RCurl}- function
\code{guessMIMEType()} to do exactly this: guessing the mime type of
\code{cdb$fileName}.

If the switch \code{cdb$attachmentsWithPath} is set to \code{TRUE}
the attachment is saved with the path. This behavior is default
since version 0.2.5 of R4CouchDB
}
\examples{
\dontrun{
Expand Down Expand Up @@ -49,7 +54,7 @@ ccc <- cdbAddAttachment(ccc)
}
}
\author{
wactbprot
wactbprot
}
\keyword{misc}

33 changes: 15 additions & 18 deletions R4CouchDB/man/cdbAddDoc.Rd
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{cdbAddDoc}
\alias{cdbAddDoc}
\title{Generates a new document}
\usage{
cdbAddDoc(cdb)
cdbAddDoc(cdb)
}
\arguments{
\item{cdb}{The list \code{cdb} only has to contain a
\code{cdb$dataList} which is not an empty \code{list()}.}
\item{cdb}{The list \code{cdb} only has to contain a \code{cdb$dataList}
which is not an empty \code{list()}.}
}
\value{
\item{cdb}{The couchdb response is stored in
\code{cdb$res} }
\item{cdb}{The couchdb response is stored in \code{cdb$res} }
}
\description{
This function adds a new document to an already existing
database
This function adds a new document to an already existing database
}
\details{
This function is called addDoc (which means add a new
document). Therefore the \code{cdb$id} is requested using
\code{cdbGetUuid()} for every document to add if no
\code{cdb$id} is provided. If a \code{cdb$id} is provided
the function fails when a document with the given id
already exists. In this case one should use
\code{cdbUpdateDoc()}. Since version v0.6 the function
writes the \code{_rev} and \code{_id} key to the top
level of \code{cdb$dataList}.
This function is called addDoc (which means add a new document). Therefore
the \code{cdb$id} is requested using \code{cdbGetUuid()} for every document
to add if no \code{cdb$id} is provided. If a \code{cdb$id} is provided the
function fails when a document with the given id already exists. In this
case one should use \code{cdbUpdateDoc()}. Since version v0.6 the function
writes the \code{_rev} and \code{_id} key to the top level of
\code{cdb$dataList}.
}
\examples{
\dontrun{
Expand All @@ -38,10 +35,10 @@ ccc <- cdbAddDoc(ccc)
}
}
\author{
wactbprot
wactbprot
}
\seealso{
\code{cdbGetDoc()}
\code{cdbGetDoc()}
}
\keyword{misc}

25 changes: 12 additions & 13 deletions R4CouchDB/man/cdbDeleteDoc.Rd
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{cdbDeleteDoc}
\alias{cdbDeleteDoc}
\title{Deletes a document from a database}
\usage{
cdbDeleteDoc(cdb)
cdbDeleteDoc(cdb)
}
\arguments{
\item{cdb}{Beside \code{cdb$serverName}, \code{cdb$port}
and \code{cdb$DBName} the \code{cdb$id} must be given. R
errors are reported in \code{cdb$errors}}
\item{cdb}{Beside \code{cdb$serverName}, \code{cdb$port} and
\code{cdb$DBName} the \code{cdb$id} must be given. R errors are reported in
\code{cdb$errors}}
}
\value{
\item{cdb }{The result of the delete request is stored in
\code{cdb$res}(whatever this means). }
\item{cdb }{The result of the delete request is stored in
\code{cdb$res}(whatever this means). }
}
\description{
With a given \code{cdb$id} this function sends a http
\code{"DELETE"} request to the url
\code{.../cdb$id?rev=cdb$rev}.
With a given \code{cdb$id} this function sends a http \code{"DELETE"}
request to the url \code{.../cdb$id?rev=cdb$rev}.
}
\author{
wactbprot
wactbprot
}
\references{
\url{ http://couchdb.apache.org/ } \url{
http://www.omegahat.org/ }
\url{ http://couchdb.apache.org/ } \url{ http://www.omegahat.org/ }
}
\seealso{
\code{cdbAddDoc()}
\code{cdbAddDoc()}
}
\keyword{misc}

24 changes: 11 additions & 13 deletions R4CouchDB/man/cdbGetConfig.Rd
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{cdbGetConfig}
\alias{cdbGetConfig}
\title{Request couchdb config}
\usage{
cdbGetConfig(cdb)
cdbGetConfig(cdb)
}
\arguments{
\item{cdb}{Only the connection settings \code{cdb$port}
and \code{cdb$serverName} is needed.}
\item{cdb}{Only the connection settings \code{cdb$port} and
\code{cdb$serverName} is needed.}
}
\value{
\item{cdb }{The result of the request is stored in
\code{cdb$re} after converting the answer into a list
using \code{fromJSON()}. }
\item{cdb }{The result of the request is stored in \code{cdb$re} after
converting the answer into a list using \code{fromJSON()}. }
}
\description{
Function provides access to the \code{_config} api end
point
Function provides access to the \code{_config} api end point
}
\examples{
\dontrun{
cdbGetConfig(cdbIni())$res
}
}
\author{
wactbprot
wactbprot
}
\references{
\url{ http://www.omegahat.org/RCurl/ } \url{
http://www.omegahat.org/RJSONIO/ } \url{
http://couchdb.apache.org/ }
\url{ http://www.omegahat.org/RCurl/ } \url{
http://www.omegahat.org/RJSONIO/ } \url{ http://couchdb.apache.org/ }
}
\seealso{
\code{cdbMakeDB}
\code{cdbMakeDB}
}
\keyword{misc}

31 changes: 14 additions & 17 deletions R4CouchDB/man/cdbGetDoc.Rd
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{cdbGetDoc}
\alias{cdbGetDoc}
\title{Get a doc from CouchDB}
\usage{
cdbGetDoc(cdb)
cdbGetDoc(cdb)
}
\arguments{
\item{cdb}{Beside \code{cdb$serverName}, \code{cdb$port}
and \code{cdb$DBName} the \code{cdb$id} must be given. R
errors are reported
\item{cdb}{Beside \code{cdb$serverName}, \code{cdb$port} and
\code{cdb$DBName} the \code{cdb$id} must be given. R errors are reported

in cdb$errors}
in cdb$errors}
}
\value{
\item{cdb }{The result of the request is stored in
\code{cdb$res} after converting the answer into a list
using \code{fromJSON()}. If a list entry needed in
\code{cdb} is not provided \code{cdb$error} gives some
information.
\item{cdb }{The result of the request is stored in \code{cdb$res} after
converting the answer into a list using \code{fromJSON()}. If a list entry
needed in \code{cdb} is not provided \code{cdb$error} gives some
information.

}
}
}
\description{
With a given \code{cdb$id} this function requests the
document.
With a given \code{cdb$id} this function requests the document.
}
\examples{
\dontrun{
Expand All @@ -34,14 +32,13 @@ cdbGetDoc(ccc)$res
}
}
\author{
wactbprot
wactbprot
}
\references{
\url{ http://couchdb.apache.org/ } \url{
http://www.omegahat.org/ }
\url{ http://couchdb.apache.org/ } \url{ http://www.omegahat.org/ }
}
\seealso{
\code{cdbAddDoc()}
\code{cdbAddDoc()}
}
\keyword{misc}

Loading

0 comments on commit 472861c

Please sign in to comment.