Skip to content

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
sinoru committed Jul 20, 2022
2 parents 2ad0225 + a97b01f commit baa9209
Show file tree
Hide file tree
Showing 30 changed files with 1,274 additions and 33 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: SwiftLint

on:
push:
paths:
- '.github/workflows/swiftlint.yml'
- '.swiftlint.yml'
- '**/*.swift'

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: sinoru/actions-setup-swift@v2
with:
swift-version: '5.6.2'
- uses: sinoru/actions-swiftlint@v6
with:
swiftlint-version: '809dcc6bdcf40b35fc23c01086fa884f84ad9473'
65 changes: 65 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test

on:
push:
paths:
- '.github/workflows/test.yml'
- '**/*.swift'
pull_request:
paths:
- '.github/workflows/test.yml'
- '**/*.swift'

jobs:
swift-test:
strategy:
fail-fast: true
matrix:
operating-system: ["macos-11", "macos-12", "ubuntu-18.04", "ubuntu-20.04"]
swift-version: ["5.5.3", "5.6.2"]
runs-on: ${{ matrix.operating-system }}
steps:
- uses: actions/checkout@v2
- uses: sinoru/actions-setup-xcode@v2
if: ${{ startsWith(matrix.operating-system, 'macos') }}
with:
xcode-version: "13.2.1"
apple-id: ${{ secrets.APPLE_ID }}
apple-id-password: ${{ secrets.APPLE_ID_PASSWORD }}
- uses: sinoru/actions-setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- name: Build
run: swift build
env:
SWIFT_VERSION: ${{ matrix.swift-version }}
- name: Run tests
run: swift test
env:
SWIFT_VERSION: ${{ matrix.swift-version }}
xcode-test:
strategy:
fail-fast: true
matrix:
xcode-version: ["13.2.1", "13.4.1"]
xcode-destination: [
"platform=OS X,arch=x86_64",
"platform=OS X,arch=x86_64,variant=Mac Catalyst",
"platform=iOS Simulator,name=iPhone 12 Pro,OS=latest",
"platform=tvOS Simulator,name=Apple TV,OS=latest",
"platform=watchOS Simulator,name=Apple Watch Series 6 - 44mm,OS=latest",
]
runs-on: macos-12
steps:
- uses: actions/checkout@v2
- uses: sinoru/actions-setup-xcode@v2
with:
xcode-version: ${{ matrix.xcode-version }}
apple-id: ${{ secrets.APPLE_ID }}
apple-id-password: ${{ secrets.APPLE_ID_PASSWORD }}
- name: Resolve Package Dependencies
run: xcodebuild -resolvePackageDependencies
- name: Analyze
run: xcodebuild -scheme swift-discord -destination '${{ matrix.xcode-destination }}' analyze
- name: Test
run: xcodebuild -scheme swift-discord -destination '${{ matrix.xcode-destination }}' test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ playground.xcworkspace
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm
.swiftpm

.build/

Expand Down
49 changes: 49 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
disabled_rules:
- trailing_comma
opt_in_rules:
- anyobject_protocol
- array_init
- capture_variable
- collection_alignment
- contains_over_filter_count
- contains_over_filter_is_empty
- empty_collection_literal
- empty_string

file_length:
ignore_comment_only_lines: true

function_body_length:
warning: 50
error: 125

identifier_name:
min_length:
warning: 2
error: 1
max_length:
warning: 80
error: 100
allowed_symbols:
- '_'

line_length:
warning: 160
error: 240
ignores_comments: true

nesting:
type_level: 2
function_level: 3

type_name:
min_length:
warning: 2
error: 1
max_length:
warning: 80
error: 100
allowed_symbols:
- '_'
excluded:
- ''
7 changes: 0 additions & 7 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

This file was deleted.

25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "swift-collections",
"repositoryURL": "https://github.com/apple/swift-collections.git",
"state": {
"branch": null,
"revision": "48254824bb4248676bf7ce56014ff57b142b77eb",
"version": "1.0.2"
}
},
{
"package": "swift-snowflake",
"repositoryURL": "https://github.com/sinoru/swift-snowflake",
"state": {
"branch": null,
"revision": "440fa7765e90066a25da535b8b493a5c47bbafb6",
"version": "0.0.1"
}
}
]
},
"version": 1
}
35 changes: 28 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
// swift-tools-version: 5.6
// swift-tools-version: 5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "swift-discord",
platforms: [
.macOS(.v10_15),
.macCatalyst(.v13),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "swift-discord",
targets: ["swift-discord"]),
name: "Discord",
targets: ["DiscordV10", "Discord"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/sinoru/swift-snowflake", .upToNextMinor(from: "0.0.1")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "swift-discord",
dependencies: []),
name: "DiscordV10",
dependencies: ["Discord"]),
.target(
name: "Discord",
dependencies: [
.product(name: "Collections", package: "swift-collections"),
.product(name: "Snowflake", package: "swift-snowflake")
]),
.target(
name: "_DiscordTestSupport",
dependencies: ["Discord"]),
.testTarget(
name: "DiscordV10Tests",
dependencies: ["DiscordV10", "_DiscordTestSupport"]),
.testTarget(
name: "swift-discordTests",
dependencies: ["swift-discord"]),
name: "DiscordTests",
dependencies: ["Discord", "_DiscordTestSupport"]),
]
)
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# swift-discord
# swift-discord

