Merge branch 'feature/api' into develop

This commit is contained in:
CMK 2021-01-27 14:46:35 +08:00
commit b1f9047104
12 changed files with 217 additions and 11 deletions

View File

@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
3533495136D843E85211E3E2 /* Pods_Mastodon_MastodonUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1B4523A7981F1044DE89C21 /* Pods_Mastodon_MastodonUITests.framework */; };
5D526FE225BE9AC400460CB9 /* MastodonSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 5D526FE125BE9AC400460CB9 /* MastodonSDK */; };
5E44BF88AD33646E64727BCF /* Pods_MastodonTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD92E0F10BDE4FE7C4B999F2 /* Pods_MastodonTests.framework */; };
7A9135D4559750AF07CA9BE4 /* Pods_Mastodon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 602D783BEC22881EBAD84419 /* Pods_Mastodon.framework */; };
DB3D0FF325BAA61700EAA174 /* AlamofireImage in Frameworks */ = {isa = PBXBuildFile; productRef = DB3D0FF225BAA61700EAA174 /* AlamofireImage */; };
@ -76,6 +77,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5D526FE225BE9AC400460CB9 /* MastodonSDK in Frameworks */,
7A9135D4559750AF07CA9BE4 /* Pods_Mastodon.framework in Frameworks */,
DB3D0FF325BAA61700EAA174 /* AlamofireImage in Frameworks */,
);
@ -226,6 +228,7 @@
name = Mastodon;
packageProductDependencies = (
DB3D0FF225BAA61700EAA174 /* AlamofireImage */,
5D526FE125BE9AC400460CB9 /* MastodonSDK */,
);
productName = Mastodon;
productReference = DB427DD225BAA00100D1B89D /* Mastodon.app */;
@ -830,6 +833,10 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
5D526FE125BE9AC400460CB9 /* MastodonSDK */ = {
isa = XCSwiftPackageProductDependency;
productName = MastodonSDK;
};
DB3D0FF225BAA61700EAA174 /* AlamofireImage */ = {
isa = XCSwiftPackageProductDependency;
package = DB3D0FF125BAA61700EAA174 /* XCRemoteSwiftPackageReference "AlamofireImage" */;

View File

@ -18,6 +18,33 @@
"revision": "3e8edbeb75227f8542aa87f90240cf0424d6362f",
"version": "4.1.0"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "8da5c5a4e6c5084c296b9f39dc54f00be146e0fa",
"version": "1.14.2"
}
},
{
"package": "swift-nio-zlib-support",
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
"state": {
"branch": null,
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
"version": "1.0.0"
}
},
{
"package": "SwiftyJSON",
"repositoryURL": "https://github.com/SwiftyJSON/SwiftyJSON.git",
"state": {
"branch": null,
"revision": "2b6054efa051565954e1d2b9da831680026cd768",
"version": "5.0.0"
}
}
]
},

View File

@ -6,11 +6,13 @@
//
import UIKit
import MastodonSDK
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}

View File

@ -14,15 +14,18 @@ let package = Package(
targets: ["MastodonSDK"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "5.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "1.0.0"),
],
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: "MastodonSDK",
dependencies: []
dependencies: [
.product(name: "SwiftyJSON", package: "SwiftyJSON"),
.product(name: "NIOHTTP1", package: "swift-nio"),
]
),
.testTarget(
name: "MastodonSDKTests",

View File

@ -0,0 +1,69 @@
//
// Mastodon+API+App.swift
//
//
// Created by xiaojian sun on 2021/1/25.
//
import Combine
import Foundation
public extension Mastodon.API.App {
static func appEndpointURL(domain: String) -> URL {
return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("apps")
}
struct Application: Codable {
public let id: String
public let name: String
public let website: String?
public let redirectURI: String
public let clientID: String
public let clientSecret: String
public let vapidKey: String
enum CodingKeys: String, CodingKey {
case id
case name
case website
case redirectURI = "redirect_uri"
case clientID = "client_id"
case clientSecret = "client_secret"
case vapidKey = "vapid_key"
}
}
struct CreateAnAppQuery {
public let clientName: String
public let redirectURIs: String
public let scopes: String?
public let website: String?
public init(clientName: String, redirectURIs: String, scopes: String?, website: String?) {
self.clientName = clientName
self.redirectURIs = redirectURIs
self.scopes = scopes
self.website = website
}
var queryItems: [URLQueryItem]? {
var items: [URLQueryItem] = []
items.append(URLQueryItem(name: "client_name", value: clientName))
items.append(URLQueryItem(name: "redirect_uris", value: redirectURIs))
scopes.flatMap {
items.append(URLQueryItem(name: "scopes", value: $0))
}
website.flatMap {
items.append(URLQueryItem(name: "website", value: $0))
}
guard !items.isEmpty else { return nil }
return items
}
}
}

View File

@ -0,0 +1,22 @@
//
// Mastodon+API+Error.swift
//
//
// Created by MainasuK Cirno on 2021/1/26.
//
import Foundation
extension Mastodon.API.Error {
struct ErrorResponse: Codable {
let error: String
let errorDescription: String?
enum CodingKeys: String, CodingKey {
case error
case errorDescription = "error_description"
}
}
}

View File

@ -0,0 +1,30 @@
//
// Mastodon+API.swift
//
//
// Created by xiaojian sun on 2021/1/25.
//
import Foundation
import NIOHTTP1
public extension Mastodon.API {
static func endpointURL(domain: String) -> URL {
return URL(string: "https://" + domain + "/api/v1/")!
}
static let timeoutInterval: TimeInterval = 10
static let decoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
return decoder
}()
static let httpHeaderDateFormatter = ISO8601DateFormatter()
enum Error { }
enum App { }
}

View File

@ -0,0 +1,10 @@
//
// Mastodon+Entity.swift
//
//
// Created by xiaojian sun on 2021/1/25.
//
import Foundation
extension Mastodon.Entity { }

View File

@ -0,0 +1,15 @@
//
// Mastodon.swift
//
//
// Created by xiaojian sun on 2021/1/25.
//
import Foundation
public enum Mastodon {
public enum Request { }
public enum Response { }
public enum API { }
public enum Entity { }
}

View File

@ -1,3 +0,0 @@
struct MastodonSDK {
var text = "Hello, World!"
}

View File

@ -6,7 +6,6 @@ final class MastodonSDKTests: XCTestCase {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(MastodonSDK().text, "Hello, World!")
}
static var allTests = [

View File

@ -3,18 +3,43 @@
## Requirements
- Xcode 12.4+
- Swift 5.3+
- iOS 14.0+
## Setup
We needs the latest version Xcode from App Store. And install Cocoapods for dependency management.
### Setup for M1 Mac
### CocoaPods
CocoaPods may fail to update. Try install fii to fix it.
#### For the Intel Mac
```zsh
# https://github.com/CocoaPods/CocoaPods/issues/10220
# install cocoapods from Homebrew
brew install cocoapods
pod install
```
#### For the M1 Mac
```zsh
# install cocoapods from Homebrew
brew install cocoapods
# pod install may not works on M1 Mac. Fix by install ffi
# ref: https://github.com/CocoaPods/CocoaPods/issues/10220
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install
```
## Start
1. Open `Mastodon.xcworkspace`
2. Wait the Swift Package Dependencies resolved.
2. Check the signing settings make sure choose a team. [More info…](https://help.apple.com/xcode/mac/current/#/dev23aab79b4)
3. Select `Mastodon` scheme and run it.
## Acknowledgements