Skip to content

Commit

Permalink
Merge pull request #71 from makinosp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
makinosp authored Sep 7, 2024
2 parents eaf7360 + d21827d commit 64a6600
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
5 changes: 2 additions & 3 deletions Sources/VRCKit/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public final class APIClient {

/// Initializes the API client with optional username and password.
public init() {
let domainUrl = "https://api.vrchat.cloud"
baseUrl = "\(domainUrl)/api/1"
cookieManager = CookieManager(domainURL: domainUrl)
baseUrl = "\(Const.apiBaseUrl)/\(Const.apiVersion)"
cookieManager = CookieManager(domainURL: Const.apiBaseUrl)
}

/// Set username and password.
Expand Down
8 changes: 8 additions & 0 deletions Sources/VRCKit/Models/InstanceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public extension Instance {
}
return instanceTypeAlias.description
}

var userPlatforms: [UserPlatform] {
[
platforms.android > 0 ? UserPlatform.android : nil,
platforms.ios > 0 ? UserPlatform.ios : nil,
platforms.standalonewindows > 0 ? UserPlatform.standalonewindows : nil
].compactMap { $0 }
}
}

extension Instance.GroupAccessType {
Expand Down
6 changes: 6 additions & 0 deletions Sources/VRCKit/Models/UserDetailModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ public struct UserDetail: ProfileDetailRepresentable, LocationRepresentable {
public let lastActivity: Date
public let platform: UserPlatform
}

public extension UserDetail {
var url: URL? {
URL(string: [Const.homeBaseUrl, "user", id].joined(separator: "/"))
}
}
3 changes: 3 additions & 0 deletions Sources/VRCKit/Models/UserModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public extension User {
var platform: UserPlatform {
presence.platform
}
var url: URL? {
URL(string: [Const.homeBaseUrl, "user", id].joined(separator: "/"))
}
}

public extension User {
Expand Down
16 changes: 16 additions & 0 deletions Sources/VRCKit/Models/UserPlatformModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,19 @@ public enum UserPlatform: String, Codable {
case android, ios, standalonewindows, web
case blank = ""
}

extension UserPlatform: Identifiable {
public var id: String { self.rawValue }
}

extension UserPlatform: CustomStringConvertible {
public var description: String {
switch self {
case .android: "Android"
case .ios: "iOS"
case .standalonewindows: "PC"
case .web: "Web"
case .blank: ""
}
}
}
4 changes: 2 additions & 2 deletions Sources/VRCKit/Protocols/ImageUrlRepresentableProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public protocol ImageUrlRepresentable {

public extension ImageUrlRepresentable {
func replaceImageUrl(url: URL, resolution: ImageResolution) -> URL? {
guard resolution != .origin, Int(url.lastPathComponent) != nil else { return url }
guard resolution != .origin, let number = Int(url.lastPathComponent), number > 1 else { return url }
var urlString = url.absoluteString
if let range = urlString.range(of: url.lastPathComponent, options: .backwards) {
if let range = urlString.range(of: number.description, options: .backwards) {
urlString.replaceSubrange(range, with: resolution.description)
}
return URL(string: urlString)
Expand Down
12 changes: 12 additions & 0 deletions Sources/VRCKit/Utils/Const.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Const.swift
// VRCKit
//
// Created by makinosp on 2024/09/06.
//

public enum Const {
static let homeBaseUrl = "https://vrchat.com/home"
static let apiBaseUrl = "https://api.vrchat.cloud/api"
static let apiVersion = 1
}

0 comments on commit 64a6600

Please sign in to comment.