2020-03-15 01:00:29 +01:00
|
|
|
//
|
|
|
|
// NewsBlurFolderChange.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Anh Quang Do on 2020-03-14.
|
|
|
|
// Copyright (c) 2020 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
enum NewsBlurFolderChange {
|
|
|
|
case add(String)
|
2020-03-15 01:42:45 +01:00
|
|
|
case rename(String, String)
|
2020-03-15 02:09:42 +01:00
|
|
|
case delete(String, [String])
|
2020-03-15 01:00:29 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 01:42:45 +01:00
|
|
|
extension NewsBlurFolderChange: NewsBlurDataConvertible {
|
2020-03-15 01:00:29 +01:00
|
|
|
var asData: Data? {
|
|
|
|
var postData = URLComponents()
|
|
|
|
postData.queryItems = {
|
|
|
|
switch self {
|
|
|
|
case .add(let name):
|
2020-03-21 22:16:35 +01:00
|
|
|
return [
|
|
|
|
URLQueryItem(name: "folder", value: name),
|
|
|
|
URLQueryItem(name: "parent_folder", value: ""), // root folder
|
|
|
|
]
|
2020-03-15 01:42:45 +01:00
|
|
|
case .rename(let from, let to):
|
|
|
|
return [
|
|
|
|
URLQueryItem(name: "folder_to_rename", value: from),
|
|
|
|
URLQueryItem(name: "new_folder_name", value: to),
|
|
|
|
URLQueryItem(name: "in_folder", value: ""), // root folder
|
|
|
|
]
|
2020-03-15 02:09:42 +01:00
|
|
|
case .delete(let name, let feedIDs):
|
|
|
|
var queryItems = [
|
2020-03-15 01:42:45 +01:00
|
|
|
URLQueryItem(name: "folder_to_delete", value: name),
|
|
|
|
URLQueryItem(name: "in_folder", value: ""), // root folder
|
|
|
|
]
|
2020-03-15 02:09:42 +01:00
|
|
|
queryItems.append(contentsOf: feedIDs.map { id in
|
|
|
|
URLQueryItem(name: "feed_id", value: id)
|
|
|
|
})
|
|
|
|
return queryItems
|
2020-03-15 01:00:29 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return postData.percentEncodedQuery?.data(using: .utf8)
|
|
|
|
}
|
|
|
|
}
|