authorization_base_url = 'https://accounts.google.com/o/oauth2/auth'
    obtain_token_url = 'https://accounts.google.com/o/oauth2/token'
    scope_list = ['https://spreadsheets.google.com/feeds']
    auth_base_url_kwargs = {'access_type': 'offline',
                            'approval_prompt': 'force'}

    if client_id == '<client/app id>':
        raise ValueError('Configure each variable for your Oauth2 request process.')

    o = Oauth2TokenRequester(client_id,
                             client_secret=client_secret,
                             redirect_uri=redirect_uri,
                             authorization_base_url=authorization_base_url,
                             obtain_token_url=obtain_token_url,
                             scope_list=scope_list,
                             **auth_base_url_kwargs)

    authorization_url = o.authorize_app()

    print ('\n###### OauthRequester User Prompt ######\n'
           '1. Please go to the following URL to authorize access: \n\n%s' % authorization_url)

    redirect_response = raw_input('\n2. Enter the full callback URL that your request was '
                                  'redirected to:\n')

    token = o.get_token(redirect_response)

    return token

Gsheets = generate_wrapper_from_adapter(GsheetsClientAdapter)
Beispiel #2
0
# coding: utf-8

from tapioca import (TapiocaAdapter, generate_wrapper_from_adapter,
                     JSONAdapterMixin)

from .resource_mapping import RESOURCE_MAPPING


class Zeus_wrapperClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://private-anon-befeaec343-izeusv3.apiary-mock.com/cgi-bin/api/v3'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(Zeus_wrapperClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Zeus_wrapper = generate_wrapper_from_adapter(Zeus_wrapperClientAdapter)
class CrunchbaseClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.crunchbase.com/v/3/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(CrunchbaseClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        if 'params' in params:
            params['params'].update({'user_key': api_params.get('user_key')})
        else:
            params['params'] = {'user_key': api_params.get('user_key')}

        return params

    def get_iterator_list(self, response_data):
        return response_data['data']['items']

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data, response):
        data = response_data.get('data')
        paging = data.get('paging')
        if not paging:
            return
        next_page_url = paging.get('next_page_url')
        if next_page_url:
            return {'url': next_page_url}


Crunchbase = generate_wrapper_from_adapter(CrunchbaseClientAdapter)
from tapioca import (TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin)
from requests_oauthlib import OAuth2
from .sently_resource_mapping import RESOURCE_MAPPING
from .printers import sentlyinfo

class SentlyClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://apiserver.sent.ly/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(SentlyClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id', ''), token={
                'access_token': api_params.get('access_token'),
                'token_type': 'Bearer'})
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

Sently = generate_wrapper_from_adapter(SentlyClientAdapter)
Sently.info = sentlyinfo
class YoutubeClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://www.googleapis.com/youtube/v3/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(YoutubeClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id', ''), token={
                'access_token': self.auth(api_params.get('client_id'), api_params.get('client_secret')),
                'token_type': 'Bearer'})
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def auth(self, client_id, client_secret):
        global access_token
        if not access_token:
            scope = 'https://www.googleapis.com/auth/youtube'
            access_token = google_auth(client_id, client_secret, scope)
        return access_token

Youtube = generate_wrapper_from_adapter(YoutubeClientAdapter)
Youtube.info = youtubeinfo
class GmailClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://www.googleapis.com/gmail/v1/users/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(GmailClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id', ''), token={
                'access_token': self.auth(api_params.get('client_id'), api_params.get('client_secret')),
                'token_type': 'Bearer'})
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def auth(self, client_id, client_secret):
        global access_token
        if not access_token:
            scope = 'https://www.googleapis.com/auth/gmail.modify'
            access_token = google_auth(client_id, client_secret, scope)
        return access_token

