Skip to content

Commit

Permalink
Merge pull request #82 from makinosp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
makinosp authored Sep 23, 2024
2 parents c59c5e9 + 3e84739 commit a8f8d08
Show file tree
Hide file tree
Showing 55 changed files with 262 additions and 150 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift

on:
Expand All @@ -15,9 +12,19 @@ on:

jobs:
build:
runs-on: macos-latest
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
swift: ["6"]
steps:
- uses: actions/checkout@v4
- uses: SwiftyLab/setup-swift@a0188eaa95c3af0db72e8697c2f0a91c514da86c
with:
swift-version: ${{ matrix.swift }}
- name: Get Swift version
run: swift --version
- name: Build
run: swift build -v
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![License](https://img.shields.io/github/license/makinosp/vrckit.svg)](https://img.shields.io/github/license/makinosp/vrckit.svg)
[![Release](https://img.shields.io/github/release/makinosp/vrckit.svg)](https://img.shields.io/github/release/makinosp/vrckit.svg)
![Swift](https://img.shields.io/badge/Swift%205.9+-F05138?logo=Swift&logoColor=white)
![Swift](https://img.shields.io/badge/Swift%206.0-F05138?logo=Swift&logoColor=white)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/5a8b6e5463a044e0b2ee948367df127c)](https://app.codacy.com/gh/makinosp/vrckit/dashboard)

A Swift client to interact with the [VRChat API](https://vrchatapi.github.io/).
Expand Down
18 changes: 9 additions & 9 deletions Sources/VRCKit/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import FoundationNetworking
#endif

public final class APIClient {
public final actor APIClient {
typealias HTTPResponse = (data: Data, response: HTTPURLResponse)

private var username: String?
Expand Down Expand Up @@ -90,7 +90,7 @@ public final class APIClient {
}

// Add cookies to the request headers.
request.allHTTPHeaderFields = cookieManager.httpField
request.allHTTPHeaderFields = await cookieManager.httpField

// Add HTTP body and content type if body is provided.
if let body = body {
Expand All @@ -107,21 +107,21 @@ public final class APIClient {

#if canImport(FoundationNetworking)
private func requestWithFoundationNetworking(_ request: URLRequest) async throws -> HTTPResponse {
var requestError: Error?
let httpResponse = await withCheckedContinuation { continuation in
typealias Continuation = CheckedContinuation<HTTPResponse, Error>
return try await withCheckedThrowingContinuation { (continuation: Continuation) in
URLSession.shared.dataTask(with: request) { data, urlResponse, error in
if let error = error {
continuation.resume(throwing: error)
return
}
guard let data = data, let reponse = urlResponse as? HTTPURLResponse else {
requestError = error
continuation.resume(throwing: VRCKitError.invalidResponse)
return
}
continuation.resume(returning: (data, reponse))
}
.resume()
}
if let requestError = requestError {
throw requestError
}
return httpResponse
}

#else
Expand Down
12 changes: 6 additions & 6 deletions Sources/VRCKit/Models/AuthenticationModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
// Created by makinosp on 2024/02/12.
//

public enum VerifyType: String, Codable {
public enum VerifyType: String, Codable, Sendable {
case emailOtp, totp, otp
}

struct ExistsResponse: Codable {
struct ExistsResponse: Codable, Sendable {
let userExists: Bool
}

struct VerifyRequest: Codable {
struct VerifyRequest: Codable, Sendable {
let code: String
}

struct VerifyResponse: Codable {
struct VerifyResponse: Codable, Sendable {
let verified: Bool
}

struct RequiresTwoFactorAuthResponse: Codable {
struct RequiresTwoFactorAuthResponse: Codable, Sendable {
let requiresTwoFactorAuth: [VerifyType]

var requires: VerifyType? {
requiresTwoFactorAuth.first { [.totp, .emailOtp].contains($0) }
}
}

struct VerifyAuthTokenResponse: Codable {
struct VerifyAuthTokenResponse: Codable, Sendable {
let ok: Bool
let token: String
}
6 changes: 3 additions & 3 deletions Sources/VRCKit/Models/CommonModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// Created by makinosp on 2024/08/03.
//

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

public struct SuccessResponse: Codable {
public struct SuccessResponse: Codable, Sendable {
let success: ResponseMessage
}

public struct ErrorResponse: Codable, Error {
public struct ErrorResponse: Codable, Sendable, Error {
let error: ResponseMessage
}
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/EditableUserModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct EditableUserInfo: Codable, Hashable {
public struct EditableUserInfo: Codable, Sendable, Hashable {
public var bio: String
public var bioLinks: [URL]
public var status: UserStatus
Expand Down
8 changes: 4 additions & 4 deletions Sources/VRCKit/Models/FavoriteModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
// Created by makinosp on 2024/02/12.
//

public enum FavoriteType: String, Codable {
public enum FavoriteType: String, Codable, Sendable {
case world, avatar, friend
}

public struct Favorite: Codable, Identifiable {
public struct Favorite: Codable, Sendable, Identifiable {
public let id: String
public let favoriteId: String
public let tags: [String]
public let type: FavoriteType
}

public struct FavoriteDetail: Identifiable {
public struct FavoriteDetail: Sendable, Identifiable {
public let id: String
public let favorites: [Favorite]

Expand All @@ -25,7 +25,7 @@ public struct FavoriteDetail: Identifiable {
}
}

public struct FavoriteGroup: Codable, Identifiable, Hashable {
public struct FavoriteGroup: Codable, Sendable, Identifiable, Hashable {
public let id: String
public let displayName: String
public let name: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/FavoriteWorldModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

struct AnyCodable: Codable {}

public struct FavoriteWorldWrapper {
public struct FavoriteWorldWrapper: Sendable {
public let worlds: [World]
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/VRCKit/Models/FriendModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Friend: ProfileElementRepresentable, LocationRepresentable {
public struct Friend: Sendable, ProfileElementRepresentable, LocationRepresentable {
public let bio: String?
public var bioLinks: SafeDecodingArray<URL>
public let avatarImageUrl: URL?
Expand All @@ -27,7 +27,7 @@ public struct Friend: ProfileElementRepresentable, LocationRepresentable {
public let friendKey: String
}

public struct FriendsLocation: LocationRepresentable {
public struct FriendsLocation: Sendable, LocationRepresentable {
public let location: Location
public let friends: [Friend]
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/ImageResolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by makinosp on 2024/09/02.
//

public enum ImageResolution: Int, CustomStringConvertible {
public enum ImageResolution: Int, Sendable, CustomStringConvertible {
case x256 = 256
case x512 = 512
case x1024 = 1024
Expand Down
10 changes: 5 additions & 5 deletions Sources/VRCKit/Models/InstanceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Instance: Identifiable, Hashable, Decodable {
public struct Instance: Sendable, Identifiable, Hashable, Decodable {
public let active: Bool
public let capacity: Int
public let full: Bool
Expand All @@ -26,21 +26,21 @@ public struct Instance: Identifiable, Hashable, Decodable {
public let userCount: Int
public let world: World

public struct Platforms: Hashable, Codable {
public struct Platforms: Sendable, Hashable, Codable {
public let android: Int
public let ios: Int
public let standalonewindows: Int
}

public enum GroupAccessType: String, Codable {
public enum GroupAccessType: String, Sendable, Codable {
case `public`, plus
}

public enum Region: String, Codable {
public enum Region: String, Sendable, Codable {
case us, use, eu, jp, unknown
}

public enum InstanceType: String, Codable {
public enum InstanceType: String, Sendable, Codable {
case `public`, hidden, friends, `private`, group
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/LanguageTagModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by makinosp on 2024/08/22.
//

public enum LanguageTag: String, Hashable, Codable, CaseIterable {
public enum LanguageTag: String, Hashable, Codable, Sendable, CaseIterable {
case english = "language_eng"
case korean = "language_kor"
case russian = "language_rus"
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/LocationModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by makinosp on 2024/09/08.
//

public enum Location: Hashable {
public enum Location: Sendable, Hashable {
case id(String), `private`, offline, traveling
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/SystemTagModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public enum SystemTag: String, Hashable, Codable {
public enum SystemTag: String, Hashable, Codable, Sendable {
case adminAvatarAccess = "admin_avatar_access"
case adminCanGrantLicenses = "admin_can_grant_licenses"
case adminCannyAccess = "admin_canny_access"
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/TrustRankModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by makinosp on 2024/08/04.
//

public enum TrustRank: Equatable {
public enum TrustRank: Equatable, Sendable {
case trusted, known, user, newUser, visitor, unknown
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/UserDetailModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct UserDetail: ProfileDetailRepresentable, LocationRepresentable {
public struct UserDetail: Sendable, ProfileDetailRepresentable, LocationRepresentable {
public var bio: String?
public var bioLinks: SafeDecodingArray<URL>
public let avatarImageUrl: URL?
Expand Down
8 changes: 4 additions & 4 deletions Sources/VRCKit/Models/UserModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct User: ProfileDetailRepresentable {
public struct User: Sendable, ProfileDetailRepresentable {
public let activeFriends: [String]
public let allowAvatarCopying: Bool
public let bio: String?
Expand Down Expand Up @@ -39,12 +39,12 @@ public struct User: ProfileDetailRepresentable {
public let userLanguageCode: String?
public let presence: Presence

public struct DisplayName: Codable, Hashable {
public struct DisplayName: Codable, Sendable, Hashable {
public let displayName: String
public let updatedAt: Date
}

public enum State: String, Codable {
public enum State: String, Codable, Sendable {
/// User is online in VRChat
case online
/// User is online, but not in VRChat
Expand All @@ -53,7 +53,7 @@ public struct User: ProfileDetailRepresentable {
case offline
}

public struct Presence: Codable, Hashable {
public struct Presence: Codable, Hashable, Sendable {
public let groups: [String]
public let id: String
public let instance: String
Expand Down
4 changes: 2 additions & 2 deletions Sources/VRCKit/Models/UserNoteModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import Foundation

struct UserNoteRequest: Codable {
struct UserNoteRequest: Codable, Sendable {
var targetUserId: String
var note: String
}

public struct UserNoteResponse: Codable, Identifiable {
public struct UserNoteResponse: Codable, Sendable, Identifiable {
public let id: String
public let targetUserId: String
public let note: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/UserPlatformModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by makinosp on 2024/09/02.
//

public enum UserPlatform: String, Codable {
public enum UserPlatform: String, Codable, Sendable {
case android, ios, nativemobile, standalonewindows, web
case blank = ""
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/UserStatusModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by makinosp on 2024/07/20.
//

public enum UserStatus: String, Codable, CaseIterable {
public enum UserStatus: String, Codable, Sendable, CaseIterable {
case joinMe = "join me"
case active
case askMe = "ask me"
Expand Down
2 changes: 1 addition & 1 deletion Sources/VRCKit/Models/UserTagModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by makinosp on 2024/08/04.
//

public struct UserTags: Hashable {
public struct UserTags: Hashable, Sendable {
public var systemTags: [SystemTag]
public var languageTags: [LanguageTag]
public var unknownTags: [String]
Expand Down
4 changes: 2 additions & 2 deletions Sources/VRCKit/Models/WorldModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct World: Codable, Identifiable, Hashable {
public struct World: Codable, Sendable, Identifiable, Hashable {
public let id: String
public let name: String
public let description: String?
Expand All @@ -33,7 +33,7 @@ public struct World: Codable, Identifiable, Hashable {
public let favoriteGroup: String?
public let version: Int?

public enum ReleaseStatus: String, Codable {
public enum ReleaseStatus: String, Codable, Sendable {
case `public`, `private`, hidden, all
}
}
Expand Down
Loading

0 comments on commit a8f8d08

Please sign in to comment.