forked from RocketChat/Rocket.Chat.iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIRequestOption.swift
More file actions
48 lines (40 loc) · 1.01 KB
/
Copy pathAPIRequestOption.swift
File metadata and controls
48 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// APIRequestOption.swift
// Rocket.Chat
//
// Created by Matheus Cardoso on 5/11/18.
// Copyright © 2018 Rocket.Chat. All rights reserved.
//
import Foundation
enum APIRequestOption: Hashable {
case paginated(count: Int, offset: Int)
case retryOnError(count: Int)
case none
var query: String? {
switch self {
case .paginated(let count, let offset):
return "count=\(count)&offset=\(offset)"
default:
return nil
}
}
}
typealias APIRequestOptionSet = Set<APIRequestOption>
extension Set where Element == APIRequestOption {
var retries: Int {
for option in self {
if case let .retryOnError(retries) = option {
return retries
}
}
return 0
}
func withRetries(_ retries: Int) -> APIRequestOptionSet {
return Set(map {
if case .retryOnError = $0 {
return .retryOnError(count: retries)
}
return $0
})
}
}