def create_or_fetch(cls, name, age, gender): url = URL.persons r = requests.post(url, data=dict(name=name, age=age, gender=gender)) print(r) json_resp = r.json() Print.json(json_resp) person = cls(**json_resp) if r.status_code == 201: Print.api("Created New Person: {})".format(person)) elif r.status_code == 200: Print.api("Fetched Existing Person: {}".format(person)) return person
def create(cls): url = URL.sessions payload = dict( person=sys_manager.person.id, ch_names=ch_names, is_real_data=sys_manager.is_real_data ) r = requests.post(url, data=payload) json_resp = r.json() obj = cls(**json_resp) if r.status_code == 201: Print.api("Created New Session ({})".format(obj.id)) else: Print.failure("Something went wrong") return obj