Skip to content

Instantly share code, notes, and snippets.

@jppsantos
Last active September 26, 2020 23:53
Show Gist options
  • Save jppsantos/683c58178347fb9528e25047c7e58ccf to your computer and use it in GitHub Desktop.
Save jppsantos/683c58178347fb9528e25047c7e58ccf to your computer and use it in GitHub Desktop.
enum PurchaseEndpoint {
private var baseURL: String { return "https://www.purchase.com" }
case product
case user
case shop
case payment
case productWith(UUID)
case userWith(UUID)
case shopWith(UUID)
case paymentWith(UUID)
private var fullPath: String {
var endpoint:String
switch self {
case .productWith(let id):
endpoint = "/product/\(id.uuidString)"
case .userWith(let id):
endpoint = "/user/\(id.uuidString)"
case .shopWith(let id):
endpoint = "/store/\(id.uuidString)"
case .paymentWith(let id):
endpoint = "/payment/\(id.uuidString)"
default:
endpoint = "/\(String(describing: self))"
}
return baseURL + endpoint
}
var url: URL {
guard let url = URL(string: fullPath) else {
preconditionFailure("The url used in \(PurchaseEndpoint.self) is not valid")
}
return url
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment