diff --git a/CHANGELOG.md b/CHANGELOG.md index 46fffac..99b6c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,3 +89,8 @@ _None._ ### Internal Changes - Add this changelog file [#119] + +## 1.16.0 + +- Deprecates some types in favor of the new [Gravatar iOS SDK](https://github.com/Automattic/Gravatar-SDK-iOS) + diff --git a/Sources/WordPressUI/Extensions/Gravatar/Gravatar.swift b/Sources/WordPressUI/Extensions/Gravatar/Gravatar.swift index 3b8525a..c266524 100644 --- a/Sources/WordPressUI/Extensions/Gravatar/Gravatar.swift +++ b/Sources/WordPressUI/Extensions/Gravatar/Gravatar.swift @@ -3,6 +3,7 @@ import Foundation /// Helper Enum that specifies all of the available Gravatar Image Ratings /// TODO: Convert into a pure Swift String Enum. It's done this way to maintain ObjC Compatibility /// +@available(*, deprecated, message: "Use `Rating` from the Gravatar iOS SDK. See: https://github.com/Automattic/Gravatar-SDK-iOS.") @objc public enum GravatarRatings: Int { case g @@ -30,12 +31,14 @@ public enum GravatarRatings: Int { /// Helper Enum that specifies some of the options for default images /// To see all available options, visit : https://en.gravatar.com/site/implement/images/ /// +@available(*, deprecated, message: "Use `DefaultAvatarOption` from the Gravatar iOS SDK. See: https://github.com/Automattic/Gravatar-SDK-iOS.") public enum GravatarDefaultImage: String { case fileNotFound = "404" case mp case identicon } +@available(*, deprecated, message: "Use `AvatarURL` from the Gravatar iOS SDK. See: https://github.com/Automattic/Gravatar-SDK-iOS") public struct Gravatar { fileprivate struct Defaults { static let scheme = "https" @@ -107,13 +110,17 @@ public struct Gravatar { } } +@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.") extension Gravatar: Equatable {} +@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.") public func ==(lhs: Gravatar, rhs: Gravatar) -> Bool { return lhs.canonicalURL == rhs.canonicalURL } +@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.") public extension Gravatar { + @available(*, deprecated, message: "Usage of the deprecated type: Gravatar.") init?(_ url: URL) { guard Gravatar.isGravatarURL(url) else { return nil diff --git a/Sources/WordPressUI/Extensions/UIImageView+Gravatar.swift b/Sources/WordPressUI/Extensions/UIImageView+Gravatar.swift index a00b25d..8fc7beb 100644 --- a/Sources/WordPressUI/Extensions/UIImageView+Gravatar.swift +++ b/Sources/WordPressUI/Extensions/UIImageView+Gravatar.swift @@ -29,6 +29,8 @@ extension UIImageView { /// - email: the user's email /// - rating: expected image rating /// + /// This method uses deprecated types. Please check the deprecation warning in `GravatarRatings`. Also check out the UIImageView extension from the Gravatar iOS SDK as an alternative to download images. See: https://github.com/Automattic/Gravatar-SDK-iOS. + @available(*, deprecated, message: "Usage of the deprecated type: GravatarRatings.") @objc public func downloadGravatarWithEmail(_ email: String, rating: GravatarRatings) { downloadGravatarWithEmail(email, rating: rating, placeholderImage: .gravatarPlaceholderImage) @@ -40,7 +42,8 @@ extension UIImageView { /// - email: the user's email /// - rating: expected image rating /// - placeholderImage: Image to be used as Placeholder - /// + /// This method uses deprecated types. Please check the deprecation warning in `GravatarRatings`. Also check out the UIImageView extension from the Gravatar iOS SDK as an alternative to download images. See: https://github.com/Automattic/Gravatar-SDK-iOS. + @available(*, deprecated, message: "Usage of the deprecated type: GravatarRatings.") @objc public func downloadGravatarWithEmail(_ email: String, rating: GravatarRatings = .default, placeholderImage: UIImage = .gravatarPlaceholderImage) { let gravatarURL = Gravatar.gravatarUrl(for: email, size: gravatarDefaultSize(), rating: rating) @@ -50,7 +53,7 @@ extension UIImageView { } /// Configures the UIImageView to listen for changes to the gravatar it is displaying - private func listenForGravatarChanges(forEmail trackedEmail: String) { + public func listenForGravatarChanges(forEmail trackedEmail: String) { if let currentObersver = gravatarWrapper?.observer { NotificationCenter.default.removeObserver(currentObersver) gravatarWrapper = nil @@ -88,6 +91,8 @@ extension UIImageView { /// - animate: enable/disable fade in animation /// - failure: Callback block to be invoked when an error occurs while fetching the Gravatar image /// + /// This method uses deprecated types. Please check the deprecation warning in `GravatarRatings`. Also check out the UIImageView extension from the Gravatar iOS SDK as an alternative to download images. See: https://github.com/Automattic/Gravatar-SDK-iOS. + @available(*, deprecated, message: "Usage of the deprecated type: Gravatar.") public func downloadGravatar(_ gravatar: Gravatar?, placeholder: UIImage, animate: Bool, failure: ((Error?) -> Void)? = nil) { guard let gravatar = gravatar else { self.image = placeholder @@ -138,6 +143,7 @@ extension UIImageView { /// P.s.: /// Hope buddah, and the code reviewer, can forgive me for this hack. /// + @available(*, deprecated, message: "Usage of the deprecated type: GravatarRatings.") @objc public func overrideGravatarImageCache(_ image: UIImage, rating: GravatarRatings, email: String) { guard let gravatarURL = Gravatar.gravatarUrl(for: email, size: gravatarDefaultSize(), rating: rating) else { return diff --git a/Tests/WordPressUITests/Extensions/GravatarTest.swift b/Tests/WordPressUITests/Extensions/GravatarTest.swift index 7200d9b..c5851fa 100644 --- a/Tests/WordPressUITests/Extensions/GravatarTest.swift +++ b/Tests/WordPressUITests/Extensions/GravatarTest.swift @@ -2,36 +2,42 @@ import XCTest @testable import WordPressUI class GravatarTest: XCTestCase { + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testUnknownGravatarUrlMatchesURLWithSubdomainAndQueryParameters() { let url = URL(string: "https://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=256&r=G")! let gravatar = Gravatar(url) XCTAssertNil(gravatar) } + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testUnknownGravatarUrlMatchesURLWithoutSubdomains() { let url = URL(string: "https://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536")! let gravatar = Gravatar(url) XCTAssertNil(gravatar) } + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testIsUnknownGravatarUrlMatchesURLWithHttpSchema() { let url = URL(string: "http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536")! let gravatar = Gravatar(url) XCTAssertNil(gravatar) } + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testGravatarRejectsIncorrectPath() { let url = URL(string: "http://0.gravatar.com/5b415e3c9c245e557af9f580eeb8760a")! let gravatar = Gravatar(url) XCTAssertNil(gravatar) } + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testGravatarRejectsIncorrectHost() { let url = URL(string: "http://0.argvatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")! let gravatar = Gravatar(url) XCTAssertNil(gravatar) } + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testGravatarRemovesQueryParameters() { let url = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a?d=http://0.gravatar.com/5b415e3c9c245e557af9f580eeb8760a")! let expected = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")! @@ -40,6 +46,7 @@ class GravatarTest: XCTestCase { XCTAssertEqual(gravatar!.canonicalURL, expected) } + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testGravatarForcesHTTPS() { let url = URL(string: "http://0.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")! let expected = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")! @@ -48,6 +55,7 @@ class GravatarTest: XCTestCase { XCTAssertEqual(gravatar!.canonicalURL, expected) } + @available(*, deprecated, message: "Deprecated because of Gravatar usage") func testGravatarAppendsSizeQuery() { let url = URL(string: "http://0.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")! let expected = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a?s=128&d=404")! diff --git a/WordPressUI.podspec b/WordPressUI.podspec index 6187914..d9dcac8 100644 --- a/WordPressUI.podspec +++ b/WordPressUI.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'WordPressUI' - s.version = '1.15.1' + s.version = '1.16.0' s.summary = 'Home of reusable WordPress UI components.' s.description = <<-DESC