Gmail = generate_wrapper_from_adapter(GmailClientAdapter)
Gmail.info = gmailinfo
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(FacebookClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = OAuth2(api_params.get('client_id'),
                                token={
                                    'access_token':
                                    api_params.get('access_token'),
                                    'token_type': 'Bearer'
                                })

        return params

    def get_iterator_list(self, response_data):
        return response_data['data']

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        paging = response_data.get('paging')
        if not paging:
            return
        url = paging.get('next')

        if url:
            return {'url': url}


Facebook = generate_wrapper_from_adapter(FacebookClientAdapter)
Beispiel #8
0
from requests.auth import HTTPBasicAuth

from .resource_mapping import RESOURCE_MAPPING


class DeskClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(DeskClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(api_params.get('user'),
                                       api_params.get('password'))

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def get_api_root(self, api_params):
        return 'https://{}.desk.com/api/v2'.format(api_params['site'])


Desk = generate_wrapper_from_adapter(DeskClientAdapter)
                        return True
                else:
                    logging.info('Исчерпан лимит запросов')
        return False

    def to_df(self, data, *args, **kwargs):
        """Преобразование в DataFrame"""
        try:
            df = json_normalize(data.get('items') or data)
        except Exception:
            raise TypeError('Не удалось преобразовать в DataFrame')
        else:
            return df


Mytarget = generate_wrapper_from_adapter(MytargetClientAdapter)


class MytargetLight:
    CAMPAIGN_STATS = 'campaigns'
    BANNER_STATS = 'banners'
    USER_STATS = 'users'
    _SUMMARY_STATS = 'summary'
    _DAY_STATS = 'day'

    def __init__(self,
                 access_token,
                 as_dataframe=False,
                 retry_request_if_limit=True,
                 language='ru',
                 *args,
Beispiel #10
0
        if api_root:
            return api_root
        else:
            return self.api_root

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(DiscourseClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        auth = {
            'api_key': api_params.get('api_key'),
            'api_username': api_params.get('api_username'),
        }

        if 'params' in params:
            params['params'].update(auth)
        else:
            params['params'] = auth

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Discourse = generate_wrapper_from_adapter(DiscourseClientAdapter)
Beispiel #11
0
    api_root = 'https://api.trello.com/1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(TrelloClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs
        )

        auth = {
            'key': api_params.get('key'),
            'token': api_params.get('token'),
        }

        if 'params' in params:
            params['params'].update(auth)
        else:
            params['params'] = auth

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Trello = generate_wrapper_from_adapter(TrelloClientAdapter)
Beispiel #12
0
    TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin)

from requests.auth import HTTPBasicAuth
from .resource_mapping import RESOURCE_MAPPING


class KigoClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://app.kigo.net/api/ra/v1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(KigoClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        
        params['auth'] = HTTPBasicAuth(
            api_params.get('user'), api_params.get('password'))
        

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data, response):
        pass


Kigo = generate_wrapper_from_adapter(KigoClientAdapter)
Beispiel #13
0

class TrustwaveClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = '{protocol}://{server}/Hailstorm.WS/HailstormRESTService.svc/client/{client}/customer/{customer}/'
    resource_mapping = RESOURCE_MAPPING

    def get_api_root(self, api_params):
        protocol = api_params.get('protocol', 'https')  # default https
        server = api_params.get('server')
        client = api_params.get('client')
        customer = api_params.get('customer')
        return self.api_root.format(protocol=protocol,
                                    server=server,
                                    client=client,
                                    customer=customer)

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(TrustwaveClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Trustwave = generate_wrapper_from_adapter(TrustwaveClientAdapter)
Beispiel #14
0
class IuguClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.iugu.com/v1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(IuguClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(api_params.get('user'), '')

        return params

    def get_iterator_list(self, response_data):
        return response_data.get('items', response_data)

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        if 'params' not in iterator_request_kwargs:
            iterator_request_kwargs['params'] = {}

        start = iterator_request_kwargs['params'].get('start', 0)
        total_items = response_data.get('totalItems')
        items = len(response_data.get('items'))
        if total_items >= items + start:
            iterator_request_kwargs['params']['start'] = start + items
            return iterator_request_kwargs


Iugu = generate_wrapper_from_adapter(IuguClientAdapter)
from tapioca import (TapiocaAdapter, generate_wrapper_from_adapter,
                     JSONAdapterMixin)

from .resource_mapping import RESOURCE_MAPPING


class JarbasClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://jarbas.serenata.ai/api/chamber_of_deputies/'
    resource_mapping = RESOURCE_MAPPING

    def get_iterator_list(self, response_data):
        return response_data.get('results', response_data)

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        next_url = response_data.get('next', '')
        if not next_url:
            return

        iterator_request_kwargs['url'] = next_url
        iterator_request_kwargs.pop('params',
                                    None)  # these are sent in the next_url
        return iterator_request_kwargs


Jarbas = generate_wrapper_from_adapter(JarbasClientAdapter)
from tapioca import (TapiocaAdapter, generate_wrapper_from_adapter,
                     JSONAdapterMixin)

from requests.auth import HTTPBasicAuth

from .resource_mapping import RESOURCE_MAPPING


class AsanaClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://app.asana.com/api/1.0'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(AsanaClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(api_params.get('personal_key'), '')

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Asana = generate_wrapper_from_adapter(AsanaClientAdapter)
Beispiel #17
0
                     JSONAdapterMixin)

from resource_mapping import RESOURCE_MAPPING


class CbrainClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://portal.cbrain.mcgill.ca/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        kwargs = super(CbrainClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        kwargs['headers'] = {'Accept': 'application/json'}

        kwargs['params'] = {
            'cbrain_api_token': api_params.get('cbrain_api_token')
        }

        return kwargs

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Cbrain = generate_wrapper_from_adapter(CbrainClientAdapter)
    api_root = 'https://api.parse.com/1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(ParseClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        if 'headers' not in params:
            params['headers'] = {}

        params['headers'].update({
            'X-Parse-Application-Id': api_params.get('application_id'),
            'X-Parse-REST-API-Key': api_params.get('rest_api_key')})

        return params

    def get_iterator_list(self, response_data):
        return response_data.get('results')

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data, response):
        limit = 100
        params = iterator_request_kwargs.get('params', {'limit': limit, 'skip': -limit})
        params['skip'] = params['limit'] + params['skip']
        iterator_request_kwargs['params'] = params

        return iterator_request_kwargs


Parse = generate_wrapper_from_adapter(ParseClientAdapter)

class GithubClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.github.com/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        arguments = super(GithubClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)
        client_id = api_params.get('client_id')
        arguments['auth'] = OAuth2(
            client_id, token={'access_token': api_params.get('access_token')})
        return arguments

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(
            self, iterator_request_kwargs, response_data, response):
        if "Link" in response.headers:
            links = response.headers["Link"].split(", ")
            for link in links:
                (url, rel) = link.split("; ")
                url = url[1:-1]
                rel = rel[5:-1]
                if rel == 'next':
                    return {'url': url}


Github = generate_wrapper_from_adapter(GithubClientAdapter)
Beispiel #20
0
        else:
            params['auth'] = HTTPBasicAuth(api_params.get('user'),
                                           api_params.get('password'))

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def response_to_native(self, response):
        if response.headers._store['content-type'][
                1] == 'application/octet-stream':
            return response

        elif response.content.strip():
            return response.json()

    def format_data_to_request(self, data):
        if data:
            try:
                return json.dumps(data)
            except:
                return data


Nessus = generate_wrapper_from_adapter(NessusClientAdapter)
Beispiel #21
0
from .resource_mapping import RESOURCE_MAPPING


class TogglClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://www.toggl.com/api/v8/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(TogglClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        access_token = api_params.get('access_token')

        if access_token:
            params['auth'] = HTTPBasicAuth(access_token, 'api_token')
        else:
            params['auth'] = HTTPBasicAuth(api_params.get('user'),
                                           api_params.get('password'))

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Toggl = generate_wrapper_from_adapter(TogglClientAdapter)
Beispiel #22
0

class CanvasClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    resource_mapping = RESOURCE_MAPPING

    def get_api_root(self, api_params):
        return api_params.get('api_root', 'http://localhost')

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(CanvasClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = OAuth2(api_params.get('client_id', ''),
                                token={
                                    'access_token':
                                    api_params.get('access_token'),
                                    'token_type': 'Bearer'
                                })

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Canvas = generate_wrapper_from_adapter(CanvasClientAdapter)
Beispiel #23
0
from tapioca import TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin

from requests.auth import HTTPBasicAuth

from .resource_mapping import RESOURCE_MAPPING


class CircleCIClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://circleci.com/api/v1.1/'
    resource_mapping = RESOURCE_MAPPING
    _default_resource_kwargs = {'vcs_type': 'github', 'branch': 'master'}

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super().get_request_kwargs(api_params, *args, **kwargs)
        params['auth'] = HTTPBasicAuth(api_params.get('token'), '')
        params['headers']['Content-Type'] = 'application/json;charset=UTF-8'
        params['timeout'] = api_params.get('timeout', kwargs.get('timeout', 5))
        return params

    def fill_resource_template_url(self, template, params):
        for key in self._default_resource_kwargs:
            if key in template and key not in params:
                params[key] = self._default_resource_kwargs[key]

        return super().fill_resource_template_url(template, params)


CircleCI = generate_wrapper_from_adapter(CircleCIClientAdapter)
from requests_oauthlib import OAuth2


from .resource_mapping import RESOURCE_MAPPING


class LinkedinClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.linkedin.com/v1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(LinkedinClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id', ''), token={
                'access_token': api_params.get('access_token'),
                'token_type': 'Bearer'})
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Linkedin = generate_wrapper_from_adapter(LinkedinClientAdapter)
class TogglClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://www.toggl.com/api/v8/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(TogglClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs
        )

        access_token = api_params.get('access_token')

        if access_token:
            params['auth'] = HTTPBasicAuth(access_token, 'api_token')
        else:
            params['auth'] = HTTPBasicAuth(
                api_params.get('user'),
                api_params.get('password')
            )

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Toggl = generate_wrapper_from_adapter(TogglClientAdapter)
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(HarvestClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(
            api_params.get('user'), api_params.get('password'))

        params['headers'] = params.get('headers', {})
        params['headers']['Accept'] = 'application/json'

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def response_to_native(self, response):
        if response.content.strip():
            return super(HarvestClientAdapter, self).response_to_native(response)

    def get_api_root(self, api_params):
        return 'https://' + api_params['company_name'] + '.harvestapp.com/'


Harvest = generate_wrapper_from_adapter(HarvestClientAdapter)
Beispiel #27
0
from tapioca import TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin

from .resource_mapping import RESOURCE_MAPPING


class DisqusClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = "https://disqus.com/api/3.0/"
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(DisqusClientAdapter, self).get_request_kwargs(api_params, *args, **kwargs)
        if "params" in params:
            params["params"].update({"api_secret": api_params.get("api_secret")})
        else:
            params["params"] = {"api_secret": api_params.get("api_secret")}
        return params

    def get_iterator_list(self, response_data):
        return response_data["response"]

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs, response_data, response):
        cursor = response_data.get("cursor")
        if not cursor or not cursor.get("hasNext"):
            return
        next_val = cursor.get("next")
        if next_val:
            return {"url": "{}&cursor=".format(response.url, next_val)}


