def post(self):
     data = request.get_json()
     try:
         validate = Utilities.validateStructureJson(
             data, CompanyCreateResource.required_company_create)
         if not validate["error"]:
             company_exists = Company.get_data_by_identification(
                 data["identification"])
             if company_exists is None:
                 insert_company = Company.insert_data(data)
                 if insert_company:
                     return Utilities.response_services(
                         True, 201, "Company successfully inserted",
                         insert_company)
                 else:
                     return Utilities.response_services(
                         False, 500,
                         "An error occurred while inserting the company")
             else:
                 return Utilities.response_services(
                     False, 400,
                     "There is already a company with the identification sent"
                 )
         else:
             return Utilities.response_services(False, 400,
                                                validate["message"])
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred", None)
 def get(self):
     data_companies = Company.get_all()
     if data_companies:
         return Utilities.response_services(True, 200, "Successful action",
                                            data_companies)
     else:
         return Utilities.response_services(False, 404,
                                            "There are no companies")
Ejemplo n.º 3
0
def verificacion():
    if request.method != 'OPTIONS' and request.endpoint != "welcome":
        if request.headers.get('Authorization'):
            if not Utilities.isTokenIntegration(
                    request.headers.get('Authorization')):
                return Utilities.response_services(False, 403, "Access denied")
        else:
            return Utilities.response_services(
                False, 403, "Access denied, send authorization")
 def delete(self, _id):
     company_exists = Company.get_data(_id)
     if company_exists is None:
         return Utilities.response_services(False, 404,
                                            "The company not found")
     else:
         delete_company = Company.delete_data(_id)
         if delete_company is not None:
             return Utilities.response_services(
                 True, 202, "Company successfully eliminated")
         else:
             return Utilities.response_services(
                 True, 500, "An error occurred while deleting the company")
Ejemplo n.º 5
0
    def post(self):
        try:
            payload = Utilities.get_json_create_delivery()
            url = app_config[enviroment].URLS_ENVIAME["create_delivery"]
            print(url)
            headers = {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'api-key': 'ea670047974b650bbcba5dd759baf1ed'
            }
            data_inser_log = {
                'name': 'create_delivery',
                'status': 0,
                'payload': json.dumps({
                    'headers': headers,
                    'payload': payload
                })
            }
            data_insert = LogsEnviame.insert_data(data_inser_log)
            r = requests.post(url, data=json.dumps(payload), headers=headers)
            if r.status_code == 201:
                rs = json.loads(r.text)
                data_update_log = {'response': json.dumps(rs), 'status': 1}
                data_update = LogsEnviame.update_data(data_insert['id'],
                                                      data_update_log)
                return Utilities.response_services(
                    True, 201, "Delivery created successfully", data_update)
            else:
                rs = json.loads(r.text)
                data_update_log = {'response': json.dumps(rs), 'status': 2}
                data_update = LogsEnviame.update_data(data_insert['id'],
                                                      data_update_log)
                return Utilities.response_services(
                    False, 500,
                    "An error occurred while inserting the delivery")

        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            msj = 'Error: ' + str(
                exc_obj) + ' File: ' + fname + ' linea: ' + str(
                    exc_tb.tb_lineno)
            print(str(msj))
            return Utilities.response_services(
                False, 500, "An unexpected error has occurred")
Ejemplo n.º 6
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('km', type=int, required=False)
     params = parser.parse_args()
     try:
         km = randint(0, 2000) if params["km"] is None else params["km"]
         days = Utilities.fibonacciDelivery(km)
         message = "time for delivery for a distance of " + str(
             km) + " km is " + str(days) + " days"
         return Utilities.response_services(True, 200, message)
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred")
 def get(self, _id):
     try:
         data_company = Company.get_data(_id)
         if data_company:
             return Utilities.response_services(True, 200,
                                                "Successful action",
                                                data_company)
         else:
             return Utilities.response_services(False, 404,
                                                "Company not found")
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' line: ' + str(
                 exc_tb.tb_lineno)
         print(msj)
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred", None)
Ejemplo n.º 8
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('quantity',
                         type=int,
                         required=True,
                         help="You must indicate an quantity")
     params = parser.parse_args()
     try:
         fake = Faker()
         data_response = []
         error_response = []
         for item in range(params["quantity"]):
             data = {
                 "identification": fake.bothify(text='#########'),
                 "name": fake.company(),
                 "address": fake.address(),
                 "status": 1,
                 "phone": fake.bothify(text='2########'),
                 "mail": fake.company_email()
             }
             data_company = Company.insert_data(data)
             if data_company is not None:
                 data_response.append(data_company)
             else:
                 error_response.append(data)
         if len(error_response) == 0:
             return Utilities.response_services(
                 True, 201, "Companies successfully inserted",
                 data_response)
         else:
             return Utilities.response_services(True, 201,
                                                "Some inserts with errors")
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred")
Ejemplo n.º 9
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('divisors', type=int, required=False)
     params = parser.parse_args()
     try:
         limit_divisors = 1000 if params["divisors"] is None else params[
             "divisors"]
         return Utilities.response_services(
             True, 200,
             "The first number in the fibonacci sequence with more than " +
             str(limit_divisors) + " divisors is : " +
             str(Utilities.fibonacciDivisors(limit_divisors)))
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred")
Ejemplo n.º 10
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('string', type=str, required=False)
     params = parser.parse_args()
     try:
         string = "afoolishconsistencyisthehobgoblinoflittlemindsadoredbylittlestatesmenandphilosophersanddivineswithconsistencyagreatsoulhassimplynothingtodohemayaswellconcernhimselfwithhisshadowonthewallspeakwhatyouthinknowinhardwordsandtomorrowspeakwhattomorrowthinksinhardwordsagainthoughitcontradicteverythingyousaidtodayahsoyoushallbesuretobemisunderstoodisitsobadthentobemisunderstoodpythagoraswasmisunderstoodandsocratesandjesusandlutherandcopernicusandgalileoandnewtonandeverypureandwisespiritthatevertookfleshtobegreatistobemisunderstood" if params[
             "string"] is None else params["string"]
         return Utilities.getPalindromesFromString(string)
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         msj = 'Error: ' + str(
             exc_obj) + ' File: ' + fname + ' linea: ' + str(
                 exc_tb.tb_lineno)
         print(str(msj))
         return Utilities.response_services(
             False, 500, "An unexpected error has occurred")