Skip to content

Commit

Permalink
Merge pull request #1 from cloudant-labs/cloudant
Browse files Browse the repository at this point in the history
Cloudant
  • Loading branch information
garbados committed Nov 4, 2013
2 parents 727d866 + bfad293 commit 2e90144
Show file tree
Hide file tree
Showing 29 changed files with 1,258 additions and 573 deletions.
40 changes: 4 additions & 36 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
local_credentials.py
.idea
cloudant.py

*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
venv
*.pyc
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
dist
.coverage
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: python
python:
- "2.7"
services:
- couchdb
before_script:
- pip install coverage coveralls
script:
- coverage run --source=cloudant setup.py test
after_success:
- coveralls
3 changes: 0 additions & 3 deletions CHANGES.md

This file was deleted.

3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Contributors
============

healthy is written and maintained by [Dustin Collins](https://github.com/dustinmm80)
* [Dustin Collins](https://github.com/dustinmm80)
* [Max Thayer](http://github.com/garbados)
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

31 changes: 0 additions & 31 deletions README.md

This file was deleted.

Binary file removed api_reference_v102.pdf
Binary file not shown.
8 changes: 6 additions & 2 deletions cloudant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/usr/bin/env python
# coding=utf-8
from resource import Resource
from connection import Connection
from database import Database
from document import Document
from attachment import Attachment
from view import View
10 changes: 10 additions & 0 deletions cloudant/attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .resource import Resource


class Attachment(Resource):

"""
Attachment methods for a single document
"""

pass # lawl everything is defined by the parent class :D
153 changes: 0 additions & 153 deletions cloudant/client.py

This file was deleted.

77 changes: 77 additions & 0 deletions cloudant/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from .resource import Resource
from .database import Database


class Connection(Resource):

"""
A connection to a Cloudant or CouchDB instance.
connection = cloudant.Connection()
connection.login(USERNAME, PASSWORD).result()
print connection.get().result().json()
# {"couchdb": "Welcome", ...}
"""

def __init__(self, uri="http://localhost:5984", **kwargs):
super(Connection, self).__init__(uri, **kwargs)

def database(self, name, **kwargs):
"""Create a `Database` object prefixed with this connection's URL."""
opts = dict(self.opts.items() + kwargs.items())
return Database(self._make_url(name), session=self._session, **opts)

def __getitem__(self, name):
"""Shortcut to `Connection.database`."""
return self.database(name, **self.opts)

def all_dbs(self, **kwargs):
"""List all databases."""
return self.get('_all_dbs', **kwargs)

def session(self, **kwargs):
"""Get current user's authentication and authorization status."""
return self.get('_session', **kwargs)

def login(self, username, password, **kwargs):
"""Authenticate the connection via cookie."""
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
data = "name=%s&password=%s" % (username, password)
return self.post('_session', headers=headers, data=data, **kwargs)

def logout(self, **kwargs):
"""De-authenticate the connection's cookie."""
return self.delete('_session', **kwargs)

def active_tasks(self, **kwargs):
"""List replication, compaction, and indexer tasks currently running."""
return self.get('_active_tasks', **kwargs)

def replicate(self, source, target, opts={}, **kwargs):
"""
Begin a replication job.
`opts` contains replication options such as whether the replication
should create the target (`create_target`) or whether the replication
is continuous (`continuous`).
Note: unless continuous, will not return until the job is finished.
"""

params = {
'source': source,
'target': target
}

params.update(opts)
if 'params' in kwargs:
params.update(kwargs['params'])
del kwargs['params']

return self.post('_replicate', params=params, **kwargs)

def uuids(self, count=1, **kwargs):
"""Generate an arbitrary number of UUIDs."""
params = dict(count=count)
return self.get('_uuids', params=params, **kwargs)
Loading

0 comments on commit 2e90144

Please sign in to comment.