Disqus = generate_wrapper_from_adapter(DisqusClientAdapter)
Beispiel #28
0
        if api_root:
            return api_root
        else:
            return self.api_root

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(CloudezClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = HTTPTokenAuth(api_params.get('auth_token'))

        return params

    def get_iterator_list(self, response_data):
        if isinstance(response_data, list):
            return response_data
        elif isinstance(response_data, dict) and 'results' in response_data:
            return response_data['results']

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        if isinstance(response_data, dict):
            next = response_data.get('next')

            if next:
                return {'url': next}


Cloudez = generate_wrapper_from_adapter(CloudezClientAdapter)
Beispiel #29
0
from requests_oauthlib import OAuth2
from tapioca import JSONAdapterMixin, TapiocaAdapter, generate_wrapper_from_adapter

from resource_mapping import RESOURCE_MAPPING


class SlackClientAdapter(JSONAdapterMixin, TapiocaAdapter):

    api_root = "https://slack.com/api/"
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(SlackClientAdapter, self).get_request_kwargs(api_params, *args, **kwargs)

        params["auth"] = OAuth2(
            api_params.get("client_id", ""),
            token={"access_token": api_params.get("access_token"), "token_type": "Bearer"},
        )

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs, response_data, response):
        pass


Slack = generate_wrapper_from_adapter(SlackClientAdapter)
Beispiel #30
0
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(api_params.get('user'),
                                       api_params.get('password'))

        if 'headers' not in params:
            params['headers'] = {}

        params['headers'].update({'Content-Type': 'application/json'})

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def response_to_native(self, response):
        if response.content.strip():
            if 'xml' in response.headers['content-type']:
                return xmltodict.parse(response.content,
                                       **self._xmltodict_parse_kwargs)
            elif 'json' in response.headers['content-type']:
                return response.json()
        return {'text': response.text}


