Network layer core
Topic | Link | Description |
---|---|---|
Ministry of Digital Transformation of Ukraine | https://thedigital.gov.ua/ | The Official homepage of the Ministry of Digital Transformation of Ukraine |
Diia App | https://diia.gov.ua/ | The Official website for the Diia application |
To install DiiaNetwork using Swift Package Manager you can follow the tutorial published by Apple using the URL for this repo with the current version:
- In Xcode, select “File” → “Add Packages...”
- Enter
https://github.com/diia-open-source/ios-network.git
or you can add the following dependency to your Package.swift
:
.package(url: "https://github.com/diia-open-source/ios-network.git", from: "1.0.0")
Creates and configures Alamofire.Session for the network layer core.
import DiiaNetwork
// Dependencies for networkConfigurator should be defined or confirmed at the project level.
func configureNetwork() {
let networkConfigurator = NetworkConfiguration.default
// Make a dictionary of the following type: [String: ServerTrustEvaluating] using method in the extension that should be defined in the app
let serverTrustPolicies = networkConfigurator.activeServerTrustPolicies()
// Make an instance of AuthorizationInterceptor that conforms to RequestInterceptor from Alamofire
let interceptor: RequestInterceptor = AuthorizationInterceptor()
// Retrieve the logging boolean status based on whether the app is in debug mode
let isLoggingEnabled = Constants.isInDebug
let httpStatusCodeHandler: HTTPStatusCodeHandler = HTTPStatusCodeAdapter()
let jsonDecoderConfig: JSONDecoderConfigProtocol = JSONDecoderConfig()
let responseErrorHandler: ResponseErrorHandler = CrashlyticsErrorRecorder()
let analyticsHandler: AnalyticsNetworkHandler = AnaliticsNetworkAdapter()
networkConfigurator.set(serverTrustPolicies: serverTrustPolicies)
networkConfigurator.set(interceptor: interceptor)
networkConfigurator.set(logging: isLoggingEnabled)
networkConfigurator.set(httpStatusCodeHandler: httpStatusCodeHandler)
networkConfigurator.set(jsonDecoderConfig: jsonDecoderConfig)
networkConfigurator.set(responseErrorHandler: responseErrorHandler)
networkConfigurator.set(analyticsHandler: analyticsHandler)
}
import DiiaNetwork
enum AuthorizationAPI: CommonService {
case getToken(processId: String)
var method: HTTPMethod {
switch self {
case .getToken:
return .get
}
}
var path: String {
switch self {
case .getToken:
return "v1/auth/token"
}
}
var parameters: [String: Any]? {
switch self {
case .getToken(let processId):
return ["processId": processId]
}
}
var host: String {
return Constants.defaultHost
}
var timeoutInterval: TimeInterval {
return Constants.defaultTimeoutInterval
}
var headers: [String: String]? {
return Constants.defaultHeaders
}
var analyticsName: String {
switch self {
case .getToken:
return Constants.NetworkActionKey.getToken.rawValue
}
}
var analyticsAdditionalParameters: String? { return nil }
}
Define an API client for an endpoint that makes data requests using a pre-defined session manager.
import ReactiveKit
import DiiaNetwork
protocol AuthorizationAPIClientProtocol {
func getToken(processId: String) -> Signal<TokenResponse, NetworkError>
}
class AuthorizationAPIClient: ApiClient<AuthorizationAPI>, AuthorizationAPIClientProtocol {
func getToken(processId: String) -> Signal<TokenResponse, NetworkError> {
return request(.getToken(processId: processId))
}
}
In order to run tests and check coverage please follow next steps We use xcov in order to run This guidline provides step-by-step instructions on running xcove locally through a shell script. Discover the process and locate the results conveniently in .html format.
- Install xcov
- go to folder ./Scripts then run
sh xcove_runner.sh
- In order to check coverage report find the file
index.html
in the folder../../xcove_output
.
We use Scripts/.xcovignore
xcov configuration file in order to exclude files that are not going to be covered by unit tests (views, models and so on) from coverage result.
It is used SwiftLint to enforce Swift style and conventions. The app should build and work without it, but if you plan to write code, you are encouraged to install SwiftLint.
You can run SwiftLint manully by running
swiftlint Sources --quiet --reporter html > Scripts/swiftlint_report.html.
You can also set up a Git pre-commit hook to run SwiftLint automatically by copy Scripts/githooks into .git/hooks
The Diia project welcomes contributions into this solution; please refer to the CONTRIBUTING.md file for details
Copyright (C) Diia and all other contributors.
Licensed under the EUPL (the "License"); you may not use this file except in compliance with the License. Re-use is permitted, although not encouraged, under the EUPL, with the exception of source files that contain a different license.
You may obtain a copy of the License at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
Questions regarding the Diia project, the License and any re-use should be directed to modt.opensource@thedigital.gov.ua.