Skip to content

Commit 091209b

Browse files
committed
Extract no verifier parameter to APIURLRequestable protocol.
1 parent 76bef6b commit 091209b

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

Core/Core/API/APIRequestable.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public protocol APIRequestable {
165165
/// If this parameter is set to true, then we will use a custom percent encoding for every `URLQueryItem` where the `"+"` sign is encoded alongside with the `urlHostAllowed` CharacterSet.
166166
/// Some APIs expect Date strings with the time zone attached where we need to encode the `+` sign.
167167
var useExtendedPercentEncoding: Bool { get }
168+
/// This will make the API to omit the file verifier parameter when returning course file links in rich content.
169+
var shouldAddNoVerifierQuery: Bool { get }
168170

169171
func urlRequest(relativeTo: URL, accessToken: String?, actAsUserID: String?) throws -> URLRequest
170172
func decode(_ data: Data) throws -> Response
@@ -205,6 +207,8 @@ extension APIRequestable {
205207

206208
public var useExtendedPercentEncoding: Bool { false }
207209

210+
public var shouldAddNoVerifierQuery: Bool { true }
211+
208212
public func urlRequest(relativeTo baseURL: URL, accessToken: String?, actAsUserID: String?) throws -> URLRequest {
209213
guard var components = URLComponents(string: path) else { throw APIRequestableError.invalidPath(path) }
210214

@@ -278,19 +282,7 @@ extension APIRequestable {
278282
extraQueryItems.append(URLQueryItem(name: "as_user_id", value: actAsUserID))
279283
}
280284

281-
let ignoreNoVerifierQueryRequests: [any APIRequestable.Type] = [
282-
LoginWebRequest.self,
283-
GetMobileVerifyRequest.self,
284-
PostAccountUserRequest.self
285-
]
286-
let shouldAddNoVerifierQuery: Bool = {
287-
!ignoreNoVerifierQueryRequests.contains { ignorableType in
288-
(type(of: self) == ignorableType)
289-
}
290-
}()
291-
292285
if shouldAddNoVerifierQuery {
293-
/// This will make the API to omit the file verifier parameter when linking course files.
294286
extraQueryItems.append(URLQueryItem(name: "no_verifiers", value: "1"))
295287
}
296288

Core/Core/Login/APILoginWeb.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct LoginWebRequest: APIRequestable {
2525
let provider: String?
2626

2727
let path = "/login/oauth2/auth"
28+
let shouldAddNoVerifierQuery = false
2829

2930
var query: [APIQueryItem] {
3031
var items: [APIQueryItem] = [

Core/Core/Login/APIOAuth.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct GetMobileVerifyRequest: APIRequestable {
134134
HttpHeader.accept: "application/json",
135135
HttpHeader.authorization: nil
136136
]
137+
let shouldAddNoVerifierQuery = false
137138
}
138139

139140
// https://canvas.instructure.com/doc/api/file.oauth_endpoints.html#post-login-oauth2-token

Core/Core/Profile/Settings/APIPairingCode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public struct PostAccountUserRequest: APIRequestable {
5454
public typealias Response = APIUser
5555
public let method: APIMethod = .post
5656
public var body: Body?
57+
public let shouldAddNoVerifierQuery = false
5758
let baseURL: URL
5859
let accountID: String
5960
public var shouldHandleCookies: Bool = false

0 commit comments

Comments
 (0)