Beispiel #1
0
    def get_project(self, project_id):
        """Fetch list of project from remote web service API.

        Returns
        -------
        list(vizier.api.client.resources.project.ProjectResource)
        """
        # Fetch project resource
        url = self.urls.get_project(project_id)
        response = urllib.request.urlopen(url)
        data = json.loads(response.read())
        # Convert result into instance of the project resource class
        return ProjectResource.from_dict(data)
Beispiel #2
0
    def list_projects(self):
        """Fetch list of project from remote web service API.

        Returns
        -------
        list(vizier.api.client.resources.project.ProjectResource)
        """
        # Fetch projects listing
        url = self.urls.list_projects()
        response = urllib.request.urlopen(url)
        data = json.loads(response.read())
        # Convert result into list of project resources
        projects = list()
        for obj in data['projects']:
            projects.append(ProjectResource.from_dict(obj))
        return projects
Beispiel #3
0
    def create_project(self, properties: Dict[str, Any]) -> ProjectResource:
        """Create a new project resource at the server.

        Parameters
        ----------
        properties: dict
            Dictionary of project properties

        Results
        -------
        vizier.api.client.resources.project.ProjectResource
        """
        # Get the request url and create the request body
        url = self.urls.create_project()
        data = {labels.PROPERTIES: serialize.PROPERTIES(properties)}
        # Send request. Raise exception if status code indicates that the
        # request was not successful
        r = requests.post(url, json=data)
        r.raise_for_status()
        # The result is the new project descriptor
        return ProjectResource.from_dict(json.loads(r.text))
Beispiel #4
0
    def update_project(self, project_id, properties):
        """Update the properties of a given project.

        Parameters
        ----------
        project_id: string
            Unique project identifier
        properties: dict
            Properties update statements

        Returns
        -------
        vizier.api.client.resources.project.ProjectResource
        """
        # Get the request url and create the request body
        url = self.urls.update_project(project_id)
        data = {labels.PROPERTIES: serialize.PROPERTIES(properties)}
        # Send request. Raise exception if status code indicates that the
        # request was not successful
        r = requests.put(url, json=data)
        r.raise_for_status()
        # The result is the new project descriptor
        return ProjectResource.from_dict(json.loads(r.text))