#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from heartbeat import Challenge

import requests

from .utils import urlify
from .exc import DownstreamError


class DownstreamClient(object):
    def __init__(self, server_url):
        self.server = server_url.strip('/')
        self.challenges = []

    def connect(self, url):
        raise NotImplementedError

    def store_path(self, path):
        raise NotImplementedError

    def get_chunk(self, hash):
        raise NotImplementedError

    def challenge(self, hash, challenge):
        raise NotImplementedError

    def answer(self, hash, hash_answer):
        raise NotImplementedError

    def _enc_fname(self, filename):
        return urlify(os.path.split(filename)[1])

    def get_challenges(self, filename):
        enc_fname = urlify(os.path.split(filename)[1])
        url = '%s/api/downstream/challenge/%s' % (self.server, enc_fname)
        resp = requests.get(url)

    def answer_challenge(self, filename):
        enc_fname = self._enc_fname(filename)
        raise NotImplementedError
@@ -939,16 +939,414 @@
 get(url)
+%0A        try:%0A            resp.raise_for_status()%0A        except Exception as e:%0A            raise DownstreamError(%22Error connecting to downstream-node:%22,%0A                                        e.message)%0A%0A        _json = resp.json()%0A%0A        for challenge in _json%5B'challenges'%5D:%0A            chal = Challenge(challenge.get('block'), challenge.get('seed'))%0A            self.challenges.append(chal)
 %0A%0A    de

Add check_connectivity helper meth