Skip to content

Commit

Permalink
Docs: Update TurboVote (move-coop#376)
Browse files Browse the repository at this point in the history
* Update docs.

* Fix class import.

* Remove incorrect docs.
  • Loading branch information
jburchard authored Sep 14, 2020
1 parent 55a3b3a commit 3b96085
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
38 changes: 36 additions & 2 deletions docs/turbovote.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
TurboVote
=========

`TurboVote <https://turbovote.org/>`_ is an online registration tool used by progressive organizations.
`TurboVote <https://turbovote.org/>`_ is an online voter registration and vote by mail
tool. This class contains a single method which allows you to export your users
(aka signups).

.. autoclass :: parsons.turbovote.turbovote.TurboVote
.. note::
Authentication
TurboVote requires `HTTP Basic Auth <https://en.wikipedia.org/wiki/Basic_access_authentication>`_.
Clients with a TurboVote account must pass their subdomain, username, and password.

**********
QuickStart
**********

To instantiate the TurboVote class, you can either store your TurboVote API
username, password, subdomain as environmental variables (``TURBOVOTE_USERNAME``,
``TURBOVOTE_PASSWORD``, and ``TURBOVOTE_SUBDOMAIN``, respectively) or pass them
in as arguments:

.. code-block:: python
from parsons import TurboVote
# First approach: Pass credentials via environmental variables.
tv = TurboVote()
# Second approach: Pass credentials as arguments.
tv = TurboVote(username='me', password='pass', subdomain='myorg')
You can then call the method:

.. code-block:: python
# Get users
tv.get_users()
.. autoclass :: parsons.TurboVote
:inherited-members:
12 changes: 1 addition & 11 deletions parsons/turbovote/turbovote.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ class TurboVote(object):
env variable set.
password: str
A valid turbovote password. Not required if ``TURBOVOTE_PASSWORD``
env variable set
env variable set.
subdomain: str
Your turbovote subdomain (i.e. ``https://MYORG.turbovote.org``). Not
required if ``TURBOVOTE_SUBDOMAIN`` env variable set.
uri: str
Base turbovote API url
`Returns:`
class
"""
Expand All @@ -39,18 +37,12 @@ def _get_token(self):
# Retrieve a temporary bearer token to access API

url = self.uri + 'login'

payload = {'username': self.username,
'password': self.password}

logger.info('Generating token...')
r = requests.post(url, data=payload)
logger.debug(r.url)

r.raise_for_status()

logger.info('Token generated.')

return r.json()['id-token']

def get_users(self):
Expand All @@ -65,8 +57,6 @@ def get_users(self):
url = self.uri + f'partners/{self.subdomain}.turbovote.org/users'

headers = {"Authorization": f"Bearer {self._get_token()}"}

logger.info('Requesting users table...')
r = requests.get(url, headers=headers)
logger.debug(r)
r.raise_for_status()
Expand Down

0 comments on commit 3b96085

Please sign in to comment.