-
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.
Merge pull request #131 from adessoTurkey/feature/SASU0122-ServiceLay…
…erModularization [SASU-0122] - Service Layer Modularization #124
- Loading branch information
Showing
104 changed files
with
1,310 additions
and
551 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
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,26 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "NetworkService", | ||
platforms: [ | ||
.iOS(.v16) | ||
], | ||
products: [ | ||
// Products define the executables and libraries a package produces, making them visible to other packages. | ||
.library( | ||
name: "NetworkService", | ||
targets: ["NetworkService"]), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package, defining a module or a test suite. | ||
// Targets can depend on other targets in this package and products from dependencies. | ||
.target( | ||
name: "NetworkService"), | ||
.testTarget( | ||
name: "NetworkServiceTests", | ||
dependencies: ["NetworkService"]), | ||
] | ||
) |
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
Projects/NetworkService/Sources/NetworkService/Base/NetworkLoader.swift
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,16 @@ | ||
// | ||
// NetworkLoader.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Saglam, Fatih on 10.01.2023. | ||
// Copyright © 2023 Adesso Turkey. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public class NetworkLoader: NetworkLoaderProtocol { | ||
public static let shared = NetworkLoader() | ||
|
||
public var session: URLSessionProtocol = URLSession.shared | ||
public var decoder: JSONDecoder = JSONDecoder() | ||
} |
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
30 changes: 30 additions & 0 deletions
30
Projects/NetworkService/Sources/NetworkService/Configuration/Configuration.swift
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,30 @@ | ||
// | ||
// Configuration.swift | ||
// NetworkService | ||
// | ||
// Created by Abay, Batuhan on 6.12.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
final class Configuration: ConfigurationProtocol { | ||
static var baseURL: String { | ||
let url: String? = try? self.value(for: "base_url") | ||
return url ?? "" | ||
} | ||
|
||
static var coinApiKey: String { | ||
let key: String? = try? self.value(for: "personal_api") | ||
guard let key, !key.isEmpty else { | ||
/// Get your API key from https://www.cryptocompare.com/ | ||
#warning("Please Enter an API Key") | ||
return "" | ||
} | ||
return key | ||
} | ||
|
||
static var webSocketBaseUrl: String { | ||
let url: String? = try? self.value(for: "webSocket_base_url") | ||
return url ?? "" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Projects/NetworkService/Sources/NetworkService/Configuration/ConfigurationError.swift
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,12 @@ | ||
// | ||
// ConfigurationError.swift | ||
// NetworkService | ||
// | ||
// Created by Abay, Batuhan on 6.12.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ConfigurationError: Swift.Error { | ||
case missingKey, invalidValue | ||
} |
29 changes: 29 additions & 0 deletions
29
Projects/NetworkService/Sources/NetworkService/Configuration/ConfigurationProtocol.swift
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,29 @@ | ||
// | ||
// ConfigurationProtocol.swift | ||
// NetworkService | ||
// | ||
// Created by Abay, Batuhan on 6.12.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ConfigurationProtocol {} | ||
|
||
extension ConfigurationProtocol { | ||
static func value<T>(for key: String) throws -> T where T: LosslessStringConvertible { | ||
guard let object = Bundle.main.object(forInfoDictionaryKey: key) else { | ||
throw ConfigurationError.missingKey | ||
} | ||
|
||
switch object { | ||
case let value as T: | ||
return value | ||
case let string as String: | ||
guard let value = T(string) else { fallthrough } | ||
return value | ||
default: | ||
throw ConfigurationError.invalidValue | ||
} | ||
} | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
Projects/NetworkService/Sources/NetworkService/Endpoints/AllCoinEndpoints.swift
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,23 @@ | ||
// | ||
// AllCoinEndpoints.swift | ||
// NetworkService | ||
// | ||
// Created by Abay, Batuhan on 6.12.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
enum AllCoinEndpoints: TargetEndpointProtocol { | ||
case allCoin(limit: Int, unitToBeConverted: String, page: Int) | ||
|
||
private struct Constants { | ||
static let allCoinEndpoint = "top/mktcapfull?limit=%d&tsym=%@&page=%d&api_key=%@" | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .allCoin(let limit, let toConvert, let page): | ||
return BaseEndpoints.base.path + String(format: Constants.allCoinEndpoint, limit, toConvert, page, Configuration.coinApiKey) | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
Projects/NetworkService/Sources/NetworkService/Endpoints/CoinPriceHistoryEndpoints.swift
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,27 @@ | ||
// | ||
// CoinPriceHistoryEndpoints.swift | ||
// NetworkService | ||
// | ||
// Created by Abay, Batuhan on 6.12.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
enum CoinPriceHistoryEndpoints: TargetEndpointProtocol { | ||
case daily(coinCode: String, unitToBeConverted: String, dayLimit: Int, aggregate: Int) | ||
case hourly(coinCode: String, unitToBeConverted: String, hourLimit: Int, aggregate: Int) | ||
|
||
private struct Constants { | ||
static let dailyEndpoint = "v2/histoday?fsym=%@&tsym=%@&limit=%d&aggregate=%d&api_key=%@" | ||
static let hourlyEndpoint = "v2/histohour?fsym=%@&tsym=%@&limit=%d&aggregate=%d&api_key=%@" | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .daily(let coinCode, let unitToBeConverted, let dayLimit, let aggregate): | ||
return BaseEndpoints.base.path + String(format: Constants.dailyEndpoint, coinCode, unitToBeConverted, dayLimit, aggregate, Configuration.coinApiKey) | ||
case .hourly(let coinCode, let unitToBeConverted, let hourLimit, let aggregate): | ||
return BaseEndpoints.base.path + String(format: Constants.hourlyEndpoint, coinCode, unitToBeConverted, hourLimit, aggregate, Configuration.coinApiKey) | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
Projects/NetworkService/Sources/NetworkService/Entities/HTTPMethod.swift
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,9 @@ | ||
import Foundation | ||
|
||
public enum HTTPMethod: String { | ||
case delete = "DELETE" | ||
case get = "GET" | ||
case patch = "PATCH" | ||
case post = "POST" | ||
case put = "PUT" | ||
} |
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
39 changes: 39 additions & 0 deletions
39
Projects/NetworkService/Sources/NetworkService/Extensions/CodableExtensions.swift
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,39 @@ | ||
// | ||
// CodableExtensions.swift | ||
// SampleAppSwiftUI | ||
// | ||
// Created by Alver, Tunay on 5.04.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Encodable { | ||
func encode() -> Data? { | ||
let encoder = JSONEncoder() | ||
encoder.dataEncodingStrategy = .deferredToData | ||
return try? encoder.encode(self) | ||
} | ||
|
||
func encode() -> String? { | ||
let encoder = JSONEncoder() | ||
encoder.dataEncodingStrategy = .deferredToData | ||
if let jsonData = try? encoder.encode(self) { | ||
return String(data: jsonData, encoding: .utf8) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
public extension Decodable { | ||
static func decode(_ data: Data) -> Self? { | ||
let decoder = JSONDecoder() | ||
decoder.dataDecodingStrategy = .deferredToData | ||
return try? decoder.decode(self, from: data) | ||
} | ||
|
||
static func decode(_ data: String) -> Self? { | ||
let decoder = JSONDecoder() | ||
decoder.dataDecodingStrategy = .deferredToData | ||
return try? decoder.decode(self, from: Data(data.utf8)) | ||
} | ||
} |
Oops, something went wrong.