Skip to content

Commit

Permalink
rename function and remove typealias
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhoffmann committed Jan 22, 2021
1 parent 71d2eb1 commit 246a4a5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions AEPServices/Sources/network/DefaultHeadersFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import Foundation
///
public struct DefaultHeadersFormatter {

typealias httpHeaderConstants = HttpConnectionConstants.Header

///
/// Gets the formatted locale
/// - Parameter unformattedLocale: The unformatted locale as a string
/// - Returns: The formatted locale as a string or nil if not able to format it.
///
public static func getFormattedLocale(unformattedLocale: String) -> String {
public static func formatLocale(_ unformattedLocale: String) -> String {
// "^" // beginning of line
// "([a-zA-Z]{2,3})" // language (required) (match group 1)
// "(?:(?:-|_)[a-zA-Z]{3})?" // extlang (optional)
Expand Down
2 changes: 1 addition & 1 deletion AEPServices/Sources/network/NetworkRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Foundation

let systemInfoService = ServiceProvider.shared.systemInfoService
let defaultHeaders = [NetworkRequest.REQUEST_HEADER_KEY_USER_AGENT: systemInfoService.getDefaultUserAgent(),
HttpConnectionConstants.Header.HTTP_HEADER_KEY_ACCEPT_LANGUAGE: DefaultHeadersFormatter.getFormattedLocale(unformattedLocale: systemInfoService.getActiveLocaleName())]
HttpConnectionConstants.Header.HTTP_HEADER_KEY_ACCEPT_LANGUAGE: DefaultHeadersFormatter.formatLocale(systemInfoService.getActiveLocaleName())]
self.httpHeaders = defaultHeaders.merging(httpHeaders) { _, new in new } // add in default headers and apply `httpHeaders` on top

self.connectTimeout = connectTimeout
Expand Down
4 changes: 2 additions & 2 deletions AEPServices/Tests/services/DefaultHeadersFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class DefaultHeadersFormatterTest: XCTestCase {
return
}

let formattedLocale = DefaultHeadersFormatter.getFormattedLocale(unformattedLocale: v)
let formattedLocale = DefaultHeadersFormatter.formatLocale(v)

XCTAssertEqual(k, formattedLocale)
}
}

func testEmptyLocale() {
let formattedLocale = DefaultHeadersFormatter.getFormattedLocale(unformattedLocale: "")
let formattedLocale = DefaultHeadersFormatter.formatLocale("")
XCTAssertEqual("en-US", formattedLocale)
}
}
Expand Down

0 comments on commit 246a4a5

Please sign in to comment.