sofa connection client

Description

sofa connection client

Arguments

host

(character) A base URL (without the transport), e.g., localhost, 127.0.0.1, or foobar.cloudant.com

port

(numeric) Port. Remember that if you don't want a port set, set this parameter to NULL. Default: 5984

path

(character) context path that is appended to the end of the url. e.g., bar in http://foo.com/bar. Default: NULL, ignored

transport

(character) http or https. Default: http

user

(character) A user name

pwd

(character) A password

headers

Either an object of class request or a list that can be coerced to an object of class request via add_headers. These headers are used in all requests. To use headers in individual requests and not others, pass in headers using add_headers via ... in a function call.

Details

Methods

ping()

Ping the CouchDB server

make_url()

Construct full base URL from the pieces in the connection object

get_headers()

Get headers that will be sent with each request

Value

An object of class Cushion, with variables accessible for host, port, path, transport, user, pwd, and headers. Functions are callable to get headers, and to make the base url sent with all requests.

CouchDB versions

sofa was built assuming CouchDB version 2 or greater. Some functionality of this package will work with versions < 2, while some may not (mango queries, see db_query). I don't plan to support older CouchDB versions per se.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## Not run: 
# Create a CouchDB connection client
(x <- Cushion$new())

## metadata
x$host
x$path
x$port
x$type

## ping the CouchDB server
x$ping()

## CouchDB server statistics
# stats(x)

# create database
db_create(x, "stuff")

# add documents to a database
db_create(x, "sofadb")
doc1 <- '{"name": "drink", "beer": "IPA", "score": 5}'
doc_create(x, dbname="sofadb", docid="abeer", doc1)

# bulk create
db_create(x, "mymtcars")
bulk_create(x, dbname="mymtcars", doc = mtcars)
db_list(x)

## database info
db_info(x, "bulktest")

## list dbs
db_list(x)

## all docs
alldocs(x, "bulktest", limit = 3)

## changes
changes(x, "bulktest")

# With auth
x <- Cushion$new(user = 'sckott', pwd = 'sckott')

# Using Cloudant
z <- Cushion$new(host = "ropensci.cloudant.com", transport = 'https', port = NULL,
   user = 'ropensci', pwd = Sys.getenv('CLOUDANT_PWD'))
z
db_list(z)
db_create(z, "stuff2")
db_info(z, "stuff2")
alldocs(z, "foobar")

## End(Not run)