[![Test](https://github.com/swift-discord/swift-discord/actions/workflows/test.yml/badge.svg)](https://github.com/swift-discord/swift-discord/actions/workflows/test.yml)

A Swift library for Discord API.

## Using **swift-discord** in your project

To use this package in a SwiftPM project, you need to set it up as a package dependency:

```swift
// swift-tools-version:5.5
import PackageDescription

let package = Package(
name: "MyPackage",
dependencies: [
.package(
url: "https://github.com/swift-discord/swift-discord.git",
.upToNextMajor(from: "0.0.1") // or `.upToNextMinor
)
],
targets: [
.target(
name: "MyTarget",
dependencies: [
.product(name: "DiscordV10", package: "swift-discord")
]
)
]
)
```
8 changes: 8 additions & 0 deletions Sources/Discord/Discord.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Discord.swift
//
//
// Created by Jaehong Kang on 2022/07/21.
//

@_exported import Snowflake
27 changes: 27 additions & 0 deletions Sources/Discord/Extensions/Foundation+JSONDecoder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Foundation+JSONDecoder.swift
//
//
// Created by Jaehong Kang on 2022/07/20.
//

import Foundation
import Snowflake

extension JSONDecoder {
static var oAuth2: JSONDecoder {
let jsonDecoder = JSONDecoder()
jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase

return jsonDecoder
}

public static var discord: JSONDecoder {
let jsonDecoder = JSONDecoder()
jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase
jsonDecoder.dateDecodingStrategy = .iso8601
jsonDecoder.snowflakeDecodingStrategy = .auto

return jsonDecoder
}
}
27 changes: 27 additions & 0 deletions Sources/Discord/Extensions/Foundation+JSONEncoder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Foundation+JSONEncoder.swift
//
//
// Created by Jaehong Kang on 2022/07/20.
//

import Foundation
import Snowflake

extension JSONEncoder {
static var oAuth2: JSONEncoder {
let jsonEncoder = JSONEncoder()
jsonEncoder.keyEncodingStrategy = .convertToSnakeCase

return jsonEncoder
}

public static var discord: JSONEncoder {
let jsonEncoder = JSONEncoder()
jsonEncoder.keyEncodingStrategy = .convertToSnakeCase
jsonEncoder.dateEncodingStrategy = .iso8601
jsonEncoder.snowflakeEncodingStrategy = .string

return jsonEncoder
}
}
21 changes: 21 additions & 0 deletions Sources/Discord/Extensions/Foundation+URL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Foundation+URL.swift
//
//
// Created by Jaehong Kang on 2022/07/20.
//

import Foundation

extension URL {
public static let discordAPIBaseURL: URL = URL(string: "https://discord.com/api")!

public init?(discordAPIPath: String) {
self.init(
string: discordAPIPath,
relativeTo: Self.discordAPIBaseURL
.deletingLastPathComponent()
.appendingPathComponent(Self.discordAPIBaseURL.lastPathComponent, isDirectory: true)
)
}
}
35 changes: 35 additions & 0 deletions Sources/Discord/Extensions/Foundation+URLSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Foundation+URLSession.swift
//
//
// Created by Jaehong Kang on 2022/07/21.
//

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

extension URLSession {
@available(iOS, deprecated: 15.0, renamed: "data(for:delegate:)")
@available(macOS, deprecated: 13.0, renamed: "data(for:delegate:)")
@available(macCatalyst, deprecated: 15.0, renamed: "data(for:delegate:)")
@available(tvOS, deprecated: 15.0, renamed: "data(for:delegate:)")
@available(watchOS, deprecated: 8.0, renamed: "data(for:delegate:)")
@inline(__always)
func _data(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<(Data, URLResponse), Error>) in
dataTask(with: request) { data, response, error in
guard
let data = data,
let response = response
else {
continuation.resume(throwing: error!)
return
}

continuation.resume(returning: (data, response))
}.resume()
}
}
}
Loading

0 comments on commit baa9209

Please sign in to comment.