Skip to content

Commit

Permalink
Swift lint auto fix
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-londar committed Nov 24, 2024
1 parent 69eb571 commit b67a41a
Show file tree
Hide file tree
Showing 136 changed files with 1,015 additions and 1,020 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ class CrowdinContentDeliveryAPI: BaseAPI {
case etag = "Etag"
case ifNoneMatch = "If-None-Match"
}

private typealias CrowdinAPIDataCompletion = ((Data?, URLResponse?, Error?) -> Void)

private let hash: String
private let baseURL = "https://distributions.crowdin.net"

init(hash: String, session: URLSession) {
self.hash = hash
super.init(session: session)
}

init(hash: String) {
self.hash = hash
super.init(session: URLSession.shared)
}

private func manifestURL() -> String {
"\(baseURL)/\(hash)/manifest.json"
}

private func buildURL(filePath: String, timestamp: TimeInterval?) -> String {
if let timestamp = timestamp {
return "\(baseURL)/\(hash)\(filePath)?timestamp=\(String(timestamp))"
} else {
return "\(baseURL)/\(hash)\(filePath)"
}
}
// MARK - General download methods

// MARK: - General download methods
private func getFile(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIDataCompletion) {
let stringURL = buildURL(filePath: filePath, timestamp: timestamp)
var headers: [String: String] = [:]
Expand All @@ -71,8 +71,8 @@ class CrowdinContentDeliveryAPI: BaseAPI {
)
}
}
// MARK - Localization download methods:

// MARK: - Localization download methods:
func getStrings(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIStringsCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, response, error) in
let etag = (response as? HTTPURLResponse)?.allHeaderFields[Strings.etag.rawValue] as? String
Expand All @@ -87,8 +87,8 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}
// MARK - Localization download methods:

// MARK: - Localization download methods:
func getFileData(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIFileDataCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, response, error) in
let etag = (response as? HTTPURLResponse)?.allHeaderFields[Strings.etag.rawValue] as? String
Expand All @@ -99,7 +99,7 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}

func getPlurals(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIPluralsCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, response, error) in
let etag = (response as? HTTPURLResponse)?.allHeaderFields[Strings.etag.rawValue] as? String
Expand All @@ -114,7 +114,7 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}

func getXliff(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIXliffCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, response, error) in
let etag = (response as? HTTPURLResponse)?.allHeaderFields[Strings.etag.rawValue] as? String
Expand All @@ -129,7 +129,7 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}

func getJson(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIStringsCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, response, error) in
let etag = (response as? HTTPURLResponse)?.allHeaderFields[Strings.etag.rawValue] as? String
Expand All @@ -144,8 +144,8 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}
// MARK - Mapping download methods:

// MARK: - Mapping download methods:
func getStringsMapping(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIStringsMappingCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, _, error) in
if let data = data {
Expand All @@ -159,7 +159,7 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}

func getPluralsMapping(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIPluralsMappingCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, _, error) in
if let data = data {
Expand All @@ -173,7 +173,7 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}

func getXliffMapping(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIXliffMappingCompletion) {
self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, _, error) in
if let data = data {
Expand All @@ -187,7 +187,7 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}

func getManifest(completion: @escaping CrowdinAPIManifestCompletion) {
let stringURL = manifestURL()
super.get(url: stringURL) { [weak self] (data, _, error) in
Expand All @@ -204,7 +204,7 @@ class CrowdinContentDeliveryAPI: BaseAPI {
}
}
}

func getManifestSync() -> (response: ManifestResponse?, error: Error?) {
let stringURL = manifestURL()
let result = super.get(url: stringURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct CustomLangugage {
let androidCode: String
let osxCode: String
let osxLocale: String

init(id: String, customLanguage: ManifestResponse.ManifestResponseCustomLangugage) {
self.id = id
self.locale = customLanguage.locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ struct ManifestResponse: Codable {
public let files: [String]
public let timestamp: TimeInterval?
public let languages: [String]?
public let responseCustomLanguages: [String: ManifestResponseCustomLangugage]?
public let responseCustomLanguages: [String: ManifestResponseCustomLangugage]?
public let content: [String: [String]]
public let mapping: [String]

enum CodingKeys: String, CodingKey {
case files
case timestamp
Expand All @@ -23,7 +23,7 @@ struct ManifestResponse: Codable {
case content
case mapping
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
files = try values.decode([String].self, forKey: .files)
Expand All @@ -46,7 +46,7 @@ struct ManifestResponse: Codable {
self.content = content
self.mapping = mapping
}

// MARK: - ManifestResponseCustomLangugage
struct ManifestResponseCustomLangugage: Codable {
let locale: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import Foundation

protocol DataParser {
associatedtype `Type`

static func parse(data: Data) -> Type?
}

class PropertyListDataParser: DataParser {
typealias `Type` = [AnyHashable: Any]

static func parse(data: Data) -> [AnyHashable: Any]? {
var propertyListForamat = PropertyListSerialization.PropertyListFormat.xml
if let dictionary = try? PropertyListSerialization.propertyList(from: data, options: .mutableContainersAndLeaves, format: &propertyListForamat) as? [AnyHashable: Any] {
Expand All @@ -27,7 +27,7 @@ class PropertyListDataParser: DataParser {

class XLIFFDataParser: DataParser {
typealias `Type` = [AnyHashable: Any]

static func parse(data: Data) -> [AnyHashable: Any]? {
if let dictionary = SwiftXMLParser().makeDic(data: data) {
return dictionary
Expand Down
Loading

0 comments on commit b67a41a

Please sign in to comment.