Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev to master #64

Merged
merged 22 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c89c981
[feat] add a method for fileURL download to DownloadAPIManaging
matejmolnar Dec 19, 2023
09f80f1
[chore] move method to an extension
matejmolnar Dec 19, 2023
a2861cd
[feat] simplify UploadAPIManager usage
matejmolnar Dec 20, 2023
009f486
[feat] remove UploadService and simplify Upload example
matejmolnar Dec 21, 2023
862c2d6
[feat] unify download and upload UI
matejmolnar Dec 21, 2023
8bd2bdc
[feat] Move extension to a new file
matejmolnar Dec 21, 2023
ffe198a
[chore] code format
matejmolnar Dec 21, 2023
551a3b2
[chore] fix filename
matejmolnar Jan 2, 2024
e3a1877
[chore] fix swiftlint warning
matejmolnar Jan 2, 2024
f8d6aa8
[chore] change import order
matejmolnar Jan 2, 2024
9dfe860
[feat] replace onAppear with task
matejmolnar Jan 8, 2024
437aaf1
[feat] add separate files for basic routers
matejmolnar Jan 8, 2024
701bd89
Merge branch 'dev' into feat/downloads-uploads-simplification
cejanen Jan 16, 2024
ec70c53
Merge branch 'feat/downloads-uploads-simplification' of github.com:st…
cejanen Jan 16, 2024
337da1f
Merge pull request #59 from strvcom/feat/downloads-uploads-simplifica…
matejmolnar Jan 23, 2024
47093eb
[feat] add swift setting flag to enable docc extension symbol links
matejmolnar Jan 22, 2024
b8650d3
[feat] documentation updates
matejmolnar Jan 22, 2024
1354c77
[chore] remove unnecessary pragma marks
matejmolnar Jan 22, 2024
36afa70
[feat] update documentation
matejmolnar Jan 23, 2024
646971a
[feat] generate static web documentation
matejmolnar Jan 23, 2024
daead52
[feat] update readme
matejmolnar Jan 23, 2024
9687308
Merge pull request #63 from strvcom/feat/web-hosted-docs
matejmolnar Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
54 changes: 19 additions & 35 deletions NetworkingSampleApp/NetworkingSampleApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Foundation
enum SampleAPIConstants {
static let userHost = "https://reqres.in/api"
static let authHost = "https://nonexistentmockauth.com/api"
// swiftlint:disable:next force_https
static let uploadHost = "https://httpbin.org"
// swiftlint:disable:next force_unwrapping force_https
static let uploadURL = URL(string: "https://httpbin.org/post")!
static let validEmail = "eve.holt@reqres.in"
static let validPassword = "cityslicka"
static let videoUrl = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import Networking
import Foundation

final class SampleAuthorizationManager: AuthorizationManaging {
// MARK: Public properties
let storage: AuthorizationStorageManaging = SampleAuthorizationStorageManager()
// MARK: Private properties
/// For refresh token logic we create new instance of APIManager without injecting `AuthorizationTokenInterceptor` to avoid cycling in refreshes
/// We use mock data to simulate real API requests here

// For refresh token logic we create new instance of APIManager without
// injecting `AuthorizationTokenInterceptor` in order to avoid cycling in refreshes.
// We use mock data to simulate real API requests here.
private let apiManager: APIManager = {
APIManager(
responseProvider: MockResponseProvider(with: Bundle.main, sessionId: "2023-01-31T15:08:08Z"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// URLSessionTask.State+Convenience.swift
// NetworkingSampleApp
//
// Created by Matej Molnár on 21.12.2023.
//

import Foundation

extension URLSessionTask.State {
var title: String {
switch self {
case .canceling: "cancelling"
case .completed: "completed"
case .running: "running"
case .suspended: "suspended"
@unknown default: ""
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// UploadAPIManager+SharedInstance.swift
// NetworkingSampleApp
//
// Created by Matej Molnár on 21.12.2023.
//

import Networking

extension UploadAPIManager {
static var shared: UploadAPIManaging = {
var responseProcessors: [ResponseProcessing] = [
LoggingInterceptor.shared,
StatusCodeProcessor.shared
]
var errorProcessors: [ErrorProcessing] = [LoggingInterceptor.shared]

#if DEBUG
responseProcessors.append(EndpointRequestStorageProcessor.shared)
errorProcessors.append(EndpointRequestStorageProcessor.shared)
#endif

return UploadAPIManager(
urlSessionConfiguration: .default,
requestAdapters: [
LoggingInterceptor.shared
],
responseProcessors: responseProcessors,
errorProcessors: errorProcessors
)
}()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,41 @@ import Foundation
import Networking

@MainActor
final class DownloadProgressViewModel: ObservableObject {
final class DownloadProgressViewModel: TaskProgressViewModel {
private let task: URLSessionTask

@Published var state: DownloadProgressState = .init()

let isRetryable = false
private(set) var title: String = ""
private(set) var status: String = ""
private(set) var downloadedBytes: String = ""
private(set) var state: URLSessionTask.State = .running
private(set) var percentCompleted: Double = 0

init(task: URLSessionTask) {
self.task = task
}

func startObservingDownloadProgress() async {
func onAppear() async {
let stream = DownloadAPIManager.shared.progressStream(for: task)

for try await downloadState in stream {
var newState = DownloadProgressState()
newState.percentCompleted = downloadState.fractionCompleted * 100
newState.downloadedBytes = ByteCountFormatter.megaBytesFormatter.string(fromByteCount: downloadState.downloadedBytes)
newState.status = downloadState.taskState
newState.statusTitle = downloadState.taskState.title
newState.errorTitle = downloadState.error?.localizedDescription
newState.fileURL = downloadState.downloadedFileURL?.absoluteString
newState.title = task.currentRequest?.url?.absoluteString ?? "-"
state = newState
title = task.currentRequest?.url?.absoluteString ?? "-"
percentCompleted = downloadState.fractionCompleted * 100
downloadedBytes = ByteCountFormatter.megaBytesFormatter.string(fromByteCount: downloadState.downloadedBytes)
state = downloadState.taskState
status = {
if let error = downloadState.error {
return "Error: \(error.localizedDescription)"
}

if let downloadedFileURL = downloadState.downloadedFileURL {
return "Downloaded at: \(downloadedFileURL.absoluteString)"
}

return downloadState.taskState.title
}()

objectWillChange.send()
}
}

Expand All @@ -45,28 +58,6 @@ final class DownloadProgressViewModel: ObservableObject {
func cancel() {
task.cancel()
}
}

// MARK: Download state
struct DownloadProgressState {
var title: String = ""
var status: URLSessionTask.State = .running
var statusTitle: String = ""
var percentCompleted: Double = 0
var downloadedBytes: String = ""
var errorTitle: String?
var fileURL: String?
}

// MARK: URLSessionTask states
private extension URLSessionTask.State {
var title: String {
switch self {
case .canceling: "cancelling"
case .completed: "completed"
case .running: "running"
case .suspended: "suspended"
@unknown default: ""
}
}
func retry() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct DownloadsView: View {
Section("Active downloads") {
List {
ForEach(viewModel.tasks, id: \.taskIdentifier) { task in
DownloadProgressView(viewModel: .init(task: task))
TaskProgressView(viewModel: DownloadProgressViewModel(task: task))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private extension DownloadsViewModel {

do {
let (task, _) = try await downloadAPIManager.downloadRequest(
SampleDownloadRouter.download(url: url),
url,
resumableData: nil,
retryConfiguration: RetryConfiguration.default
)
Expand Down

This file was deleted.

Loading
Loading