feat: implement all entities

This commit is contained in:
CMK 2021-01-29 14:49:25 +08:00
parent 4c9e644820
commit fe83c02e03
17 changed files with 571 additions and 22 deletions

View File

@ -21,7 +21,7 @@ extension Mastodon.Entity {
public typealias ID = String
public let id: ID
public let type: Type?
public let type: Type
public let url: String
public let previewURL: String
@ -47,12 +47,36 @@ extension Mastodon.Entity {
}
extension Mastodon.Entity.Attachment {
public enum `Type`: String, Codable {
public enum `Type`: RawRepresentable, Codable {
case unknown
case image
case gifv
case video
case audio
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "unknown": self = .unknown
case "image": self = .image
case "gifv": self = .gifv
case "video": self = .video
case "audio": self = .audio
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .unknown: return "unknown"
case .image: return "image"
case .gifv: return "gifv"
case .video: return "video"
case .audio: return "audio"
case ._other(let value): return value
}
}
}
}

View File

@ -21,7 +21,7 @@ extension Mastodon.Entity {
public let url: String
public let title: String
public let description: String
public let type: Type?
public let type: Type
public let authorName: String?
public let authorURL: String?
@ -54,10 +54,32 @@ extension Mastodon.Entity {
}
extension Mastodon.Entity.Card {
public enum `Type`: String, Codable {
public enum `Type`: RawRepresentable, Codable {
case link
case photo
case video
case rich
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "link": self = .link
case "photo": self = .photo
case "video": self = .video
case "rich": self = .rich
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .link: return "link"
case .photo: return "photo"
case .video: return "video"
case .rich: return "rich"
case ._other(let value): return value
}
}
}
}

View File

@ -21,7 +21,7 @@ extension Mastodon.Entity {
public let id: ID
public let phrase: String
public let context: [Context?]
public let context: [Context]
public let expiresAt: Date
public let irreversible: Bool
public let wholeWord: Bool
@ -38,10 +38,32 @@ extension Mastodon.Entity {
}
extension Mastodon.Entity.Filter {
public enum Context: String, Codable {
public enum Context: RawRepresentable, Codable {
case home
case notifications
case `public`
case thread
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "home": self = .home
case "notifications": self = .notifications
case "public": self = .`public`
case "thread": self = .thread
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .home: return "home"
case .notifications: return "notifications"
case .public: return "public"
case .thread: return "thread"
case ._other(let value): return value
}
}
}
}

View File

@ -21,6 +21,7 @@ extension Mastodon.Entity {
public let id: ID
public let title: String
public let repliesPolicy: ReplyPolicy?
enum CodingKeys: String, CodingKey {
@ -32,9 +33,29 @@ extension Mastodon.Entity {
}
extension Mastodon.Entity {
public enum ReplyPolicy: String, Codable {
public enum ReplyPolicy: RawRepresentable, Codable {
case followed
case list
case none
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "followed": self = .followed
case "list": self = .list
case "none": self = .none
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .followed: return "followed"
case .list: return "list"
case .none: return "none"
case ._other(let value): return value
}
}
}
}

View File

@ -0,0 +1,38 @@
//
// Mastodon+Entity+Marker.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// Marker
///
/// - Since: 3.0.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/marker/)
public struct Marker: Codable {
// Base
public let home: Position
public let notifications: Position
}
}
extension Mastodon.Entity.Marker {
public struct Position: Codable {
public let lastReadID: Mastodon.Entity.Status.ID
public let updatedAt: Date
public let version: Int
enum CodingKeys: String, CodingKey {
case lastReadID = "last_read_id"
case updatedAt = "updated_at"
case version
}
}
}

View File

@ -1,12 +0,0 @@
//
// Mastodon+Entity+Media.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
}

View File

@ -0,0 +1,77 @@
//
// Mastodon+Entity+Notification.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// Notification
///
/// - Since: 0.9.9
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/notification/)
public struct Notification: Codable {
public typealias ID = String
public let id: ID
public let type: Type
public let createdAt: Date
public let account: Account
public let status: Status?
enum CodingKeys: String, CodingKey {
case id
case type
case createdAt = "created_at"
case account
case status
}
}
}
extension Mastodon.Entity.Notification {
public enum `Type`: RawRepresentable, Codable {
case follow
case followRequest
case mention
case reblog
case favourite
case poll
case status
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "follow": self = .follow
case "follow_request": self = .followRequest
case "mention": self = .mention
case "reblog": self = .reblog
case "favourite": self = .favourite
case "poll": self = .poll
case "status": self = .status
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .follow: return "follow"
case .followRequest: return "follow_request"
case .mention: return "mention"
case .reblog: return "reblog"
case .favourite: return "favourite"
case .poll: return "poll"
case .status: return "status"
case ._other(let value): return value
}
}
}
}

View File

@ -0,0 +1,58 @@
//
// Mastodon+Entity+Preferences.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// Preferences
///
/// - Since: 2.8.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/preferences/)
public struct Preferences: Codable {
public let postingDefaultVisibility: Visibility
public let postingDefaultSensitive: Bool
public let postingDefaultLanguage: String? // (ISO 639-1 language two-letter code)
public let readingExpandMedia: ExpandMedia
public let readingExpandSpoilers: Bool
}
}
extension Mastodon.Entity.Preferences {
public typealias Visibility = Mastodon.Entity.Source.Privacy
}
extension Mastodon.Entity.Preferences {
public enum ExpandMedia: RawRepresentable, Codable {
case `default`
case showAll
case hideAll
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "default": self = .default
case "showAll": self = .showAll
case "hideAll": self = .hideAll
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .default: return "default"
case .showAll: return "showAll"
case .hideAll: return "hideAll"
case ._other(let value): return value
}
}
}
}

