Skip to content

Instantly share code, notes, and snippets.

@jknthn
Created August 24, 2016 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jknthn/f2a5c2bcd3ebbd59c2d6fe53d8738e76 to your computer and use it in GitHub Desktop.
Save jknthn/f2a5c2bcd3ebbd59c2d6fe53d8738e76 to your computer and use it in GitHub Desktop.
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