Skip to content

Commit

Permalink
refact: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
makinosp committed Aug 3, 2024
1 parent 7e03caa commit 7c65820
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 47 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
}
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 }
}
4 changes: 3 additions & 1 deletion Sources/VRCKit/Models/UserDetailModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ public struct EditableUserInfo: Codable, Hashable {
public var status: UserStatus
public var statusDescription: String
public var tags: [Tag]
}

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: 1 addition & 3 deletions Sources/VRCKit/Models/UserStatus.swift
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 }
}
6 changes: 4 additions & 2 deletions Sources/VRCKit/Utils/OptionalISO8601Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import Foundation
public struct OptionalISO8601Date {
private let date: Date?
private let formatter = DateFormatter.iso8601Full
}

public init(date: Date? = nil) {
self.date = date
public extension OptionalISO8601Date {
init() {
date = nil
}
}

Expand Down

0 comments on commit 7c65820

Please sign in to comment.