Skip to content

Commit b6aec5b

Browse files
committed
Clean up code and improve readme
1 parent 8b9a5b5 commit b6aec5b

File tree

7 files changed

+37
-29
lines changed

7 files changed

+37
-29
lines changed

dataverse/connection.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
class Connection(object):
1010

11-
def __init__(self, host, token=None, username=None, password=None):
11+
def __init__(self, host, token):
1212
# Connection Properties
1313
self.token = token
14-
self.username = username
15-
self.password = password
1614
self.host = host
1715
self.sd_uri = "https://{host}/dvn/api/data-deposit/v1.1/swordv2/service-document".format(host=self.host)
1816
self.service_document = None
@@ -22,11 +20,7 @@ def __init__(self, host, token=None, username=None, password=None):
2220

2321
@property
2422
def auth(self):
25-
return (self.token, None) if self.token else (self.username, self.password)
26-
27-
@property
28-
def has_api_key(self):
29-
return True if self.token else False
23+
return self.token, None
3024

3125
def connect(self):
3226
resp = requests.get(self.sd_uri, auth=self.auth)

dataverse/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import requests
77

88
from exceptions import (
9-
MethodNotAllowedError, NoContainerError, OperationFailedError,
9+
NoContainerError, OperationFailedError,
1010
ConnectionError, MetadataNotFoundError, VersionJsonNotFoundError
1111
)
1212
from file import DataverseFile

dataverse/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class DataverseFile(object):
5-
def __init__(self, dataset, name, file_id=None, edit_media_uri=None):
5+
def __init__(self, dataset, name, file_id=None):
66
self.dataset = dataset
77
self.name = sanitize(name)
88
self.id = file_id

dataverse/settings/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
DEFAULT_HOST = "dataverse-demo.iq.harvard.edu"
2-
DEFAULT_TOKEN = "changeme"
1+
TEST_HOST = "dataverse-demo.iq.harvard.edu"
2+
TEST_TOKEN = "changeme"
33

44
EXAMPLE_DICT = {
55
"title": "ExampleTitle",

dataverse/test/test_dataverse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dataverse.connection import Connection
88
from dataverse.dataset import Dataset
99
from dataverse.exceptions import DataverseError
10-
from dataverse.settings import DEFAULT_TOKEN, DEFAULT_HOST
10+
from dataverse.settings import TEST_HOST, TEST_TOKEN
1111
from dataverse.test.config import PICS_OF_CATS_DATASET, ATOM_DATASET
1212
from dataverse import utils
1313

@@ -93,7 +93,7 @@ class TestDatasetOperations(unittest.TestCase):
9393
@classmethod
9494
def setUpClass(self):
9595
print "Connecting to DVN."
96-
self.dvc = Connection(DEFAULT_HOST, DEFAULT_TOKEN)
96+
self.dvc = Connection(TEST_HOST, TEST_TOKEN)
9797

9898
print "Getting Dataverse"
9999
dataverses = self.dvc.get_dataverses()

readme.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
11
## Dataverse API Client
22

33
This is a library for writing Python applications that make use of Dataverse
4-
APIs v4.0. The code started as a "proof of concept" in the
5-
[dvn/swordpoc](https://github.com/dvn/swordpoc) repo and the intent is to
6-
publish the python client on https://pypi.python.org.
4+
APIs v4.0. The intent is to publish the python client on https://pypi.python.org.
75

86
## Installation
97

10-
This client requires python 2.6+.
11-
It has not been tested in python 3.
8+
$ pip install -e git+https://github.com/IQSS/dataverse-client-python.git#egg=dataverse
9+
10+
Requires Python >= 2.6.
1211

13-
To install dataverse as a package:
1412

15-
$ pip install -e git+https://github.com/rliebz/dvn-client-python.git#egg=dataverse
13+
## Usage
1614

17-
## Configuration
15+
To use the python client, you will need a dataverse account and an API token.
16+
```python
17+
from dataverse import Connection
18+
19+
host = 'apitest.dataverse.org' # All clients >4.0 are supported
20+
token = '4d0634d3-74d5-4770-8088-1971847ac75e' # Generated at /account/apitoken
21+
22+
connection = Connection(host, token)
23+
```
24+
25+
Dataverse Objects can be retrieved from their respective containers
26+
```python
27+
dataverse = connection.get_dataverse('ALIAS')
28+
dataset = dataverse.get_dataset_by_doi('DOI:10.5072/FK2/ABC123')
29+
files = dataset.get_files('latest')
30+
```
31+
32+
## Testing
33+
34+
### Configuration
1835

1936
Create a file at `settings/local.py`. The file should contain the following
2037
information:
2138

2239
```python
23-
DEFAULT_HOST = "dataverse-demo.iq.harvard.edu"
40+
DEFAULT_HOST = "apitest.dataverse.org"
2441
DEFAULT_TOKEN = "" # Token can be generated at {host}/account/apitoken
2542
```
2643

2744
Do not commit this file.
2845

29-
## Testing
46+
### Running Tests
3047

3148
In order to run any tests, you must first create a Dataverse on the
3249
host you wish to test. Do not run tests on the production server.
3350

34-
To run tests
51+
To run tests:
3552

3653
$ cd dataverse/test
3754
$ python -m unittest test_dataverse

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# -*- coding: utf-8 -*-
2-
import re
3-
import sys
42
from setuptools import setup, find_packages
53
import unittest
6-
from setuptools.command.test import test as TestCommand
74

85

96
REQUIRES = [
@@ -24,7 +21,7 @@ def read(fname):
2421

2522
setup(
2623
name='dataverse',
27-
version='0.1',
24+
version='0.1.1',
2825
description='Python client for Dataverse version 3.X',
2926
long_description=read("readme.md"),
3027
author='Dataverse',

0 commit comments

Comments
 (0)