Qualys_was = generate_wrapper_from_adapter(Qualys_wasClientAdapter)
    api_root = 'https://api.bitbucket.org/2.0'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(BitbucketClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id'), token={
            'access_token': api_params.get('access_token'),
            'token_type': 'Bearer'})

        return params

    def get_iterator_list(self, response_data):
        return response_data['values']

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data, response):
        page = response_data.get('page')
        if not page:
            return

        url = response_data.get('next')

        if url:
            return {'url': url}


Bitbucket = generate_wrapper_from_adapter(BitbucketClientAdapter)
Beispiel #32
0
from requests_oauthlib import OAuth2


from .resource_mapping import RESOURCE_MAPPING


class GoogleClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://www.googleapis.com/plus/v1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(GoogleClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id', ''), token={
                'access_token': api_params.get('access_token'),
                'token_type': 'Bearer'})
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Google = generate_wrapper_from_adapter(GoogleClientAdapter)
class GithubClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.github.com/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params):
        client_id = api_params.get('client_id')
        return {
            'auth': OAuth2(
                client_id,
                token={'access_token': api_params.get('access_token')}
            ),
        }

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data, response):
        if "Link" in response.headers:
            links = response.headers["Link"].split(", ")
            for link in links:
                (url, rel) = link.split("; ")
                url = url[1:-1]
                rel = rel[5:-1]
                if rel == 'next':
                    return {'url': url}


