Skip to content

Commit

Permalink
#1 - add auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdavisgithub committed Sep 28, 2016
1 parent f9ce3b6 commit bc9ee95
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions dandelion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DandelionConfig(dict):
""" class for storing the default dandelion configuration, such
as authentication parameters
"""
ALLOWED_KEYS = ['app_id', 'app_key']
ALLOWED_KEYS = ['token']

def __setitem__(self, key, value):
if not key in self.ALLOWED_KEYS:
Expand Down Expand Up @@ -55,20 +55,17 @@ def __init__(self, **kwargs):
import requests
from dandelion import default_config
self.uri = self._get_uri(host=kwargs.get('host'))
self.app_id = kwargs.get('app_id', default_config.get('app_id'))
self.app_key = kwargs.get('app_key', default_config.get('app_key'))
self.token = kwargs.get('token', default_config.get('token'))

self.requests = requests.session()
self.cache = kwargs.get('cache', NoCache())

if self.REQUIRE_AUTH and not self.app_id:
raise MissingParameterException("app_id")
if self.REQUIRE_AUTH and not self.app_key:
raise MissingParameterException("app_key")
if self.REQUIRE_AUTH and not self.token:
raise MissingParameterException("token")

def do_request(self, params, extra_url='', method='post', **kwargs):
if self.REQUIRE_AUTH:
params['$app_id'] = self.app_id
params['$app_key'] = self.app_key
params['token'] = self.token

url = self.uri + ''.join('/' + x for x in extra_url)

Expand Down

0 comments on commit bc9ee95

Please sign in to comment.