Skip to content

Commit

Permalink
Merge pull request #110 from Infomaniak/cursored-response
Browse files Browse the repository at this point in the history
feat: Add cursor support for ApiResponse
  • Loading branch information
PhilippeWeidmann committed Mar 7, 2024
2 parents 7647060 + a00f588 commit 4433608
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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
}

0 comments on commit 4433608

Please sign in to comment.