Add UserAgent.headers() function — otherwise that code was duplicated in a couple places.

This commit is contained in:
Brent Simmons 2017-10-07 12:34:12 -07:00
parent fa0d355ab0
commit 07e6ff5572

View File

@ -8,9 +8,9 @@
import Foundation
public class UserAgent {
public struct UserAgent {
public class func fromInfoPlist() -> String? {
public static func fromInfoPlist() -> String? {
guard let userAgentName = Bundle.main.object(forInfoDictionaryKey: "UserAgent") else {
return nil
@ -20,4 +20,13 @@ public class UserAgent {
}
return "\(userAgentName) \(version)"
}
public static func headers() -> [AnyHashable: String]? {
guard let userAgent = fromInfoPlist() else {
return nil
}
return [HTTPRequestHeader.userAgent: userAgent]
}
}