Esempio n. 1
0
    def do_PUT(self):
        
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)
        success = False
        # Delete a single animal from the list
        if resource == "animals":
            update_animal(id, post_body)
        if resource == "customers":
            update_customer(id, post_body)
        if resource == "employees":
            update_employee(id, post_body)
        if resource == "locations":
            update_location(id, post_body)

        if success:
            self._set_headers(204)
        else:
            self._set_headers(404)

        # Encode the new animal and send in response
        self.wfile.write("".encode())
Esempio n. 2
0
    def do_PUT(self):
        self._set_headers(204)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)
        # turns into post body when json loads
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        # checks for resourse, passes id and post body
        if resource == "animals":
            update_animal(id, post_body)

        if resource == "customers":
            update_customer(id, post_body)    

        if resource == "employees":
            update_employee(id, post_body)  

        if resource == "locations":
            update_location(id, post_body)        

        # Encode the new animal and send in response
        self.wfile.write("".encode())
Esempio n. 3
0
    def do_PUT(self):
        self._set_headers(204)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        # Delete a single animal from the list
        if resource == "animals":
            update_animal(id, post_body)

        # Encode the new animal and send in response
        self.wfile.write("".encode())
Esempio n. 4
0
    def do_PUT(self):
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        success = False

        if resource == "animals":
            success = update_animal(id, post_body)
        # rest of the elif's
        if resource == "employees":
            success = update_employee(id, post_body)

        if resource == "locations":
            success = update_location(id, post_body)

        if resource == "customers":
            success = update_customer(id, post_body)

        if success:
            self._set_headers(204)
        else:
            self._set_headers(404)

        self.wfile.write("".encode())
Esempio n. 5
0
    def do_PUT(self):
        self._set_headers(201)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)
        post_body = json.loads(post_body)

        (resource, id) = self.parse_url(self.path)

        success = False

        if resource == 'animals':
            success = update_animal(id, post_body)

        if success:
            self._set_headers(204)
        else:
            self._set_headers(404)

        self.wfile.write("".encode())
    def do_PUT(self):
        # You should be able to explain which HTTP method is used by the client to request that a resource's state should change.
        self._set_headers(204)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        success = False

        if resource == "animals":
            success = update_animal(id, post_body)
            # Encode the new animal and send in response
            # self.wfile.write("".encode())

        if resource == "customers":
            success = update_customer(id, post_body)
            # Encode the new customer and send in response
            # self.wfile.write("".encode())

        if resource == "employees":
            success = update_employee(id, post_body)
            # Encode the new employee and send in response
            # self.wfile.write("".encode())

        if resource == "locations":
            success = update_location(id, post_body)
            # Encode the new location and send in response

        if success:
            self._set_headers(204)
        else:
            self._set_headers(404)



        self.wfile.write("".encode())
Esempio n. 7
0
    def do_PUT(self):
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        print(resource)

        success = False

        # update single animal from list
        if resource == "animals":
            success = update_animal(id, post_body)
        elif resource == "customers":
            success = update_customer(id, post_body)
        elif resource == "employees":
            success = update_employee(id, post_body)
        elif resource == "locations":
            success = update_location(id, post_body)

        self.wfile.write("".encode())