Skip to content

Commit

Permalink
Eric/0.19 headers (#752)
Browse files Browse the repository at this point in the history
Co-authored-by: mormaer <nick@mormaer.dev>
  • Loading branch information
EricBAndrews and mormaer authored Nov 9, 2023
1 parent b91d4e5 commit 84fa94c
Showing 3 changed files with 6 additions and 25 deletions.
4 changes: 4 additions & 0 deletions Mlem/API/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
@@ -141,6 +141,10 @@ class APIClient {
defintion.headers.forEach { header in
urlRequest.setValue(header.value, forHTTPHeaderField: header.key)
}

if case let .authenticated(_, token) = session {
urlRequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
}

if defintion as? any APIGetRequest != nil {
urlRequest.httpMethod = "GET"
4 changes: 2 additions & 2 deletions Mlem/API/Models/Person/APIPersonAggregates.swift
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ struct APIPersonAggregates: Decodable {
let id: Int
let personId: Int
let postCount: Int
let postScore: Int
let postScore: Int?
let commentCount: Int
let commentScore: Int
let commentScore: Int?
}
23 changes: 0 additions & 23 deletions Mlem/API/Requests/Post/GetPosts.swift
Original file line number Diff line number Diff line change
@@ -14,29 +14,6 @@ struct GetPostsRequest: APIGetRequest {
let instanceURL: URL
let path = "post/list"
let queryItems: [URLQueryItem]

init(
account: SavedAccount, // TODO: needs to move to a session based call...
communityId: Int?,
page: Int,
sort: PostSortType?,
type: FeedType,
limit: Int? = nil,
savedOnly: Bool? = nil,
communityName: String? = nil
) {
self.instanceURL = account.instanceLink
self.queryItems = [
.init(name: "auth", value: account.accessToken),
.init(name: "page", value: "\(page)"),
.init(name: "type_", value: type.rawValue),
.init(name: "sort", value: sort.map(\.rawValue)),
.init(name: "community_id", value: communityId.map(String.init)),
.init(name: "community_name", value: communityName),
.init(name: "limit", value: limit.map(String.init)),
.init(name: "saved_only", value: savedOnly.map(String.init))
]
}

init(
session: APISession,

0 comments on commit 84fa94c

Please sign in to comment.