Exemplo n.º 1
0
    def patch(self, transaction_uuid):
        '''
            Modify transaction
        '''
        logging.info('request.arguments {0}'.format(self.request.arguments))
        logging.info('request.body {0}'.format(self.request.body))

        struct = yield check_json(self.request.body)

        logging.info('patch received struct {0}'.format(struct))

        format_pass = (True
                       if not dict(struct).get('errors', False) else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON': format_pass})
            return

        account = self.request.arguments.get('account', [None])[0]

        logging.info('account {0} uuid {1} struct {2}'.format(
            account, transaction_uuid, struct))

        result = yield self.modify_transaction(account, transaction_uuid,
                                               struct)

        if not result:
            self.set_status(400)
            system_error = errors.Error('missing')
            error = system_error.missing('transaction', transaction_uuid)
            self.finish(error)
            return

        self.set_status(200)
        self.finish({'message': 'update completed successfully'})
Exemplo n.º 2
0
    def post(self):
        '''
            Create company
        '''
        struct = yield check_json(self.request.body)
        
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        struct['account_type'] = 'user'

        logging.info('new company structure %s' % str(struct))

        result = yield self.new_company(struct)

        if 'error' in result:
            model = 'User'
            reason = {'duplicates': [(model, 'account'), (model, 'email')]}

            message = yield self.let_it_crash(struct, model, result, reason)

            logging.warning(message)

            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish({'uuid':result})
Exemplo n.º 3
0
    def post(self):
        '''
            Create company
        '''
        struct = yield check_json(self.request.body)

        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON': format_pass})
            return

        struct['account_type'] = 'user'

        logging.info('new company structure %s' % str(struct))

        result = yield self.new_company(struct)

        if 'error' in result:
            model = 'User'
            reason = {'duplicates': [(model, 'account'), (model, 'email')]}

            message = yield self.let_it_crash(struct, model, result, reason)

            logging.warning(message)

            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish({'uuid': result})
Exemplo n.º 4
0
    def post(self):
        '''
            New payment
        '''
        # post structure
        struct = yield check_json(self.request.body)

        # format pass ().
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON': format_pass})
            return

        # settings database
        db = self.settings.get('db')

        # logging new contact structure
        logging.info('new payment structure {0}'.format(str(struct)))

        # logging request query arguments
        logging.info(self.request.arguments)

        # request query arguments
        query_args = self.request.arguments

        # get account from new contact struct
        account = struct.get('account', None)

        # get the current frontend logged username
        username = self.get_current_username()

        # if the user don't provide an account we use the frontend username as last resort
        account = (query_args.get('account', [username])[0]
                   if not account else account)

        # we use the front-end username as last resort
        if not struct.get('account'):
            struct['account'] = account

        new_payment = yield self.new_payment(struct)

        # TODO: a little work on error stuff on cuallix API services.

        if 'error' in new_payment:
            scheme = 'payment'
            reason = {
                'duplicates': [(scheme, 'account'), (scheme, 'phone_number')]
            }
            message = yield self.let_it_crash(struct, scheme, new_payment,
                                              reason)

            logging.warning(message)
            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish({'uuid': new_payment})
Exemplo n.º 5
0
    def post(self):
        '''
            New payment
        '''
        # post structure
        struct = yield check_json(self.request.body)

        # format pass ().
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        # settings database
        db = self.settings.get('db')

        # logging new contact structure
        logging.info('new payment structure {0}'.format(str(struct)))

        # logging request query arguments
        logging.info(self.request.arguments)

        # request query arguments
        query_args = self.request.arguments

        # get account from new contact struct
        account = struct.get('account', None)

        # get the current frontend logged username
        username = self.get_current_username()

        # if the user don't provide an account we use the frontend username as last resort
        account = (query_args.get('account', [username])[0] if not account else account)

        # we use the front-end username as last resort
        if not struct.get('account'):
            struct['account'] = account

        new_payment = yield self.new_payment(struct)

        # TODO: a little work on error stuff on cuallix API services.

        if 'error' in new_payment:
            scheme = 'payment'
            reason = {'duplicates': [
                (scheme, 'account'),
                (scheme, 'phone_number')
            ]}
            message = yield self.let_it_crash(struct, scheme, new_payment, reason)

            logging.warning(message)
            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish({'uuid':new_payment})
Exemplo n.º 6
0
    def post(self):
        '''
            Load Funds
        '''
        # post structure
        struct = yield check_json(self.request.body)

        # format pass ().
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON': format_pass})
            return

        # logging new structure
        logging.info('cuallix load funds structure {0}'.format(str(struct)))

        # logging request query arguments
        logging.info('logging request query arguments... {0}'.format(
            str(self.request.arguments)))

        # request query arguments
        query_args = self.request.arguments

        # get account from new struct
        account = struct.get('account', None)

        # get the current frontend logged username
        username = self.get_current_username()

        # if the user don't provide an account we use the frontend username as last resort
        account = (query_args.get('account', [username])[0]
                   if not account else account)

        # execute the method function stuff
        load_funds = yield self.load_funds(struct)

        # TODO: a little work on error stuff on cuallix API services.

        if 'error' in load_funds:
            scheme = 'payment'
            reason = {
                'duplicates': [(scheme, 'account'), (scheme, 'phone_number')]
            }
            message = yield self.let_it_crash(struct, scheme, load_funds,
                                              reason)

            logging.warning(message)
            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish(load_funds)
Exemplo n.º 7
0
    def post(self):
        '''
            Cuallix Report Transactions
        '''
        # post structure
        struct = yield check_json(self.request.body)

        # format pass ().
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON': format_pass})
            return

        # logging new structure
        logging.info('cuallix report transactions structure {0}'.format(
            str(struct)))

        # logging request query arguments
        logging.info('logging request query arguments... {0}'.format(
            str(self.request.arguments)))

        # request query arguments
        query_args = self.request.arguments

        # get account from new struct
        account = struct.get('account', None)

        # execute the method function stuff
        report_transactions = yield self.report_transactions(struct)

        # TODO: a little work on error stuff on cuallix API services.

        if 'error' in report_transactions:
            scheme = 'payment'
            reason = {
                'duplicates': [(scheme, 'account'), (scheme, 'phone_number')]
            }
            message = yield self.let_it_crash(struct, scheme,
                                              report_transactions, reason)

            logging.warning(message)
            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish(report_transactions)
Exemplo n.º 8
0
    def post(self):
        '''
            Search Customer
        '''
        # post structure
        struct = yield check_json(self.request.body)

        # format pass ().
        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON': format_pass})
            return

        # logging new structure
        logging.info('cuallix search customer structure {0}'.format(
            str(struct)))

        # logging request query arguments
        logging.info('logging request query arguments... {0}'.format(
            str(self.request.arguments)))

        # request query arguments
        query_args = self.request.arguments

        # get account from new struct
        account = struct.get('account', None)

        # execute user register function
        get_token = yield self.search_customer(struct)

        # TODO: more work on error stuff on cuallix API services.
        if 'error' in get_token:
            scheme = 'contact'  # ???
            reason = {
                'duplicates': [(scheme, 'account'), (scheme, 'phone_number')]
            }
            message = yield self.let_it_crash(struct, scheme, get_token,
                                              reason)

            logging.warning(message)
            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish(get_token)
Exemplo n.º 9
0
    def patch(self, account):
        '''
            Update company
        '''

        logging.info('request.arguments {0}'.format(self.request.arguments))
        logging.info('request.body {0}'.format(self.request.body))

        struct = yield check_json(self.result.body)

        logging.info('patch received struct {0}'.format(struct))

        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        struct['account_type'] = 'user'

        logging.info('new update on company structure %s' % str(struct))

        result = yield self.modify_company(account, struct)

        if 'error' in result:
            model = 'User'
            reason = {'duplicates': [(model, 'account'), (model, 'email')]}

            message = yield self.let_it_crash(struct, model, result, reason)

            logging.warning(message)

            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish({'uuid':result})
Exemplo n.º 10
0
    def patch(self, account):
        '''
            Update company
        '''

        logging.info('request.arguments {0}'.format(self.request.arguments))
        logging.info('request.body {0}'.format(self.request.body))

        struct = yield check_json(self.result.body)

        logging.info('patch received struct {0}'.format(struct))

        format_pass = (True if struct else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON': format_pass})
            return

        struct['account_type'] = 'user'

        logging.info('new update on company structure %s' % str(struct))

        result = yield self.modify_company(account, struct)

        if 'error' in result:
            model = 'User'
            reason = {'duplicates': [(model, 'account'), (model, 'email')]}

            message = yield self.let_it_crash(struct, model, result, reason)

            logging.warning(message)

            self.set_status(400)
            self.finish(message)
            return

        self.set_status(201)
        self.finish({'uuid': result})
Exemplo n.º 11
0
    def post(self):
        '''
            Upload content
        '''
        # post structure
        struct = yield check_json(self.request.body)

        # format pass ()
        format_pass = (True if struct else False)
        if not format_pass and not self.request.files:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        logging.info('new random file received')

        # logging request query arguments
        logging.info(self.request.arguments)

        # request query arguments
        query_args = self.request.arguments

        # get the current frontend logged username
        username = self.get_current_username()

        # if the user don't provide an account we use the frontend username as last resort
        account = query_args.get('account', [username])[0]

        if self.request.files:
            filedata = self.request.files['filearg'][0]
            fname = filedata['filename']
            extn = os.path.splitext(fname)[1]
            cname = str(uuid.uuid4()) + extn
            fh = open(__UPLOADS__ + cname, 'w')
            fh.write(filedata['body'])

            message = {'message':cname + " is uploaded!! Check %s folder" %__UPLOADS__}
        else:
            #logging.info(struct)

            logging.info('lol todo bien')
            
            filedata = struct.get('filearg', None)

            cname = str(uuid.uuid4()) + '.csv'

            if filedata:
                logging.info("there's something here")
                
                fh = open(__UPLOADS__ + cname, 'w')
                
                data = filedata.split(",")[1]
                
                data = base64.b64decode(data)

                if data:
                    fh.write(data)
                else:
                    print 'shit..'

                #import csv

                #with open('eggs.csv', 'rb') as csvfile:
                #    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
                #    for row in spamreader:
                #        print ', '.join(row)
                print "hmmm, let's check this shit out"
            else:
                logging.warning('how are we handle this file?')
            
        self.finish({'ki':'ka'})