github4s icon indicating copy to clipboard operation
github4s copied to clipboard

List followers of a user

Open abteilung6 opened this issue 3 years ago • 3 comments

Users.scala

  /**
   * Lists the people following the specified user.
   *
   * @param username of the user to retrieve
   * @param pagination Limit and Offset for pagination
   * @param headers optional user headers to include in the request
   * @return GHResponse[List[User]\] User details
   */
  def getFollowers(
      username: String,
      pagination: Option[Pagination] = None,
      headers: Map[String, String] = Map()
  ): F[GHResponse[List[User]]]

UsersInterpreter.scala

  override def getFollowers(
      username: String,
      pagination: Option[Pagination],
      headers: Map[String, String]
  ): F[GHResponse[List[User]]] =
    client
      .get[List[User]](s"users/$username/followers", headers, pagination = pagination)

UsersSpec.scala


  "Users >> GetFollowers" should "return the expected followers list for a valid username" taggedAs Integration in {
    val response = clientResource
      .use { client =>
        Github[IO](client, accessToken).users
          .getFollowers(validUsername, None, headerUserAgent)
      }
      .unsafeRunSync()

    testIsRight[List[User]](response, r => r.nonEmpty shouldBe true)
    response.statusCode shouldBe okStatusCode
  }

  it should "return error on Left for invalid username" taggedAs Integration in {
    val response = clientResource
      .use { client =>
        Github[IO](client, accessToken).users
          .getFollowers(invalidUsername, None, headerUserAgent)
      }
      .unsafeRunSync()

    testIsLeft[GHError.NotFoundError, List[User]](response)
    response.statusCode shouldBe notFoundStatusCode
  }

abteilung6 avatar Jul 31 '22 12:07 abteilung6

@abteilung6, thanks for the suggestions. I can help you with the missing pieces if you want to create the PR. It would be nice to give you the proper credits for the contribution.

fedefernandez avatar Aug 01 '22 14:08 fedefernandez

@fedefernandez I think i didn't had the permission for an upstream branch in order to create a draft PR. But I will retry it the next days!

abteilung6 avatar Aug 08 '22 19:08 abteilung6

@abteilung6 yeah, I think the only way would be through a fork

fedefernandez avatar Aug 09 '22 07:08 fedefernandez