Esempio n. 1
0
    def auth(self, account_type, login=None, username=None, password=None, pin=None, options=None, patch=False):
        """
        Add a bank account user/login to Plaid and receive an access token
        unless a 2nd level of authentication is required, in which case
        an MFA (Multi Factor Authentication) question(s) is returned

        `account_type`  str     The type of bank account you want to sign in
                                to, must be one of the keys in `ACCOUNT_TYPES`
        `username`      str     The username for the bank account you want to
                                sign in to
        `password`      str     The password for the bank account you want to
                                sign in to
        `options`       dict
            `webhook`   str         URL to hit once the account's transactions
                                    have been processed
            `mfa_list`  boolean     List all available MFA (Multi Factor
                                    Authentication) options
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['auth'])

        if not login:
            credentials = {
                'username': username,
                'password': password
            }
        else:
            credentials = login

        if pin:
            credentials['pin'] = pin

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'type': account_type,
            'credentials': json.dumps(credentials)
        }

        if options:
            data['options'] = json.dumps(options)

        if patch:
            data['access_token'] = self.access_token
            response = http_request(url, 'PATCH', data)
        else:
            response = http_request(url, 'POST', data)

        if response.ok:
            json_data = json.loads(response.content)
            if json_data.has_key('access_token'):
                self.access_token = json_data['access_token']

        return response
Esempio n. 2
0
    def auth_step(self, account_type, mfa, options=None):
        """
        Perform a MFA (Multi Factor Authentication) step, requires
        `access_token`

        `account_type`  str     The type of bank account you're performing MFA
                                on, must match what you used in the `connect`
                                call
        `mfa`           str     The MFA answer, e.g. an answer to q security
                                question or code sent to your phone, etc.
        `options`       dict
            `send_method`   dict    The send method your MFA answer is for,
                                    e.g. {'type': Phone'}, should come from
                                    the list from the `mfa_list` option in
                                    the `connect` call
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['auth_step'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'type': account_type,
            'mfa': mfa
        }

        if options:
            data['options'] = json.dumps(options)

        return http_request(url, 'POST', data)
Esempio n. 3
0
    def auth_step(self, account_type, mfa, options=None):
        """
        Perform a MFA (Multi Factor Authentication) step, requires
        `access_token`

        `account_type`  str     The type of bank account you're performing MFA
                                on, must match what you used in the `connect`
                                call
        `mfa`           str     The MFA answer, e.g. an answer to q security
                                question or code sent to your phone, etc.
        `options`       dict
            `send_method`   dict    The send method your MFA answer is for,
                                    e.g. {'type': Phone'}, should come from
                                    the list from the `mfa_list` option in
                                    the `connect` call
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['auth_step'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'type': account_type,
            'mfa': mfa
        }

        if options:
            data['options'] = json.dumps(options)

        return http_request(url, 'POST', data)
Esempio n. 4
0
    def categories_by_mapping(self, mapping, category_type, options=None):
        """
        Fetch category data by category mapping and data source

        `mapping`       str     The category mapping to explore,
                                e.g. "Food > Spanish Restaurant",
                                see all categories here:
                                https://github.com/plaid/Support/blob/master/categories.md
        `category_type` str     The category data source, must be a value from
                                `CATEGORY_TYPES`
        `options`       dict
            `full_match`    boolean     Whether to try an exact match for
                                        `mapping`. Setting to `False` will
                                        return best match.
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['categories_by_mapping'])
        data = {
            'mapping': mapping,
            'type': category_type
        }
        if options:
            data['options'] = json.dumps(options)
        return http_request(url, 'GET', data)
Esempio n. 5
0
 def request_followers(self, path, post_args=None, log_request=False, **kwargs):
     """Requesting followers does not need consumer key
     """
     if post_args:
         raise NotImplementedError
     base_url = FiveHundredPx.BASE_URL
     return http_request(base_url, path, post_args, log_request, **kwargs) 