Github = generate_wrapper_from_adapter(GithubClientAdapter)
Beispiel #34
0
from tapioca import TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin

from .resource_mapping import RESOURCE_MAPPING


class FifaApiClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    resource_mapping = RESOURCE_MAPPING

    def get_api_root(self, api_params, **kwargs):
        if api_params.get("mock"):
            return "http://www.mocky.io/v2/5cf825d8300000f7d4a38141"
        if api_params.get("qa"):
            return "https://api.qa.fifa.com/api/v1"
        return "https://api.fifa.com/api/v1"

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(FifaApiClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


FifaApiWrapper = generate_wrapper_from_adapter(FifaApiClientAdapter)
Beispiel #35
0
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = OAuth1(
            api_params.get('api_key'),
            client_secret=api_params.get('api_secret'),
            resource_owner_key=api_params.get('access_token', ''),
            resource_owner_secret=api_params.get('access_token_secret', ''))

        return params

    def get_iterator_list(self, response_data):
        if isinstance(response_data, list):
            return response_data

        if isinstance(response_data, dict) and 'statuses' in response_data:
            return response_data['statuses']

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        iterator_list = self.get_iterator_list(response_data)
        last_item = iterator_list[-1]
        if 'id' in last_item:
            if not 'params' in iterator_request_kwargs:
                iterator_request_kwargs['params'] = {}
            iterator_request_kwargs['params']['max_id'] = last_item['id']

            return iterator_request_kwargs


Twitter = generate_wrapper_from_adapter(TwitterClientAdapter)
# coding: utf-8

from tapioca import (
    TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin)
from requests.auth import HTTPBasicAuth


class AwesomebikesClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'http://localhost:8000/api/'
    resource_mapping = {'bikes': {'resource': 'bikes/'}}

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(AwesomebikesClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(
            api_params.get('user'), api_params.get('password'))

        return params

Awesomebikes = generate_wrapper_from_adapter(AwesomebikesClientAdapter)
        return obj

    def get_iterator_list(self, response_data):
        # items = []
        # assert isinstance(response_data, dict)
        # for k, v in response_data.iteritems():
        #     if isinstance(v, list):
        #         items.extend(v)
        # return items
        return response_data

    def response_to_native(self, response):
        native = super(BookingSyncClientAdapter, self).response_to_native(response)
        items = []
        assert isinstance(native, dict)
        for k, v in native.iteritems():
            if isinstance(v, list):
                items.extend(v)
        return items

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs, response_data, response):
        links = [m.groupdict() for m in self.re_links.finditer(response.headers['link'])]
        next_link = filter(lambda x: x.get('rel') == 'next', links)
        if not next_link:
            return
        else:
            return {'url': next_link[0]['link']}


BookingSync = generate_wrapper_from_adapter(BookingSyncClientAdapter)
Beispiel #38
0
        'resource': 'resource/{number}/',
        'docs': 'http://www.test.com/resource',
        'spam': 'eggs',
        'foo': 'bar'
    },
}


