feat: add some entities and make it pass unit tests

This commit is contained in:
CMK 2021-01-28 19:28:37 +08:00
parent f8718510a6
commit 4c9e644820
12 changed files with 469 additions and 1 deletions

View File

@ -0,0 +1,25 @@
//
// Mastodon+Entity+Activity.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// Activity
///
/// - Since: 2.1.2
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/activity/)
public struct Activity: Codable {
public let week: Date
public let statuses: Int
public let logins: Int
public let registrations: Int
}
}

View File

@ -0,0 +1,52 @@
//
// Mastodon+Entity+Announcement.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// Announcement
///
/// - Since: 3.1.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/announcement/)
public struct Announcement: Codable {
public typealias ID = String
// Base
public let id: ID
public let text: String
public let published: Bool?
public let allDay: Bool
public let createdAt: Date
public let updatedAt: Date
public let read: Bool
public let reactions: [AnnouncementReaction]
public let scheduledAt: Date?
public let startsAt: Date?
public let endsAt: Date?
enum CodingKeys: String, CodingKey {
case id
case text
case published
case allDay
case createdAt = "created_at"
case updatedAt = "updated_at"
case read
case reactions
case scheduledAt = "scheduled_at"
case startsAt = "starts_at"
case endsAt
}
}
}

View File

@ -0,0 +1,37 @@
//
// Mastodon+Entity+AnnouncementReaction.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// AnnouncementReaction
///
/// - Since: 3.1.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/announcementreaction/)
public struct AnnouncementReaction: Codable {
// Base
public let name: String
public let count: Int
public let me: Bool
// Custom Emoji
public let url: String?
public let staticURL: String?
enum CodingKeys: String, CodingKey {
case name
case count
case me
case url
case staticURL = "static_url"
}
}
}

View File

@ -0,0 +1,124 @@
//
// Mastodon+Entity+Attachment.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// Attachment
///
/// - Since: 0.6.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/attachment/)
public struct Attachment: Codable {
public typealias ID = String
public let id: ID
public let type: Type?
public let url: String
public let previewURL: String
public let remoteURL: String?
public let textURL: String?
public let meta: Meta?
public let description: String?
public let blurhash: String?
enum CodingKeys: String, CodingKey {
case id
case type
case url
case previewURL = "preview_url"
case remoteURL = "remote_url"
case textURL = "text_url"
case meta
case description
case blurhash
}
}
}
extension Mastodon.Entity.Attachment {
public enum `Type`: String, Codable {
case unknown
case image
case gifv
case video
case audio
}
}
extension Mastodon.Entity.Attachment {
/// # Reference
/// https://github.com/tootsuite/mastodon/blob/v3.3.0/app/models/media_attachment.rb
public struct Meta: Codable {
public let original: Format?
public let small: Format?
public let focus: Focus?
public let length: String?
public let duration: Double?
public let fps: Int?
public let size: String?
public let width: Int?
public let height: Int?
public let aspect: Double?
public let audioEncode: String?
public let audioBitrate: String?
public let audioChannels: String?
enum CodingKeys: String, CodingKey {
case original
case small
case focus
case length
case duration
case fps
case size
case width
case height
case aspect
case audioEncode = "audio_encode"
case audioBitrate = "audio_bitrate"
case audioChannels = "audio_channels"
}
}
}
extension Mastodon.Entity.Attachment.Meta {
public struct Format: Codable {
public let width: Int?
public let height: Int?
public let size: String?
public let aspect: Double?
public let frameRate: String?
public let duration: Double?
public let bitrate: Int?
enum CodingKeys: String, CodingKey {
case width
case height
case size
case aspect
case frameRate = "frame_rate"
case duration
case bitrate
}
}
public struct Focus: Codable {
public let x: Double
public let y: Double
}
}

View File

@ -0,0 +1,23 @@
//
// Mastodon+Entity+Context.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// Context
///
/// - Since: 0.6.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/context/)
public struct Context: Codable {
public let ancestors: [Status]
public let descendants: [Status]
}
}

View File

@ -0,0 +1,36 @@
//
// Mastodon+Entity+Conversation.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// Conversation
///
/// - Since: 2.6.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/conversation/)
public struct Conversation: Codable {
public typealias ID = String
public let id: ID
public let accounts: [Account]
public let unread: Bool
public let lastStatus: Status?
enum CodingKeys: String, CodingKey {
case id
case accounts
case unread
case lastStatus = "last_status"
}
}
}

View File

@ -0,0 +1,36 @@
//
// Mastodon+Entity+FeaturedTag.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// FeaturedTag
///
/// - Since: 3.0.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/featuredtag/)
public struct FeaturedTag: Codable {
public typealias ID = String
public let id: ID
public let name: String
public let url: String?
public let statusesCount: Int
public let lastStatusAt: Date
enum CodingKeys: String, CodingKey {
case id
case name
case url
case statusesCount = "statuses_count"
case lastStatusAt = "last_status_at"
}
}
}

View File

@ -0,0 +1,47 @@
//
// Mastodon+Entity+Filter.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// Field
///
/// - Since: 2.4.3
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/filter/)
public struct Filter: Codable {
public typealias ID = String
public let id: ID
public let phrase: String
public let context: [Context?]
public let expiresAt: Date
public let irreversible: Bool
public let wholeWord: Bool
enum CodingKeys: String, CodingKey {
case id
case phrase
case context
case expiresAt = "expires_at"
case irreversible
case wholeWord = "whole_word"
}
}
}
extension Mastodon.Entity.Filter {
public enum Context: String, Codable {
case home
case notifications
case `public`
case thread
}
}

View File

@ -0,0 +1,34 @@
//
// Mastodon+Entity+IdentityProof.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// IdentityProof
///
/// - Since: 2.8.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/identityproof/)
public struct IdentityProof: Codable {
public let provider: String
public let providerUsername: String
public let profileURL: String
public let proofURL: String
public let updatedAt: Date
enum CodingKeys: String, CodingKey {
case provider = "provider"
case providerUsername = "provider_username"
case profileURL = "profile_url"
case proofURL = "proof_url"
case updatedAt = "updated_at"
}
}
}

View File

@ -0,0 +1,40 @@
//
// Mastodon+Entity+List.swift
//
//
// Created by MainasuK Cirno on 2021/1/28.
//
import Foundation
extension Mastodon.Entity {
/// List
///
/// - Since: 2.1.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/1/28
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/list/)
public struct List: Codable {
public typealias ID = String
public let id: ID
public let title: String
public let repliesPolicy: ReplyPolicy?
enum CodingKeys: String, CodingKey {
case id
case title
case repliesPolicy = "replies_policy"
}
}
}
extension Mastodon.Entity {
public enum ReplyPolicy: String, Codable {
case followed
case list
case none
}
}

View File

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

View File

@ -31,9 +31,10 @@ extension Mastodon.Entity {
public let account: Account
public let content: String
public let visibility: String?
public let visibility: Visibility?
public let sensitive: Bool?
public let spoilerText: String?
public let mediaAttachments: [Attachment]
public let application: Application?
// Rendering
@ -73,6 +74,7 @@ extension Mastodon.Entity {
case visibility
case sensitive
case spoilerText = "spoiler_text"
case mediaAttachments = "media_attachments"
case application
case mentions