Skip to content

Commit

Permalink
Merge pull request #65 from makinosp/develop
Browse files Browse the repository at this point in the history
feat: UserTags
  • Loading branch information
makinosp authored Aug 4, 2024
2 parents fd8281e + 2ad4e8e commit a8340f4
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 102 deletions.
19 changes: 2 additions & 17 deletions Sources/VRCKit/Client.swift → Sources/VRCKit/APIClient.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
import Foundation
//
// Client.swift
// APIClient.swift
// VRCKit
//
// Created by makinosp on 2024/02/12.
//

public struct ResponseMessage: Codable {
let message: String
let statusCode: Int
}

public struct SuccessResponse: Codable {
let success: ResponseMessage
}

public struct ErrorResponse: Codable, Error {
let error: ResponseMessage
}
import Foundation

//
// MARK: API Client
//
public final class APIClient {
typealias HTTPResponse = (data: Data, response: HTTPURLResponse)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public extension KeyedDecodingContainer {
/// - key: The key that the decoded value is associated with.
/// - Returns: A `SafeDecodingArray` of the specified type.
/// - Throws: Rethrows any errors encountered during decoding.
func decodeSafeNullableArray<T>(
_ type: T.Type,
func decodeSafeNullableArray<Element>(
_ type: Element.Type,
forKey key: KeyedDecodingContainer<K>.Key
) throws -> SafeDecodingArray<T> where T: Decodable {
try decodeIfPresent(SafeDecodingArray<T>.self, forKey: key) ?? SafeDecodingArray()
) throws -> SafeDecodingArray<Element> where Element: Decodable {
try decodeIfPresent(SafeDecodingArray<Element>.self, forKey: key) ?? SafeDecodingArray()
}
}
19 changes: 19 additions & 0 deletions Sources/VRCKit/Models/CommonModels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CommonModels.swift
// VRCKit
//
// Created by makinosp on 2024/08/03.
//

public struct ResponseMessage: Codable {
let message: String
let statusCode: Int
}

public struct SuccessResponse: Codable {
let success: ResponseMessage
}

public struct ErrorResponse: Codable, Error {
let error: ResponseMessage
}
8 changes: 3 additions & 5 deletions Sources/VRCKit/Models/FriendModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import Foundation

extension Friend: ProfileElementRepresentable, LocationRepresentable {}

public struct Friend {
public struct Friend: ProfileElementRepresentable, LocationRepresentable {
public let bio: String?
public var bioLinks: SafeDecodingArray<URL>
public let avatarImageUrl: URL?
Expand All @@ -22,7 +20,7 @@ public struct Friend {
public let profilePicOverride: URL?
public let status: UserStatus
public let statusDescription: String
public let tags: [Tag]
public let tags: UserTags
public let userIcon: URL?
public let location: String
public let friendKey: String
Expand All @@ -43,7 +41,7 @@ extension Friend: Codable {
profilePicOverride = try? container.decodeIfPresent(URL.self, forKey: .profilePicOverride)
status = try container.decode(UserStatus.self, forKey: .status)
statusDescription = try container.decode(String.self, forKey: .statusDescription)
tags = try container.decode([Tag].self, forKey: .tags)
tags = try container.decode(UserTags.self, forKey: .tags)
userIcon = try? container.decodeIfPresent(URL.self, forKey: .userIcon)
location = try container.decode(String.self, forKey: .location)
friendKey = try container.decode(String.self, forKey: .friendKey)
Expand Down
46 changes: 26 additions & 20 deletions Sources/VRCKit/Models/InstanceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct Instance: Identifiable, Hashable, Codable {
public let recommendedCapacity: Int
public let region: Region
public let tags: [String]
public let type: WorldType
public let type: InstanceType
public let userCount: Int
public let world: World

Expand All @@ -38,40 +38,46 @@ public struct Instance: Identifiable, Hashable, Codable {
case us, use, eu, jp, unknown
}

public enum WorldType: String, Codable {
case `public`
case hidden
case friends
case `private`
case group
public enum InstanceType: String, Codable {
case `public`, hidden, friends, `private`, group
}
}

public enum InstanceType: String, CustomStringConvertible {
public extension Instance {
enum InstanceTypeDescription: String {
case `public` = "Public"
case friendsPlus = "Friends+"
case friends = "Friends"
case `private` = "Private"
case group = "Group"
case groupPlus = "Group+"
case groupPublic = "Group Public"

public var description: String {
rawValue
}
}

public var instanceType: InstanceType {
switch self.type {
var instanceTypeDescription: InstanceTypeDescription {
switch type {
case .public: .public
case .hidden: .friendsPlus
case .friends: .friends
case .private: .private
case .group:
switch self.groupAccessType {
case .plus: .groupPlus
case .public: .groupPublic
default: .group
}
case .group: groupAccessType?.instanceTypeDescription ?? .group
}
}
}

extension Instance.GroupAccessType {
var instanceTypeDescription: Instance.InstanceTypeDescription {
switch self {
case .public: .groupPublic
case .plus: .groupPlus
}
}
}

extension Instance.InstanceType: CustomStringConvertible {
public var description: String { rawValue }
}

extension Instance.InstanceTypeDescription: CustomStringConvertible {
public var description: String { rawValue }
}
77 changes: 77 additions & 0 deletions Sources/VRCKit/Models/TagModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// TagModel.swift
// VRCKit
//
// Created by makinosp on 2024/08/03.
//

import Foundation

public enum SystemTag: String, Hashable, Codable {
case adminAvatarAccess = "admin_avatar_access"
case adminCanGrantLicenses = "admin_can_grant_licenses"
case adminCannyAccess = "admin_canny_access"
case adminLockTags = "admin_lock_tags"
case adminLockLevel = "admin_lock_level"
case adminModerator = "admin_moderator"
case adminOfficialThumbnail = "admin_official_thumbnail"
case adminScriptingAccess = "admin_scripting_access"
case adminWorldAccess = "admin_world_access"
case showSocialRank = "show_social_rank"
case showModTag = "show_mod_tag"
case systemAvatarAccess = "system_avatar_access"
case systemEarlyAdopter = "system_early_adopter"
case systemFeedbackAccess = "system_feedback_access"
case systemNoCaptcha = "system_no_captcha"
case systemProbableTroll = "system_probable_troll"
case systemSupporter = "system_supporter"
case systemTroll = "system_troll"
case systemTrustBasic = "system_trust_basic"
case systemTrustKnown = "system_trust_known"
case systemTrustTrusted = "system_trust_trusted"
case systemTrustVeteran = "system_trust_veteran"
case systemWorldAccess = "system_world_access"
}

public enum LanguageTag: String, Hashable, Codable {
case english = "language_eng"
case korean = "language_kor"
case russian = "language_rus"
case spanish = "language_spa"
case portuguese = "language_por"
case chinese = "language_zho"
case german = "language_deu"
case japanese = "language_jpn"
case french = "language_fra"
case swedish = "language_swe"
case dutch = "language_nld"
case polish = "language_pol"
case danish = "language_dan"
case norwegian = "language_nor"
case italian = "language_ita"
case thai = "language_tha"
case finnish = "language_fin"
case hungarian = "language_hun"
case czech = "language_ces"
case turkish = "language_tur"
case arabic = "language_ara"
case romanian = "language_ron"
case vietnamese = "language_vie"
case bahasaIndonesia = "language_ind"
case bahasaMelayu = "language_msa"
case filipino = "language_fil"
case mandarinChinese = "language_cmn"
case hebrew = "language_heb"
case hmong = "language_hmn"
case ukrainian = "language_ukr"
case tokiPona = "language_tok"
case yueChinese = "language_yue"
case wuChinese = "language_wuu"
case americanSignLanguage = "language_ase"
case britishSignLanguage = "language_bfi"
case dutchSignLanguage = "language_dse"
case frenchSignLanguage = "language_fsl"
case japaneseSignLanguage = "language_jsl"
case koreanSignLanguage = "language_kvk"
case noLinguisticContent = "language_zxx"
}
30 changes: 0 additions & 30 deletions Sources/VRCKit/Models/URLString.swift

This file was deleted.

18 changes: 8 additions & 10 deletions Sources/VRCKit/Models/UserDetailModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

import Foundation

extension UserDetail: ProfileDetailRepresentable, LocationRepresentable {}

public typealias Tag = String

public struct UserDetail {
public struct UserDetail: ProfileDetailRepresentable, LocationRepresentable {
public var bio: String?
public var bioLinks: SafeDecodingArray<URL>
public let avatarImageUrl: URL?
Expand All @@ -25,7 +21,7 @@ public struct UserDetail {
public let state: User.State
public let status: UserStatus
public var statusDescription: String
public var tags: [Tag]
public var tags: UserTags
public let userIcon: URL?
public let location: String
public let friendKey: String
Expand All @@ -35,7 +31,7 @@ public struct UserDetail {
}

extension UserDetail: Codable {
public init(from decoder: any Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
bio = try container.decodeIfPresent(String.self, forKey: .bio)
bioLinks = try container.decodeSafeNullableArray(URL.self, forKey: .bioLinks)
Expand All @@ -50,7 +46,7 @@ extension UserDetail: Codable {
state = try container.decode(User.State.self, forKey: .state)
status = try container.decode(UserStatus.self, forKey: .status)
statusDescription = try container.decode(String.self, forKey: .statusDescription)
tags = try container.decode([Tag].self, forKey: .tags)
tags = try container.decode(UserTags.self, forKey: .tags)
userIcon = try? container.decodeIfPresent(URL.self, forKey: .userIcon)
location = try container.decode(String.self, forKey: .location)
friendKey = try container.decode(String.self, forKey: .friendKey)
Expand Down Expand Up @@ -90,9 +86,11 @@ public struct EditableUserInfo: Codable, Hashable {
public var bioLinks: [URL]
public var status: UserStatus
public var statusDescription: String
public var tags: [Tag]
public var tags: UserTags
}

public init(detail: any ProfileDetailRepresentable) {
public extension EditableUserInfo {
init(detail: any ProfileDetailRepresentable) {
bio = detail.bio ?? ""
bioLinks = detail.bioLinks.elements
status = detail.status
Expand Down
4 changes: 2 additions & 2 deletions Sources/VRCKit/Models/UserModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct User: ProfileDetailRepresentable {
public let state: State
public let status: UserStatus
public let statusDescription: String
public let tags: [Tag]
public let tags: UserTags
public let twoFactorAuthEnabled: Bool
public let userIcon: URL?
public let userLanguage: String?
Expand Down Expand Up @@ -80,7 +80,7 @@ extension User: Codable {
state = try container.decode(User.State.self, forKey: .state)
status = try container.decode(UserStatus.self, forKey: .status)
statusDescription = try container.decode(String.self, forKey: .statusDescription)
tags = try container.decode([Tag].self, forKey: .tags)
tags = try container.decode(UserTags.self, forKey: .tags)
twoFactorAuthEnabled = try container.decode(Bool.self, forKey: .twoFactorAuthEnabled)
userIcon = try? container.decodeIfPresent(URL.self, forKey: .userIcon)
userLanguage = try container.decodeIfPresent(String.self, forKey: .userLanguage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ extension UserStatus: CustomStringConvertible {
}

extension UserStatus: Identifiable {
public var id: Int {
self.hashValue
}
public var id: Int { hashValue }
}
Loading

0 comments on commit a8340f4

Please sign in to comment.