class TestClientAdapter(TapiocaAdapter):
    api_root = 'https://api.test.com'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params):
        return {}

    def get_iterator_list(self, response_data):
        return response_data['data']

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data):
        paging = response_data.get('paging')
        if not paging:
            return
        url = paging.get('next')

        if url:
            return {'url': url}


TestTapiocaClient = generate_wrapper_from_adapter(TestClientAdapter)
from requests.auth import HTTPBasicAuth


from .resource_mapping import RESOURCE_MAPPING


class MailgunClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.mailgun.net/v3/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(MailgunClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)


        params['auth'] = HTTPBasicAuth(
            api_params.get('user'), api_params.get('password'))


        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Mailgun = generate_wrapper_from_adapter(MailgunClientAdapter)
                      refresh_token=None,
                      *args,
                      **kwargs):
        kwargs['resource'] = self._resource
        return super(TapiocaBlinkTradeClientExecutor,
                     self)._make_request(request_method,
                                         refresh_token=refresh_token,
                                         *args,
                                         **kwargs)


class TapiocaBlinkTradeInstantiator(TapiocaInstantiator):
    def __call__(self, serializer_class=None, session=None, **kwargs):
        refresh_token_default = kwargs.pop('refresh_token_by_default', False)
        return TapiocaBlinkTradeClient(
            self.adapter_class(serializer_class=serializer_class),
            api_params=kwargs,
            refresh_token_by_default=refresh_token_default,
            session=session)


class BLinkTradePulbicAdapter(JSONAdapterMixin, TapiocaAdapter):
    resource_mapping = PUBLIC_RESOURCE_MAPPING

    def get_api_root(self, api_params):
        return '%s/api/v1/%s' % (api_params['api_url'], api_params['currency'])


BlinkTradePublic = generate_wrapper_from_adapter(BLinkTradePulbicAdapter)
BlinkTrade = TapiocaBlinkTradeInstantiator(BlinkTradeClientAdapter)
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(api_params.get('api_key'), '')

        return params

    def get_api_root(self, api_params, **kwargs):
        # stripe file creation specific endpoint
        if kwargs.get('resource_name') == 'files_create':
            return 'https://files.stripe.com/v1'

        return self.api_root

    def get_iterator_list(self, response_data):
        return response_data['data']

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        if response_data.get('has_more'):
            last_item_id = self.get_iterator_list(response_data)[-1]['id']

            if 'params' not in iterator_request_kwargs:
                iterator_request_kwargs['params'] = {}

            iterator_request_kwargs['params']['starting_after'] = last_item_id

            return iterator_request_kwargs


Stripe = generate_wrapper_from_adapter(StripeClientAdapter)
        if 'headers' not in params:
            params['headers'] = {}

        params['headers'].update({
            'X-Parse-Application-Id':
            api_params.get('application_id'),
            'X-Parse-REST-API-Key':
            api_params.get('rest_api_key')
        })

        return params

    def get_iterator_list(self, response_data):
        return response_data.get('results')

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        limit = 100
        params = iterator_request_kwargs.get('params', {
            'limit': limit,
            'skip': -limit
        })
        params['skip'] = params['limit'] + params['skip']
        iterator_request_kwargs['params'] = params

        return iterator_request_kwargs


