Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add cursor support for ApiResponse #110

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/InfomaniakCore/Networking/ApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ open class ApiFetcher {
pages: apiResponse.pages,
page: apiResponse.page,
itemsPerPage: apiResponse.itemsPerPage,
responseAt: apiResponse.responseAt
responseAt: apiResponse.responseAt,
cursor: nil,
hasMore: false
)
return ValidServerResponse(
statusCode: serverResponse.statusCode,
Expand Down
6 changes: 6 additions & 0 deletions Sources/InfomaniakCore/Networking/ApiResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ open class ApiResponse<ResponseContent: Decodable>: Decodable {
public let page: Int?
public let itemsPerPage: Int?
public let responseAt: Int?
public let cursor: String?
public let hasMore: Bool

enum CodingKeys: String, CodingKey {
case result
Expand All @@ -46,6 +48,8 @@ open class ApiResponse<ResponseContent: Decodable>: Decodable {
case page
case itemsPerPage = "items_per_page"
case responseAt = "response_at"
case cursor
case hasMore = "has_more"
}

public required init(from decoder: Decoder) throws {
Expand All @@ -64,5 +68,7 @@ open class ApiResponse<ResponseContent: Decodable>: Decodable {
page = try container.decodeIfPresent(Int.self, forKey: .page)
itemsPerPage = try container.decodeIfPresent(Int.self, forKey: .itemsPerPage)
responseAt = try container.decodeIfPresent(Int.self, forKey: .responseAt)
cursor = try container.decodeIfPresent(String.self, forKey: .cursor)
hasMore = try container.decodeIfPresent(Bool.self, forKey: .hasMore) ?? false
}
}
2 changes: 2 additions & 0 deletions Sources/InfomaniakCore/Networking/ValidApiResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public struct ValidApiResponse<ResponseContent> {
public let page: Int?
public let itemsPerPage: Int?
public let responseAt: Int?
public let cursor: String?
public let hasMore: Bool
}
Loading