Created
August 24, 2016 13:55
-
-
Save jknthn/f2a5c2bcd3ebbd59c2d6fe53d8738e76 to your computer and use it in GitHub Desktop.
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
import Foundation | |
struct MarvelURL { | |
private let ts = Int(Date().timeIntervalSinceReferenceDate) | |
private let privateKey = Bundle.main.object(forInfoDictionaryKey: "MarvelPrivateKey")! | |
private let publicKey = "3e2e1997fd3ada9d85d651c8627d1052" | |
let urlString: String | |
func authorized() -> URL { | |
let timeStamp = "ts=\(ts)" | |
let apiKey = "apikey=" + publicKey | |
let hash = "hash=" + "\(ts)\(privateKey)\(publicKey)".md5 | |
let authorizedString = urlString + "?" + [timeStamp, apiKey, hash].joined(separator: "&") | |
guard let url = URL(string: authorizedString) else { | |
fatalError("Programer error") | |
} | |
return url | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment