コード例 #1
0
ファイル: __init__.py プロジェクト: closeio/closeio-api
    def __init__(self, base_url, api_key=None, tz_offset=None, max_retries=5,
                 verify=True):
        assert base_url
        self.base_url = base_url
        self.max_retries = max_retries
        self.tz_offset = str(tz_offset or local_tz_offset())
        self.verify = verify

        self.session = requests.Session()
        if api_key:
            self.session.auth = (api_key, '')

        self.session.headers.update({
            'Content-Type': 'application/json',
            'X-TZ-Offset': self.tz_offset
        })
コード例 #2
0
    def __init__(self, base_url, api_key=None, tz_offset=None, max_retries=5,
                 verify=True):
        assert base_url
        self.base_url = base_url
        self.max_retries = max_retries
        self.tz_offset = str(tz_offset or local_tz_offset())
        self.verify = verify

        self.session = requests.Session()
        if api_key:
            self.session.auth = (api_key, '')

        self.session.headers.update({
            'User-Agent': 'Close/{} python ({})'.format(
                __version__,
                requests.utils.default_user_agent()
            ),
            'X-TZ-Offset': self.tz_offset
        })
コード例 #3
0
ファイル: __init__.py プロジェクト: sixhobbits/closeio-api
    def __init__(self,
                 base_url,
                 api_key=None,
                 tz_offset=None,
                 max_retries=5,
                 verify=True):
        assert base_url
        self.base_url = base_url
        self.max_retries = max_retries
        self.tz_offset = str(tz_offset or local_tz_offset())
        self.verify = verify

        self.session = requests.Session()
        if api_key:
            self.session.auth = (api_key, '')

        self.session.headers.update({
            'Content-Type': 'application/json',
            'X-TZ-Offset': self.tz_offset
        })
コード例 #4
0
        self.field_errors = data.get('field-errors', {})


class API(object):
    def __init__(self,
                 base_url,
                 api_key=None,
                 tz_offset=None,
                 async=False,
                 max_retries=5,
                 verify=True):
        assert base_url
        self.base_url = base_url
        self. async = async
        self.max_retries = max_retries
        self.tz_offset = tz_offset or str(local_tz_offset())
        self.verify = verify

        if async:
            import grequests
            self.requests = grequests
        else:
            self.requests = requests

        self.session = self.requests.Session()
        if api_key:
            self.session.auth = (api_key, '')
        self.session.headers.update({
            'Content-Type': 'application/json',
            'X-TZ-Offset': self.tz_offset
        })
コード例 #5
0
ファイル: __init__.py プロジェクト: guitarmaniak8/closeio-api
class APIError(Exception):
    pass

class API(object):
    def __init__(self, base_url, api_key, tz_offset=None, async=False, max_retries=5):
        assert base_url
        self.base_url = base_url
        self.api_key = api_key
        self.async = async
        self.max_retries = max_retries
        if async:
            import grequests
            self.requests = grequests
        else:
            self.requests = requests.Session()
        self.tz_offset = tz_offset or local_tz_offset()

    def dispatch(self, method_name, endpoint, data=None):
        method = getattr(self.requests, method_name)

        retries = 0
        while True and retries < self.max_retries:
            try:
                response = method(
                    self.base_url+endpoint,
                    data=data != None and json.dumps(data),
                    auth=(self.api_key, ''),
                    headers={'Content-Type': 'application/json', 'X-TZ-Offset': self.tz_offset}
                )
                break
            except requests.exceptions.ConnectionError:
コード例 #6
0
ファイル: __init__.py プロジェクト: pablofernandezcom/close
import six
from six.moves.urllib.parse import urlencode


class APIError(Exception):
    pass


class API(object):
    def __init__(self, base_url, api_key, tz_offset=None,
                 async=False, max_retries=5):
        assert base_url
        self.base_url = base_url
        self.async = async
        self.max_retries = max_retries
        self.tz_offset = tz_offset or str(local_tz_offset())

        if async:
            import grequests
            self.requests = grequests
        else:
            self.requests = requests

        self.session = self.requests.Session()

        self.session.auth = (api_key, '')
        self.session.headers.update({'Content-Type': 'application/json', 'X-TZ-Offset': self.tz_offset})

    def _print_request(self, request):
        print('{}\n{}\n{}\n\n{}\n{}'.format(
            '----------- HTTP Request -----------',