Esempio n. 6
0
    def category(self, category_id, options=None):
        """
        Fetch a specific category

        `category_id`   str     Category id to fetch
        """
        url = urljoin(self.url, self.endpoints['category']) % category_id
        return http_request(url, 'GET')
Esempio n. 7
0
    def entity(self, entity_id, options=None):
        """
        Fetch a specific entity's data

        `entity_id`     str     Entity id to fetch
        """
        url = urljoin(self.url, self.endpoints['entity'])
        return http_request(url, 'GET', {'entity_id': entity_id})
Esempio n. 8
0
    def entity(self, entity_id, options=None):
        """
        Fetch a specific entity's data

        `entity_id`     str     Entity id to fetch
        """
        url = urljoin(self.url, self.endpoints['entity'])
        return http_request(url, 'GET', {'entity_id': entity_id})
Esempio n. 9
0
    def category(self, category_id, options=None):
        """
        Fetch a specific category

        `category_id`   str     Category id to fetch
        """
        url = urljoin(self.url, self.endpoints['category']) % category_id
        return http_request(url, 'GET')
Esempio n. 10
0
 def request(self, path, post_args=None, log_request=False, **kwargs):
     """Handles the actual request to 500px. Posting has yet 
     to be implemented.
     """
     if post_args:
         raise NotImplementedError
     self._set_consumer_key_to_args_(post_args, kwargs)
     base_url = FiveHundredPx.BASE_URL
     return http_request(base_url, path, post_args, log_request, **kwargs) 
Esempio n. 11
0
 def request(self, path, post_args=None, log_request=False, **kwargs):
     """Handles the actual request to 500px. Posting has yet 
     to be implemented.
     """
     if post_args:
         raise NotImplementedError
     self._set_consumer_key_to_args_(post_args, kwargs)
     base_url = FiveHundredPx.BASE_URL
     return http_request(base_url, path, post_args, log_request, **kwargs)
Esempio n. 12
0
def main():
	if http_request() == 1:
		send_to_syslog("The server responds to HTTP requests on localhost in more than 100ms")
		send_email("The server responds to HTTP requests on localhost in more than 100ms")
	if tty_session() == 1:
		send_to_syslog("There are user(s) with tty session(s) logged into the server")	
		send_email("There are user(s) with tty session(s) logged into the server")
	if disk_usage() == 1:
		send_to_syslog("Disk usage on the root volume is more than 90%")
		send_email("Disk usage on the root volume is more than 90%")
