Skip to content

Commit 94e06e3

Browse files
committed
Replaced instance methods with apply
1 parent caac291 commit 94e06e3

File tree

11 files changed

+33
-19
lines changed

11 files changed

+33
-19
lines changed

docs/client-credentials.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ description: Client credentials grant documentation
1010
- `introspect` the token for it's details like `UserInfo`
1111

1212
```scala
13-
val accessTokenProvider = AccessTokenProvider.instance[IO](tokenUrl, clientId, clientSecret)
14-
val tokenIntrospection = TokenIntrospection.instance[IO](tokenIntrospectionUrl, clientId, clientSecret)
13+
val accessTokenProvider = AccessTokenProvider[IO](tokenUrl, clientId, clientSecret)
14+
val tokenIntrospection = TokenIntrospection[IO](tokenIntrospectionUrl, clientId, clientSecret)
1515

1616
for {
1717
token <- accessTokenProvider.requestToken(scope) // ask for token
@@ -35,7 +35,7 @@ Caching modules provide cached `AccessTokenProvider`, which can:
3535
### Cats example
3636

3737
```scala
38-
val delegate = AccessTokenProvider.instance[IO](tokenUrl, clientId, clientSecret)
38+
val delegate = AccessTokenProvider[IO](tokenUrl, clientId, clientSecret)
3939
CachingAccessTokenProvider.refCacheInstance[IO](delegate)
4040
```
4141

docs/migrating.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,28 @@ To build cached `SttpBackend`:
2424
- replace creation of `SttpOauth2ClientCredentialsXXXBackend` with the following example adjusted to your needs:
2525

2626
```scala
27-
val accessTokenProvider = AccessTokenProvider.instance[IO](tokenUrl, clientId, clientSecret)
27+
val accessTokenProvider = AccessTokenProvider[IO](tokenUrl, clientId, clientSecret)
2828
CachingAccessTokenProvider.refCacheInstance[IO](accessTokenProvider).map { cachingAccessTokenProvider =>
2929
SttpOauth2ClientCredentialsBackend[IO, Any](cachingAccessTokenProvider)(scope)
3030
}
3131
```
3232

3333
For details please see [PR](https://github.com/ocadotechnology/sttp-oauth2/pull/149).
3434

35+
### Apply
36+
37+
In many companion objects factory methods called `instance` have been replaced with `apply`, so previous way of creating objects:
38+
39+
```scala
40+
ClientCredentialsProvider.instance[IO](tokenUrl, tokenIntrospectionUrl, clientId, clientSecret)
41+
```
42+
43+
needs to be replaced with:
44+
45+
```scala
46+
ClientCredentialsProvider[IO](tokenUrl, tokenIntrospectionUrl, clientId, clientSecret)
47+
```
48+
3549

3650
## [v0.10.0](https://github.com/ocadotechnology/sttp-oauth2/releases/tag/v0.5.0)
3751

oauth2-cache-ce2/src/test/scala/com/ocadotechnology/sttp/oauth2/cache/ce2/CachingAccessTokenProviderParallelSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class CachingAccessTokenProviderParallelSpec extends AnyWordSpec with Matchers {
7878
private def prepareTest =
7979
for {
8080
state <- Ref.of[IO, TestAccessTokenProvider.State](TestAccessTokenProvider.State.empty)
81-
delegate = TestAccessTokenProvider.instance[IO](state)
81+
delegate = TestAccessTokenProvider[IO](state)
8282
cache <- CatsRefExpiringCache[IO, Scope, TokenWithExpirationTime]
8383
delayingCache = new DelayingCache(cache)
8484
cachingProvider <- CachingAccessTokenProvider[IO](delegate, delayingCache)

oauth2-cache-ce2/src/test/scala/com/ocadotechnology/sttp/oauth2/cache/ce2/CachingAccessTokenProviderSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class CachingAccessTokenProviderSpec extends AnyWordSpec with Matchers {
7171
private def prepareTest =
7272
for {
7373
state <- Ref.of[IO, TestAccessTokenProvider.State](TestAccessTokenProvider.State.empty)
74-
delegate = TestAccessTokenProvider.instance[IO](state)
74+
delegate = TestAccessTokenProvider[IO](state)
7575
cache <- CatsRefExpiringCache[IO, Scope, TokenWithExpirationTime]
7676
cachingProvider <- CachingAccessTokenProvider[IO](delegate, cache)
7777
} yield (delegate, cachingProvider)

oauth2-cache-ce2/src/test/scala/com/ocadotechnology/sttp/oauth2/cache/ce2/TestAccessTokenProvider.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object TestAccessTokenProvider {
2424
val empty: State = State(Map.empty, Map.empty)
2525
}
2626

27-
def instance[F[_]: Functor](ref: Ref[F, State]): TestAccessTokenProvider[F] =
27+
def apply[F[_]: Functor](ref: Ref[F, State]): TestAccessTokenProvider[F] =
2828
new TestAccessTokenProvider[F] {
2929
override def requestToken(scope: Scope): F[ClientCredentialsToken.AccessTokenResponse] =
3030
ref.get.map(_.tokens.getOrElse(scope, throw new IllegalArgumentException(s"Unknown $scope")))

oauth2/src/main/scala/com/ocadotechnology/sttp/oauth2/AccessTokenProvider.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object AccessTokenProvider {
2323
*
2424
* `clientId`, `clientSecret` are parameters of your application.
2525
*/
26-
def instance[F[_]](
26+
def apply[F[_]](
2727
tokenUrl: Uri,
2828
clientId: NonEmptyString,
2929
clientSecret: Secret[String]

oauth2/src/main/scala/com/ocadotechnology/sttp/oauth2/ClientCredentialsProvider.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ object ClientCredentialsProvider {
1515
*
1616
* `clientId`, `clientSecret`, `applicationScope` are parameters of your application.
1717
*/
18-
def instance[F[_]](
18+
def apply[F[_]](
1919
tokenUrl: Uri,
2020
tokenIntrospectionUrl: Uri,
2121
clientId: NonEmptyString,
2222
clientSecret: Secret[String]
2323
)(
2424
implicit backend: SttpBackend[F, Any]
2525
): ClientCredentialsProvider[F] =
26-
from[F](
27-
AccessTokenProvider.instance[F](tokenUrl, clientId, clientSecret),
28-
TokenIntrospection.instance[F](tokenIntrospectionUrl, clientId, clientSecret)
26+
ClientCredentialsProvider[F](
27+
AccessTokenProvider[F](tokenUrl, clientId, clientSecret),
28+
TokenIntrospection[F](tokenIntrospectionUrl, clientId, clientSecret)
2929
)
3030

31-
def from[F[_]](accessTokenProvider: AccessTokenProvider[F], tokenIntrospection: TokenIntrospection[F]): ClientCredentialsProvider[F] =
31+
def apply[F[_]](accessTokenProvider: AccessTokenProvider[F], tokenIntrospection: TokenIntrospection[F]): ClientCredentialsProvider[F] =
3232
new ClientCredentialsProvider[F] {
3333
override def requestToken(scope: Scope): F[ClientCredentialsToken.AccessTokenResponse] =
3434
accessTokenProvider.requestToken(scope)

oauth2/src/main/scala/com/ocadotechnology/sttp/oauth2/PasswordGrantProvider.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object PasswordGrantProvider {
1616

1717
def apply[F[_]](implicit ev: PasswordGrantProvider[F]): PasswordGrantProvider[F] = ev
1818

19-
def instance[F[_]: MonadError[*[_], Throwable]](
19+
def apply[F[_]: MonadError[*[_], Throwable]](
2020
tokenUrl: Uri,
2121
clientId: NonEmptyString,
2222
clientSecret: Secret[String]

oauth2/src/main/scala/com/ocadotechnology/sttp/oauth2/SttpOauth2ClientCredentialsBackend.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object SttpOauth2ClientCredentialsBackend {
3434
)(
3535
implicit backend: SttpBackend[F, P]
3636
): SttpOauth2ClientCredentialsBackend[F, P] = {
37-
val accessTokenProvider = AccessTokenProvider.instance(tokenUrl, clientId, clientSecret)
37+
val accessTokenProvider = AccessTokenProvider[F](tokenUrl, clientId, clientSecret)
3838
SttpOauth2ClientCredentialsBackend(accessTokenProvider)(scope)
3939
}
4040

oauth2/src/main/scala/com/ocadotechnology/sttp/oauth2/TokenIntrospection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object TokenIntrospection {
2424
*
2525
* `clientId`, `clientSecret` are parameters of your application.
2626
*/
27-
def instance[F[_]](
27+
def apply[F[_]](
2828
tokenIntrospectionUrl: Uri,
2929
clientId: NonEmptyString,
3030
clientSecret: Secret[String]

0 commit comments

Comments
 (0)