-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ubscribers-methods #93 add get subscriptions and get subscribers methods
- Loading branch information
Showing
34 changed files
with
530 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...Main/kotlin/app/meetacy/sdk/engine/ktor/requests/friends/subscribers/SubscribersEngine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app.meetacy.sdk.engine.ktor.requests.friends.subscribers | ||
|
||
import app.meetacy.sdk.engine.ktor.apiVersion | ||
import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess | ||
import app.meetacy.sdk.engine.ktor.token | ||
import app.meetacy.sdk.engine.requests.ListSubscribersRequest | ||
import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable | ||
import app.meetacy.sdk.types.serializable.paging.type | ||
import app.meetacy.sdk.types.serializable.user.UserDetailsSerializable | ||
import app.meetacy.sdk.types.serializable.user.UserSerializable | ||
import app.meetacy.sdk.types.serializable.user.type | ||
import app.meetacy.sdk.types.url.Url | ||
import app.meetacy.sdk.types.user.User | ||
import io.ktor.client.* | ||
import io.ktor.client.request.* | ||
|
||
internal class SubscribersEngine( | ||
baseUrl: Url, | ||
private val httpClient: HttpClient | ||
) { | ||
private val baseUrl = baseUrl / "subscribers" | ||
|
||
suspend fun list(request: ListSubscribersRequest): ListSubscribersRequest.Response { | ||
val url = baseUrl / "list" | ||
|
||
val response = httpClient.get(url.string) { | ||
apiVersion(request.apiVersion) | ||
token(request.token) | ||
parameter("userId", request.userId?.string) | ||
parameter("amount", request.amount.int) | ||
parameter("pagingId", request.pagingId?.string) | ||
}.bodyAsSuccess<PagingResponseSerializable<UserSerializable>>() | ||
.type() | ||
.mapItems(UserSerializable::type) | ||
|
||
return ListSubscribersRequest.Response(response) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../kotlin/app/meetacy/sdk/engine/ktor/requests/friends/subscriptions/SubscriptionsEngine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package app.meetacy.sdk.engine.ktor.requests.friends.subscriptions | ||
|
||
import app.meetacy.sdk.engine.ktor.apiVersion | ||
import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess | ||
import app.meetacy.sdk.engine.ktor.token | ||
import app.meetacy.sdk.engine.requests.ListSubscriptionsRequest | ||
import app.meetacy.sdk.types.serializable.paging.PagingResponseSerializable | ||
import app.meetacy.sdk.types.serializable.paging.type | ||
import app.meetacy.sdk.types.serializable.user.UserSerializable | ||
import app.meetacy.sdk.types.serializable.user.type | ||
import app.meetacy.sdk.types.url.Url | ||
import io.ktor.client.* | ||
import io.ktor.client.request.* | ||
|
||
internal class SubscriptionsEngine( | ||
baseUrl: Url, | ||
private val httpClient: HttpClient | ||
) { | ||
private val baseUrl = baseUrl / "subscriptions" | ||
|
||
suspend fun list(request: ListSubscriptionsRequest): ListSubscriptionsRequest.Response { | ||
val url = baseUrl / "list" | ||
|
||
val response = httpClient.get(url.string) { | ||
apiVersion(request.apiVersion) | ||
token(request.token) | ||
parameter("userId", request.userId?.string) | ||
parameter("amount", request.amount.int) | ||
parameter("pagingId", request.pagingId?.string) | ||
}.bodyAsSuccess<PagingResponseSerializable<UserSerializable>>() | ||
.type() | ||
.mapItems(UserSerializable::type) | ||
|
||
return ListSubscriptionsRequest.Response(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListSubscribersRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package app.meetacy.sdk.engine.requests | ||
|
||
import app.meetacy.sdk.types.amount.Amount | ||
import app.meetacy.sdk.types.auth.Token | ||
import app.meetacy.sdk.types.paging.PagingId | ||
import app.meetacy.sdk.types.paging.PagingResponse | ||
import app.meetacy.sdk.types.user.User | ||
import app.meetacy.sdk.types.user.UserDetails | ||
import app.meetacy.sdk.types.user.UserId | ||
|
||
public data class ListSubscribersRequest( | ||
val token: Token, | ||
val amount: Amount, | ||
val pagingId: PagingId?, | ||
val userId: UserId?, | ||
) : MeetacyRequest<ListSubscribersRequest.Response> { | ||
public data class Response(val paging: PagingResponse<User>) | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/commonMain/kotlin/app/meetacy/sdk/engine/requests/ListSubscriptionsRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package app.meetacy.sdk.engine.requests | ||
|
||
import app.meetacy.sdk.types.amount.Amount | ||
import app.meetacy.sdk.types.auth.Token | ||
import app.meetacy.sdk.types.paging.PagingId | ||
import app.meetacy.sdk.types.paging.PagingResponse | ||
import app.meetacy.sdk.types.user.User | ||
import app.meetacy.sdk.types.user.UserDetails | ||
import app.meetacy.sdk.types.user.UserId | ||
|
||
public data class ListSubscriptionsRequest( | ||
val token: Token, | ||
val amount: Amount, | ||
val pagingId: PagingId?, | ||
val userId: UserId?, | ||
) : MeetacyRequest<ListSubscriptionsRequest.Response> { | ||
public data class Response(val paging: PagingResponse<User>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 12 additions & 5 deletions
17
api/src/commonMain/kotlin/app/meetacy/sdk/friends/FriendsApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
api/src/commonMain/kotlin/app/meetacy/sdk/friends/subscribers/AuthorizedSubscribersApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package app.meetacy.sdk.friends.subscribers | ||
|
||
import app.meetacy.sdk.AuthorizedMeetacyApi | ||
import app.meetacy.sdk.types.amount.Amount | ||
import app.meetacy.sdk.types.auth.Token | ||
import app.meetacy.sdk.types.paging.PagingId | ||
import app.meetacy.sdk.types.paging.PagingRepository | ||
import app.meetacy.sdk.types.paging.PagingSource | ||
import app.meetacy.sdk.types.paging.mapItems | ||
import app.meetacy.sdk.types.user.UserId | ||
import app.meetacy.sdk.users.AuthorizedUserRepository | ||
|
||
/** | ||
* When modifying this class, corresponding classes should be altered: | ||
* - [app.meetacy.sdk.users.subscribers.AuthorizedSubscribersRepository] | ||
*/ | ||
public class AuthorizedSubscribersApi(private val api: AuthorizedMeetacyApi) { | ||
public val token: Token get() = api.token | ||
public val base: SubscribersApi get() = api.base.friends.subscribers | ||
|
||
public suspend fun list( | ||
amount: Amount, | ||
pagingId: PagingId? = null, | ||
userId: UserId? = null | ||
): PagingRepository<AuthorizedUserRepository> { | ||
return base.list(token, amount, pagingId, userId).mapItems { user -> | ||
AuthorizedUserRepository.of(user.data, api) | ||
} | ||
} | ||
|
||
public fun paging( | ||
chunkSize: Amount, | ||
startPagingId: PagingId? = null, | ||
limit: Amount? = null, | ||
userId: UserId? = null | ||
): PagingSource<AuthorizedUserRepository> { | ||
return PagingSource( | ||
chunkSize, startPagingId, limit | ||
) { currentAmount, currentPagingId -> | ||
list(currentAmount, currentPagingId, userId).response | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
api/src/commonMain/kotlin/app/meetacy/sdk/friends/subscribers/SubscribersApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package app.meetacy.sdk.friends.subscribers | ||
|
||
import app.meetacy.sdk.MeetacyApi | ||
import app.meetacy.sdk.engine.requests.ListSubscribersRequest | ||
import app.meetacy.sdk.types.amount.Amount | ||
import app.meetacy.sdk.types.auth.Token | ||
import app.meetacy.sdk.types.paging.PagingId | ||
import app.meetacy.sdk.types.paging.PagingRepository | ||
import app.meetacy.sdk.types.paging.PagingSource | ||
import app.meetacy.sdk.types.user.UserId | ||
import app.meetacy.sdk.users.UserRepository | ||
|
||
/** | ||
* When modifying this class, corresponding classes should be altered: | ||
* - [app.meetacy.sdk.friends.subscribers.AuthorizedSubscribersApi] | ||
* - [app.meetacy.sdk.users.subscribers.SubscribersRepository] | ||
*/ | ||
public class SubscribersApi(private val api: MeetacyApi) { | ||
public suspend fun list( | ||
token: Token, | ||
amount: Amount, | ||
pagingId: PagingId? = null, | ||
userId: UserId? = null, | ||
): PagingRepository<UserRepository> = PagingRepository( | ||
amount = amount, | ||
startPagingId = pagingId | ||
) { currentAmount, currentPagingId -> | ||
api.engine.execute( | ||
request = ListSubscribersRequest( | ||
token = token, | ||
userId = userId, | ||
amount = currentAmount, | ||
pagingId = currentPagingId | ||
) | ||
).paging.mapItems { user -> | ||
UserRepository.of(user, api) | ||
} | ||
} | ||
|
||
public fun paging( | ||
token: Token, | ||
chunkSize: Amount, | ||
startPagingId: PagingId? = null, | ||
limit: Amount? = null, | ||
userId: UserId? = null | ||
): PagingSource<UserRepository> { | ||
return PagingSource( | ||
chunkSize, startPagingId, limit | ||
) { currentAmount, currentPagingId -> | ||
list(token, currentAmount, currentPagingId, userId).response | ||
} | ||
} | ||
} |
Oops, something went wrong.