Parse = generate_wrapper_from_adapter(ParseClientAdapter)
        )
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def response_to_native(self, response):
        native = super(BookingSyncClientAdapter, self).response_to_native(
            response
        )
        items = []
        if native is None:
            return items

        assert isinstance(native, dict)
        for k, v in native.items():
            if isinstance(v, list):
                items.extend(v)
        return items

    def get_iterator_next_request_kwargs(self,
                                         iterator_request_kwargs,
                                         response_data,
                                         response):
        next_link = response.links.get('next')
        if next_link and 'url' in next_link.keys():
            return {'url': next_link['url']}


BookingSync = generate_wrapper_from_adapter(BookingSyncClientAdapter)
from .resource_mapping import RESOURCE_MAPPING


class AmarilisV1ClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://pms.imoveisamarilis.com.br/api/v1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(AmarilisV1ClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)
        params['auth'] = HTTPBasicAuth(api_params.get('user'),
                                       api_params.get('password'))

        return params

    def get_api_root(self, api_params):
        custom_host = api_params.get('host', None)
        if custom_host:
            return custom_host
        return self.api_root

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


AmarilisV1 = generate_wrapper_from_adapter(AmarilisV1ClientAdapter)
# coding: utf-8

from tapioca import (TapiocaAdapter, generate_wrapper_from_adapter,
                     JSONAdapterMixin)

from .resource_mapping import RESOURCE_MAPPING


class TheMoviedbClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.themoviedb.org/3/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(TheMoviedbClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)
        params.setdefault('params', {}).update(
            {'api_key': api_params.get('api_key', '')})
        return params

    def get_iterator_list(self, response_data):
        return response_data['results']

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


TheMovieDB = generate_wrapper_from_adapter(TheMoviedbClientAdapter)
Beispiel #46
0
class BraspagClientAdapter(BraspagBaseClientAdapter):

    prod_url = 'https://api.braspag.com.br/'
    sandbox_url = 'https://apisandbox.braspag.com.br/'
    homolog_url = 'https://apihomolog.braspag.com.br/'


class BraspagConsultClientAdapter(BraspagBaseClientAdapter):

    prod_url = 'https://apiquery.braspag.com.br/'
    sandbox_url = 'https://apiquerysandbox.braspag.com.br/'
    homolog_url = 'https://apiqueryhomolog.braspag.com.br/'


BraspagConsult = generate_wrapper_from_adapter(BraspagConsultClientAdapter)
Braspag = generate_wrapper_from_adapter(BraspagClientAdapter)


class TapiocaBraspagInstantiator(TapiocaInstantiator):
    def __call__(self, merchant_id=None, merchant_key=None, *args, **kwargs):
        if not 'headers' in kwargs:
            kwargs['headers'] = {
                "Content-Type": "application/json",
                "MerchantId": merchant_id,
                "MerchantKey": merchant_key,
                "ResponseId": None,
            }

        return super(TapiocaBraspagInstantiator,
                     self).__call__(*args, **kwargs)
        params = super(TwitterClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth1(api_params.get('api_key'),
                client_secret=api_params.get('api_secret'),
                resource_owner_key=api_params.get('access_token', ''),
                resource_owner_secret=api_params.get('access_token_secret', ''))

        return params

    def get_iterator_list(self, response_data):
        if isinstance(response_data, list):
            return response_data

        if isinstance(response_data, dict) and 'statuses' in response_data:
            return response_data['statuses']

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data, response):
        iterator_list = self.get_iterator_list(response_data)
        last_item = iterator_list[-1]
        if 'id' in last_item:
            if not 'params' in iterator_request_kwargs:
                iterator_request_kwargs['params'] = {}
            iterator_request_kwargs['params']['max_id'] = last_item['id']

            return iterator_request_kwargs


Twitter = generate_wrapper_from_adapter(TwitterClientAdapter)
# coding: utf-8

from tapioca import (TapiocaAdapter, generate_wrapper_from_adapter,
                     JSONAdapterMixin)
