Skip to content

Commit

Permalink
Merge pull request #1 from misdirectedpuffin/pylint-fixes
Browse files Browse the repository at this point in the history
Pylint fixes
  • Loading branch information
uoshvis committed Mar 5, 2018
2 parents 6befe12 + 998a0dc commit a631965
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Quick Start
from cryptowatch.api_client import Client
client = Client()
#get assets
assets = get_assets()
# get assets
assets = client.get_assets()
#get markets which have btc as base or quote
assets_btc = get_assets('btc')
# get markets which have btc as base or quote
assets_btc = client.get_assets('btc')
For more `check out the documentation <https://python-cryptowatch.readthedocs.io/en/latest/>`_.
21 changes: 16 additions & 5 deletions cryptowatch/api_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
"""Module contining the interface to the API client."""

from urllib.parse import quote_plus, urlencode

import requests
from urllib.parse import urlencode, quote_plus
from .exceptions import CryptowatchAPIException, CryptowatchResponseException

from cryptowatch.exceptions import (
CryptowatchAPIException,
CryptowatchResponseException
)


class Client(object):
"""The public client to the cryptowat.ch api."""

API_URL = 'https://api.cryptowat.ch'
ROUTES_MARKET = ['price', 'summary', 'orderbook', 'trades', 'ohlc']
Expand All @@ -14,13 +22,15 @@ def __init__(self):
self.uri = 'https://api.cryptowat.ch'
self.session = self._init_session()

def _init_session(self):
@staticmethod
def _init_session():
session = requests.Session()
session.headers.update({'Accept': 'application/json',
'User-Agent': 'cryptowatch/python'})
return session

def _encode_params(self, **kwargs):
@staticmethod
def _encode_params(**kwargs):
data = kwargs.get('data', None)
payload = {}
if data['route'] == 'trades':
Expand Down Expand Up @@ -57,7 +67,8 @@ def _request_api(self, method, path, symbol):
def _get(self, path, symbol=None):
return self._request_api('get', path, symbol)

def _handle_response(self, response):
@staticmethod
def _handle_response(response):
if not str(response.status_code).startswith('2'):
raise CryptowatchAPIException(response)
try:
Expand Down
7 changes: 7 additions & 0 deletions cryptowatch/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""Custom exceptions module."""


class CryptowatchAPIException(Exception):
"""Raised when the API response is not 2xx."""

def __init__(self, response):
self.status_code = response.status_code
self.reason = response.reason
Expand All @@ -9,6 +14,8 @@ def __str__(self):


class CryptowatchResponseException(Exception):
"""Raised for an invalid json response from the API"""

def __init__(self, message):
self.message = message

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pytest==3.4.1
requests==2.18.4
requests-mock==1.4.0
urllib3==1.22

0 comments on commit a631965

Please sign in to comment.