Esempio n. 13
0
    def transactions(self, options=None):
        """
        Fetch a list of transactions, requires `access_token`
        !!! DOES NOT USE as_dictionary decorator due to sketchy sandbox handling code

        `options`   dict
        """
        url = urljoin(self.url, self.endpoints['transactions'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
        }

        if options and not self.sandboxed():
            # Options not supported in sandbox mode - handle manually below
            data['options'] = json.dumps(options)

        # Make the request and raise exception if it's f****d up
        transactions_request = http_request(url, 'POST', data)
        if transactions_request.ok:
            json_response = json.loads(transactions_request.content)
        else:
            build_api_error(transactions_request)

        if self.sandboxed():
            # We have to manually apply the specified options
            filtered_transactions = []
            transactions = json_response['transactions']

            # Possible options:
            # 1) filter by account_id ('account')
            check_account = 'account' in options

            # 2) filter by date greater than or equal to a given date ('gte')
            check_date = 'gte' in options

            correct_account = True
            correct_date = True
            for transaction in transactions:
                if check_account:
                    correct_account = transaction['_account'] == options['account']
                if check_date:
                    transaction_date = datetime.strptime(transaction['date'], "%Y-%m-%d").date()
                    threshold_date = datetime.strptime(options['gte'], "%Y-%m-%d").date()
                    correct_date = transaction_date >= threshold_date

                if correct_date and correct_account:
                    filtered_transactions.append(transaction)

            json_response['transactions'] = filtered_transactions

        return json_response
Esempio n. 14
0
    def connect_step(self, mfa, account_type=None, options=None, patch=False):
        """
        Perform a MFA (Multi Factor Authentication) step, requires
        `access_token`

        `account_type`  str     The type of bank account you're performing MFA
                                on, must match what you used in the `connect`
                                call
        `mfa`           str     The MFA answer, e.g. an answer to q security
                                question or code sent to your phone, etc.
        `options`       dict
            `send_method`   dict    The send method your MFA answer is for,
                                    e.g. {'type': Phone'}, should come from
                                    the list from the `mfa_list` option in
                                    the `connect` call
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['connect_step'])

        # Handle dictionary/list MFAs
        if isinstance(mfa, dict) or (isinstance(mfa, list) and not isinstance(mfa, basestring)):
            mfa = json.dumps(mfa)

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'type': account_type,
            'mfa': mfa
        }

        if options:
            data['options'] = json.dumps(options)

        if patch:
            return http_request(url, 'PATCH', data)
        else:
            return http_request(url, 'POST', data)
Esempio n. 15
0
    def numbers(self):
        """
        Fetch the account/routing numbers for this user

        """
        url = urljoin(self.url, self.endpoints['numbers'])
        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token
        }

        return http_request(url, 'POST', data)
Esempio n. 16
0
    def numbers(self):
        """
        Fetch the account/routing numbers for this user

        """
        url = urljoin(self.url, self.endpoints['numbers'])
        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token
        }

        return http_request(url, 'POST', data)
Esempio n. 17
0
    def delete_user(self):
        """
        Delete user from Plaid, requires `access_token`
        """
        url = urljoin(self.url, self.endpoints['connect'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token
        }

        return http_request(url, 'DELETE', data)
Esempio n. 18
0
    def delete_user(self):
        """
        Delete user from Plaid, requires `access_token`
        """
        url = urljoin(self.url, self.endpoints['connect'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token
        }

        return http_request(url, 'DELETE', data)
Esempio n. 19
0
    def get_info(self, account_type=None):
        """
        Fetch info about account holder

        """
        url = urljoin(self.url, self.endpoints['get_info'])
        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'type': account_type
        }

        return http_request(url, 'POST', data)
Esempio n. 20
0
    def upgrade(self, upgrade_to):
        """
        Upgrade account to another plaid type

        """
        url = urljoin(self.url, self.endpoints['upgrade'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'upgrade_to': upgrade_to
        }

        return http_request(url, 'POST', data)
Esempio n. 21
0
    def upgrade(self, upgrade_to):
        """
        Upgrade account to another plaid type

        """
        url = urljoin(self.url, self.endpoints['upgrade'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'upgrade_to': upgrade_to
        }

        return http_request(url, 'POST', data)
Esempio n. 22
0
    def balance(self, options=None):
        """
        Fetch the real-time balance of the user's accounts

        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['balance'])
        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token
        }
        if options:
            data['options'] = json.dumps(options)

        return http_request(url, 'GET', data)
Esempio n. 23
0
    def balance(self, options=None):
        """
        Fetch the real-time balance of the user's accounts

        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['balance'])
        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token
        }
        if options:
            data['options'] = json.dumps(options)

        return http_request(url, 'GET', data)
Esempio n. 24
0
    def connect(self, account_type, username, password, email, options=None):
        """
        Add a bank account user/login to Plaid and receive an access token
        unless a 2nd level of authentication is required, in which case
        an MFA (Multi Factor Authentication) question(s) is returned

        `account_type`  str     The type of bank account you want to sign in
                                to, must be one of the keys in `ACCOUNT_TYPES`
        `username`      str     The username for the bank account you want to
                                sign in to
        `password`      str     The password for the bank account you want to
                                sign in to
        `email`         str     The email address associated with the bank
                                account
        `options`       dict
            `webhook`   str         URL to hit once the account's transactions
                                    have been processed
            `mfa_list`  boolean     List all available MFA (Multi Factor
                                    Authentication) options
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['connect'])

        credentials = {'username': username, 'password': password}

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'type': account_type,
            'credentials': json.dumps(credentials),
            'email': email
        }

        if options:
            data['options'] = json.dumps(options)

        response = http_request(url, 'POST', data)

        if response.ok:
            json_data = json.loads(response.content)
            if json_data.has_key('access_token'):
                self.access_token = json_data['access_token']

        return response