from requests.auth import HTTPBasicAuth


class AwesomebikesClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'http://localhost:8000/api/'
    resource_mapping = {'bikes': {'resource': 'bikes/'}}

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(AwesomebikesClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(api_params.get('user'),
                                       api_params.get('password'))

        return params


Awesomebikes = generate_wrapper_from_adapter(AwesomebikesClientAdapter)
Beispiel #49
0
from __future__ import unicode_literals

from tapioca import (TapiocaAdapter, generate_wrapper_from_adapter,
                     JSONAdapterMixin)

from .resources import RESOURCE_MAPPING
from .auth import RocketAuth


class RocketChatClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(RocketChatClientAdapter,
                       self).get_request_kwargs(api_params, *args, **kwargs)

        params['auth'] = RocketAuth(api_params.get('host'),
                                    api_params.get('username'),
                                    api_params.get('password'),
                                    api_params.get('token'),
                                    api_params.get('user_id'))

        return params

    def get_api_root(self, api_params):
        return '{}/api'.format(api_params.get('host', 'http://localhost'))


RocketChat = generate_wrapper_from_adapter(RocketChatClientAdapter)
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(HarvestClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = HTTPBasicAuth(
            api_params.get('user'), api_params.get('password'))

        params['headers'] = params.get('headers', {})
        params['headers']['Accept'] = 'application/json'

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def response_to_native(self, response):
        if response.content.strip():
            return super(HarvestClientAdapter, self).response_to_native(response)

    def get_api_root(self, api_params):
        return 'https://' + api_params['company_name'] + '.harvestapp.com/'


Harvest = generate_wrapper_from_adapter(HarvestClientAdapter)
class SpotifyClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.spotify.com/v1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(SpotifyClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id', ''), token={
                'access_token': self.auth(api_params.get('client_id'), api_params.get('client_secret')),
                'token_type': 'Bearer'})
        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass

    def auth(self, client_id, client_secret):
        global access_token
        if not access_token:
            scope = ['playlist-modify-public']
            access_token = spotify_auth(client_id, client_secret, scope)
        return access_token

Spotify = generate_wrapper_from_adapter(SpotifyClientAdapter)
Spotify.info = spotifyinfo
from tapioca import (
    TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin)

from .resource_mapping import RESOURCE_MAPPING


class MeetupClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.meetup.com'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(MeetupClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        try:
            params['params'].update({'key': api_params.get('key')})
        except KeyError:
            params['params'] = {'key': api_params.get('key')}

        return params

    def get_iterator_list(self, response_data):
        return response_data

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        pass


Meetup = generate_wrapper_from_adapter(MeetupClientAdapter)
class FacebookClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://graph.facebook.com/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(FacebookClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)

        params['auth'] = OAuth2(
            api_params.get('client_id'), token={
            'access_token': api_params.get('access_token'),
            'token_type': 'Bearer'})

        return params

    def get_iterator_list(self, response_data):
        return response_data['data']

    def get_iterator_next_request_kwargs(self,
            iterator_request_kwargs, response_data, response):
        paging = response_data.get('paging')
        if not paging:
            return
        url = paging.get('next')

        if url:
            return {'url': url}


Facebook = generate_wrapper_from_adapter(FacebookClientAdapter)
from .resource_mapping import RESOURCE_MAPPING


class InstagramClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.instagram.com/v1/'
    resource_mapping = RESOURCE_MAPPING

    def get_request_kwargs(self, api_params, *args, **kwargs):
        params = super(InstagramClientAdapter, self).get_request_kwargs(
            api_params, *args, **kwargs)
        params.setdefault('params', {}).update(
            {'access_token': api_params.get('access_token', '')}
        )
        return params

    def get_iterator_list(self, response_data):
        return response_data['data']

    def get_iterator_next_request_kwargs(self, iterator_request_kwargs,
                                         response_data, response):
        paging = response_data.get('pagination')
        if not paging:
            return
        url = paging.get('next_url')
        if url:
            return {'url': url}


Instagram = generate_wrapper_from_adapter(InstagramClientAdapter)