Esempio n. 1
0
    def update_me(self,
                  name: Optional[str] = None,
                  email: Optional[str] = None):
        """
        Update private profile information when authenticated through
        basic auth or OAuth with the user scope.

        If your email is set to private and you send an email parameter as part of this
        request to update your profile, your privacy settings are still enforced:
        the email address will not be displayed on your public profile or via the API.

        Args:
            name: The new name of the user.
            email: The publicly visible email address of the user.

        Returns:
            Public and private profile information for currently authenticated user.
        """
        assert self.auth is not None, "`auth` must be set for this method"
        data = {k: v for k, v in vars().items() if v is not None}
        assert data, "At least one field to update must be provided"
        request = Request(Method.PATCH,
                          self.url("/user"),
                          json=data,
                          auth=self.auth)
        return fetch(self.driver, request, model=Me)
Esempio n. 2
0
    def me(self):
        """
        Lists public and private profile information when authenticated through
        basic auth or OAuth with the user scope.

        Returns:
            Public and private profile information for currently authenticated user.
        """
        assert self.auth is not None, "`auth` must be set for this method"
        request = Request(Method.GET, self.url("/user"), auth=self.auth)
        return fetch(self.driver, request, model=Me)
Esempio n. 3
0
    def user(self, username: str):
        """
        Provides publicly available information about someone with a GitHub account.

        Args:
            username: User's username on the GitHub

        Returns:
            Public profile information for GitHub User.
        """
        request = Request(Method.GET,
                          self.url("/users/{username}", username=username))
        return fetch(self.driver, request, model=UserDetail)
Esempio n. 4
0
    def users(self, since: int = 0):
        """
        Lists all users, in the order that they signed up on GitHub.

        Pagination is powered exclusively by the since parameter.

        Args:
            since: The integer ID of the last User that you've seen.

        Returns:
            List of GitHub users
        """
        params = {"since": str(since)}
        request = Request(Method.GET, self.url("/users"), query_params=params)
        return fetch(self.driver, request, model=List[User])
Esempio n. 5
0
def test_fetch_returns_model_from_source() -> None:
    request = Request(Method.GET, "https://example.com")
    driver_response = factories.make_response(b'{"user": {"id": 1}}')
    driver = factories.make_driver(driver_response)
    user = fetch(driver, request, model=User, source="user")
    assert user == User(id=1)
Esempio n. 6
0
def test_fetch_returns_response() -> None:
    request = Request(Method.GET, "https://example.com")
    driver_response = factories.make_response(b"Hello, World")
    driver = factories.make_driver(driver_response)
    response = fetch(driver, request)
    assert response.content == b"Hello, World"