View File

@ -0,0 +1,44 @@
//
// Mastodon+Entity+PushSubscription.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// PushSubscription
///
/// - Since: 2.4.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/pushsubscription/)
public struct PushSubscription: Codable {
public typealias ID = String
public let id: ID
public let endpoint: String
public let serverKey: String
public let alerts: Alerts
enum CodingKeys: String, CodingKey {
case id
case endpoint
case serverKey = "server_key"
case alerts
}
}
}
extension Mastodon.Entity.PushSubscription {
public struct Alerts: Codable {
public let follow: Bool
public let favourite: Bool
public let reblog: Bool
public let mention: Bool
public let poll: Bool?
}
}

View File

@ -0,0 +1,53 @@
//
// Mastodon+Entity+Relationship.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// Relationship
///
/// - Since: 0.6.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/relationship/)
public struct Relationship: Codable {
public typealias ID = String
public let id: ID
public let following: Bool
public let requested: Bool?
public let endorsed: Bool?
public let followedBy: Bool
public let muting: Bool?
public let mutingNotifications: Bool?
public let showingReblogs: Bool?
public let notifying: Bool?
public let blocking: Bool
public let domainBlocking: Bool?
public let blockedBy: Bool?
public let note: String?
enum CodingKeys: String, CodingKey {
case id
case following
case requested
case endorsed
case followedBy = "followed_by"
case muting
case mutingNotifications = "muting_notifications"
case showingReblogs = "showing_reblogs"
case notifying
case blocking
case domainBlocking = "domain_blocking"
case blockedBy = "blocked_by"
case note
}
}
}

View File

@ -0,0 +1,30 @@
//
// Mastodon+Entity+Report.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// Report
///
/// - Since: ?
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/report/)
public struct Report: Codable {
public typealias ID = String
public let id: ID // undocumented
public let actionTaken: Bool? // undocumented
enum CodingKeys: String, CodingKey {
case id
case actionTaken = "action_taken"
}
}
}

View File

@ -0,0 +1,41 @@
//
// Mastodon+Entity+Results.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// Results (v1)
///
/// - Since: ?
/// - Version: 3.0.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/results/)
public struct Results: Codable {
public let accounts: [Account]
public let statuses: [Status]
public let hashtags: [String]
}
}
extension Mastodon.Entity.V2 {
/// Results (v2)
///
/// - Since: 2.4.1
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/results/)
public struct Results: Codable {
public let accounts: [Mastodon.Entity.Account]
public let statuses: [Mastodon.Entity.Status]
public let hashtags: [Mastodon.Entity.Tag]
}
}

View File

@ -0,0 +1,60 @@
//
// Mastodon+Entity+ScheduledStatus.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// ScheduledStatus
///
/// - Since: 2.7.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/scheduledstatus/)
public struct ScheduledStatus: Codable {
public typealias ID = String
public let id: ID
public let scheduledAt: Date
public let params: Parameters
public let mediaAttachments: [Attachment]
}
}
extension Mastodon.Entity.ScheduledStatus {
public struct Parameters: Codable {
public let text: String
public let inReplyToID: Mastodon.Entity.Account.ID?
public let mediaIDs: [Mastodon.Entity.Attachment.ID]?
public let sensitive: Bool?
public let spoilerText: String?
public let visibility: Visibility
public let scheduledAt: Date?
public let poll: Mastodon.Entity.Poll? // undocumented
public let applicationID: String
// public let idempotency: Bool? // undoumented
// public let withRateLimit // undoumented
enum CodingKeys: String, CodingKey {
case text
case inReplyToID = "in_reply_to_id"
case mediaIDs = "media_ids"
case sensitive
case spoilerText = "spoiler_text"
case visibility
case scheduledAt = "scheduled_at"
case poll
case applicationID = "application_id"
}
}
}
extension Mastodon.Entity.ScheduledStatus.Parameters {
public typealias Visibility = Mastodon.Entity.Source.Privacy
}

View File

@ -40,10 +40,32 @@ extension Mastodon.Entity {
}
extension Mastodon.Entity.Source {
public enum Privacy: String, Codable {
public enum Privacy: RawRepresentable, Codable {
case `public`
case unlisted
case `private`
case direct
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "public": self = .public
case "unlisted": self = .unlisted
case "private": self = .private
case "direct": self = .direct
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .public: return "public"
case .unlisted: return "unlisted"
case .private: return "private"
case .direct: return "direct"
case ._other(let value): return value
}
}
}
}

View File

@ -105,10 +105,32 @@ extension Mastodon.Entity {
}
extension Mastodon.Entity.Status {
public enum Visibility: String, Codable {
public enum Visibility: RawRepresentable, Codable {
case `public`
case unlisted
case `private`
case direct
case _other(String)
public init?(rawValue: String) {
switch rawValue {
case "public": self = .public
case "unlisted": self = .unlisted
case "private": self = .private
case "direct": self = .direct
default: self = ._other(rawValue)
}
}
public var rawValue: String {
switch self {
case .public: return "public"
case .unlisted: return "unlisted"
case .private: return "private"
case .direct: return "direct"
case ._other(let value): return value
}
}
}
}

View File

@ -0,0 +1,25 @@
//
// Mastodon+Entity+Token.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import Foundation
extension Mastodon.Entity {
/// Token
///
/// - Since: 0.1.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/29
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/token/)
public struct Token: Codable {
public let accessToken: String
public let tokenType: String
public let scope: String
public let createdAt: Date
}
}

View File

@ -7,7 +7,9 @@
import Foundation
extension Mastodon.Entity { }
extension Mastodon.Entity {
public enum V2 { }
}
// MARK: - Entity Document Template
/// Entity Name