Skip to content

Commit

Permalink
Merge pull request #123 from tidal-music/ekononenko/add-API-module
Browse files Browse the repository at this point in the history
Add TidalAPI module
  • Loading branch information
e-kononenko authored Oct 23, 2024
2 parents 4688b48 + 348235f commit 69d1cca
Show file tree
Hide file tree
Showing 310 changed files with 52,679 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ let package = Package(
name: "Common",
targets: ["Common"]
),
.library(
name: "TidalAPI",
targets: ["TidalAPI"]
),
],
dependencies: [
.package(url: "https://github.com/groue/GRDB.swift.git", from: "6.27.0"),
Expand Down Expand Up @@ -66,6 +70,16 @@ let package = Package(
.plugin(name: "SwiftLint", package: "SwiftLintPlugin"),
]
),
.target(
name: "TidalAPI",
dependencies: [
.AnyCodable,
.auth
],
plugins: [
.plugin(name: "SwiftLint", package: "SwiftLintPlugin"),
]
),
.testTarget(
name: "CatalogueTests",
dependencies: [
Expand Down Expand Up @@ -163,6 +177,7 @@ extension Target.Dependency {
static let template = byName(name: "Template")
static let eventProducer = byName(name: "EventProducer")
static let catalogue = byName(name: "Catalogue")
static let tidalAPI = byName(name: "TidalAPI")
static let common = byName(name: "Common")
static let auth = byName(name: "Auth")
static let player = byName(name: "Player")
Expand Down
81 changes: 81 additions & 0 deletions Sources/TidalAPI/Config/custom_template/TidalAPI.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif

{{#operations}}
/// This is a wrapper around `{{classname}}` that uses the injected credentialsprovider
/// from `OpenAPIClientAPI.credentialsProvider` to provide a convenience API.
///
/// Usage example:
/// ```swift
/// OpenAPIClientAPI.credentialsProvider = TidalAuth.shared
/// let dataDocument = try await {{classname}}Tidal.getResource()
/// ```
public enum {{classname}}Tidal {
{{#operation}}

{{#allParams}}
{{#isEnum}}

/**
* enum for parameter {{paramName}}
*/
public enum {{enumName}}_{{operationId}}: {{^isContainer}}{{{dataType}}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, CaseIterable{{#useVapor}}, Content{{/useVapor}} {
{{^enumUnknownDefaultCase}}
{{#allowableValues}}
{{#enumVars}}
case {{name}} = {{{value}}}
{{/enumVars}}
{{/allowableValues}}
{{/enumUnknownDefaultCase}}
{{#enumUnknownDefaultCase}}
{{#allowableValues}}
{{#enumVars}}
{{^-last}}
case {{name}} = {{{value}}}
{{/-last}}
{{/enumVars}}
{{/allowableValues}}
{{/enumUnknownDefaultCase}}

func to{{classname}}Enum() -> {{classname}}.{{enumName}}_{{operationId}} {
switch self {
{{^enumUnknownDefaultCase}}
{{#allowableValues}}
{{#enumVars}}
case .{{name}}: return .{{name}}
{{/enumVars}}
{{/allowableValues}}
{{/enumUnknownDefaultCase}}
{{#enumUnknownDefaultCase}}
{{#allowableValues}}
{{#enumVars}}
{{^-last}}
case .{{name}}: return .{{name}}
{{/-last}}
{{/enumVars}}
{{/allowableValues}}
{{/enumUnknownDefaultCase}}
}
}
}
{{/isEnum}}
{{/allParams}}

/**
{{summary}}

{{#params}}
- parameter {{paramName}}: ({{paramLocation}}) {{description}}
{{/params}}
- returns: {{returnType}}
*/
public static func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}[{{classname}}Tidal.{{enumName}}_{{operationId}}]{{/isContainer}}{{^isContainer}}{{classname}}Tidal.{{enumName}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) async throws{{#returnType}} -> {{{returnType}}}{{#returnType}}{{#isResponseOptional}}?{{/isResponseOptional}}{{/returnType}}{{/returnType}} {
return try await RequestHelper.createRequest {
{{classname}}.{{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{#isEnum}}{{paramName}}{{^required}}?{{/required}}.to{{classname}}Enum(){{/isEnum}}{{^isEnum}}{{paramName}}{{/isEnum}}{{^-last}}, {{/-last}}{{/allParams}})
}
}
{{/operation}}
}
{{/operations}}
458 changes: 458 additions & 0 deletions Sources/TidalAPI/Config/custom_template/api.mustache

Large diffs are not rendered by default.

Loading

0 comments on commit 69d1cca

Please sign in to comment.