Esempio n. 25
0
    def search_institutions(self, query=None, product=None, institution_id=None):
        """
        Search the available institutions (incl. intuit)
        """
        url = urljoin(self.url, self.endpoints['search_institutions'])
        data = {}

        if query:
            data['q'] = str(query)
        if product:
            data['p'] = str(product)
        if institution_id:
            data['id'] = str(institution_id)

        params = urlencode(data)
        url = url + '?' + params

        return http_request(url, 'GET')
Esempio n. 26
0
    def categories_by_mapping(self, mapping, category_type, options=None):
        """
        Fetch category data by category mapping and data source

        `mapping`       str     The category mapping to explore,
                                e.g. "Food > Spanish Restaurant",
                                see all categories here:
                                https://github.com/plaid/Support/blob/master/categories.md
        `category_type` str     The category data source, must be a value from
                                `CATEGORY_TYPES`
        `options`       dict
            `full_match`    boolean     Whether to try an exact match for
                                        `mapping`. Setting to `False` will
                                        return best match.
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['categories_by_mapping'])
        data = {'mapping': mapping, 'type': category_type}
        if options:
            data['options'] = json.dumps(options)
        return http_request(url, 'GET', data)
Esempio n. 27
0
    def transactions(self, options=None):
        """
        Fetch a list of transactions, requires `access_token`

        `options`   dict
            `last`      str         Collect all transactions since this
                                    transaction ID
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['connect'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'options': json.dumps(options)
        }

        if options:
            data['options'] = json.dumps(options)

        return http_request(url, 'GET', data)
Esempio n. 28
0
    def transactions(self, options=None):
        """
        Fetch a list of transactions, requires `access_token`

        `options`   dict
            `last`      str         Collect all transactions since this
                                    transaction ID
        """
        if options is None:
            options = {}
        url = urljoin(self.url, self.endpoints['connect'])

        data = {
            'client_id': self.client_id,
            'secret': self.secret,
            'access_token': self.access_token,
            'options': json.dumps(options)
        }

        if options:
            data['options'] = json.dumps(options)

        return http_request(url, 'GET', data)
Esempio n. 29
0
 def categories(self):
     """
     Fetch all categories
     """
     url = urljoin(self.url, self.endpoints['categories'])
     return http_request(url, 'GET')
Esempio n. 30
0
 def institutions(self):
     """
     Fetch the available institutions
     """
     url = urljoin(self.url, self.endpoints['institutions'])
     return http_request(url, 'GET')
Esempio n. 31
0
 def institutions(self):
     """
     Fetch the available institutions
     """
     url = urljoin(self.url, self.endpoints['institutions'])
     return http_request(url, 'GET')
Esempio n. 32
0
 def institution(self, institution_id):
     """
     Get institution by id
     """
     url = urljoin(self.url, self.endpoints['institutions'] + '/' + institution_id)
     return http_request(url, 'GET')
Esempio n. 33
0
 def categories(self):
     """
     Fetch all categories
     """
     url = urljoin(self.url, self.endpoints['categories'])
     return http_request(url, 'GET')
Esempio n. 34
0
def http_handle(request_string):
    request  = http_request(request_string)
    filepath, arg = http_urls(request)
    response = http_response(filepath, arg)
    return response