mas/MasKit/StoreSearch.swift

27 lines
776 B
Swift
Raw Normal View History

2018-12-30 06:57:06 +00:00
//
// StoreSearch.swift
// MasKit
//
// Created by Ben Chatelain on 12/29/18.
// Copyright © 2018 mas-cli. All rights reserved.
//
/// Protocol for searching the MAS catalog.
public protocol StoreSearch {
func lookupURLString(forApp: String) -> String?
2019-01-02 05:44:33 +00:00
func lookup(app appId: String) throws -> SearchResult?
2018-12-30 06:57:06 +00:00
}
2019-01-05 00:54:00 +00:00
extension StoreSearch {
/// Builds the lookup URL for an app.
///
/// - Parameter appId: MAS app identifier.
/// - Returns: A string URL for the lookup service or nil if the appId can't be encoded.
public func lookupURLString(forApp appId: String) -> String? {
if let urlEncodedAppId = appId.URLEncodedString {
return "https://itunes.apple.com/lookup?id=\(urlEncodedAppId)"
}
return nil
}
}