This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathReaderTopicServiceRemote+Interests.swift
More file actions
55 lines (46 loc) · 2.48 KB
/
Copy pathReaderTopicServiceRemote+Interests.swift
File metadata and controls
55 lines (46 loc) · 2.48 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
49
50
51
52
53
54
55
import Foundation
extension ReaderTopicServiceRemote {
/// Returns a collection of RemoteReaderInterest
/// - Parameters:
/// - Parameter success: Called when the request succeeds and the data returned is valid
/// - Parameter failure: Called if the request fails for any reason, or the response data is invalid
public func fetchInterests(_ success: @escaping ([RemoteReaderInterest]) -> Void,
failure: @escaping (Error) -> Void) {
let path = self.path(forEndpoint: "read/interests", withVersion: ._2_0)
wordPressComRESTAPI.get(path,
parameters: nil,
success: { response, _ in
do {
let decoder = JSONDecoder()
let data = try JSONSerialization.data(withJSONObject: response, options: [])
let envelope = try decoder.decode(ReaderInterestEnvelope.self, from: data)
success(envelope.interests)
} catch {
WPKitLogError("Error parsing the reader interests response: \(error)")
failure(error)
}
}, failure: { error, _ in
WPKitLogError("Error fetching reader interests: \(error)")
failure(error)
})
}
/// Follows multiple tags/interests at once using their slugs
public func followInterests(withSlugs: [String],
success: @escaping () -> Void,
failure: @escaping (Error) -> Void) {
let path = self.path(forEndpoint: "read/tags/mine/new", withVersion: ._1_2)
let parameters = ["tags": withSlugs] as [String: AnyObject]
wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in
success()
}) { error, _ in
WPKitLogError("Error fetching reader interests: \(error)")
failure(error)
}
}
/// Returns an API path for the given tag/topic/interest slug
/// - Returns: https://_api_/read/tags/_slug_/posts
public func pathForTopic(slug: String) -> String {
let endpoint = path(forEndpoint: "read/tags/\(slug)/posts", withVersion: ._1_2)
return wordPressComRESTAPI.baseURL.appendingPathComponent(endpoint).absoluteString
}
}