-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Swift Open Api generated methods
- Loading branch information
1 parent
68929c5
commit fef55de
Showing
10 changed files
with
455 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// Copyright © 2023 Alexander Romanov | ||
// NetworkService.swift, created on 30.06.2023 | ||
// | ||
import OpenAPIURLSession | ||
import OversizeServices | ||
|
||
public struct NetworkService { | ||
let client = Client( | ||
serverURL: try! Servers.server1(), | ||
transport: URLSessionTransport() | ||
) | ||
|
||
public init() {} | ||
|
||
public func fetchApps() async -> Result<[Components.Schemas.AppShort], AppError> { | ||
do { | ||
let response = try await client.fetchApps(.init()) | ||
switch response { | ||
case let .ok(okResponse): | ||
switch okResponse.body { | ||
case let .json(apps): | ||
return .success(apps) | ||
} | ||
case .undocumented: | ||
return .failure(.network(type: .unexpectedStatusCode)) | ||
case .notFound: | ||
return .failure(.network(type: .invalidURL)) | ||
} | ||
} catch { | ||
return .failure(.network(type: .unknown)) | ||
} | ||
} | ||
|
||
public func fetchInfo() async -> Result<Components.Schemas.Info, AppError> { | ||
do { | ||
let response = try await client.fetchInfo(.init()) | ||
switch response { | ||
case let .ok(okResponse): | ||
switch okResponse.body { | ||
case let .json(info): | ||
return .success(info) | ||
} | ||
case .undocumented: | ||
return .failure(.network(type: .unexpectedStatusCode)) | ||
case .notFound: | ||
return .failure(.network(type: .invalidURL)) | ||
} | ||
} catch { | ||
return .failure(.network(type: .unknown)) | ||
} | ||
} | ||
|
||
public func fetchAppById(appId: String) async -> Result<Components.Schemas.AppDetail, AppError> { | ||
do { | ||
let response = try await client.fetchAppById(.init(path: .init(appId: appId))) | ||
switch response { | ||
case let .ok(okResponse): | ||
switch okResponse.body { | ||
case let .json(info): | ||
return .success(info) | ||
} | ||
case .undocumented: | ||
return .failure(.network(type: .unexpectedStatusCode)) | ||
case .notFound: | ||
return .failure(.network(type: .invalidURL)) | ||
} | ||
} catch { | ||
return .failure(.network(type: .unknown)) | ||
} | ||
} | ||
|
||
public func fetchAds() async -> Result<[Components.Schemas.Ad], AppError> { | ||
do { | ||
let response = try await client.fetchAds(.init()) | ||
switch response { | ||
case let .ok(okResponse): | ||
switch okResponse.body { | ||
case let .json(ads): | ||
return .success(ads) | ||
} | ||
case .undocumented: | ||
return .failure(.network(type: .unexpectedStatusCode)) | ||
case .notFound: | ||
return .failure(.network(type: .invalidURL)) | ||
} | ||
} catch { | ||
return .failure(.network(type: .unknown)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.