Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit 44306e9

Browse files
authored
Gravatar SDK integration (#156)
* Make listenForGravatarChanges public * Add some notes and deprecation messages * Add more deprecations to make the CI happy * Add more deprecations to make the CI happy * Update version as '1.16.0' * Update changelog --------- Co-authored-by: Pinar Olguc <pinar.olguc@automattic.com>
1 parent da9c158 commit 44306e9

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ _None._
8989
### Internal Changes
9090

9191
- Add this changelog file [#119]
92+
93+
## 1.16.0
94+
95+
- Deprecates some types in favor of the new [Gravatar iOS SDK](https://github.com/Automattic/Gravatar-SDK-iOS)
96+

Sources/WordPressUI/Extensions/Gravatar/Gravatar.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Foundation
33
/// Helper Enum that specifies all of the available Gravatar Image Ratings
44
/// TODO: Convert into a pure Swift String Enum. It's done this way to maintain ObjC Compatibility
55
///
6+
@available(*, deprecated, message: "Use `Rating` from the Gravatar iOS SDK. See: https://github.com/Automattic/Gravatar-SDK-iOS.")
67
@objc
78
public enum GravatarRatings: Int {
89
case g
@@ -30,12 +31,14 @@ public enum GravatarRatings: Int {
3031
/// Helper Enum that specifies some of the options for default images
3132
/// To see all available options, visit : https://en.gravatar.com/site/implement/images/
3233
///
34+
@available(*, deprecated, message: "Use `DefaultAvatarOption` from the Gravatar iOS SDK. See: https://github.com/Automattic/Gravatar-SDK-iOS.")
3335
public enum GravatarDefaultImage: String {
3436
case fileNotFound = "404"
3537
case mp
3638
case identicon
3739
}
3840

41+
@available(*, deprecated, message: "Use `AvatarURL` from the Gravatar iOS SDK. See: https://github.com/Automattic/Gravatar-SDK-iOS")
3942
public struct Gravatar {
4043
fileprivate struct Defaults {
4144
static let scheme = "https"
@@ -107,13 +110,17 @@ public struct Gravatar {
107110
}
108111
}
109112

113+
@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.")
110114
extension Gravatar: Equatable {}
111115

116+
@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.")
112117
public func ==(lhs: Gravatar, rhs: Gravatar) -> Bool {
113118
return lhs.canonicalURL == rhs.canonicalURL
114119
}
115120

121+
@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.")
116122
public extension Gravatar {
123+
@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.")
117124
init?(_ url: URL) {
118125
guard Gravatar.isGravatarURL(url) else {
119126
return nil

Sources/WordPressUI/Extensions/UIImageView+Gravatar.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extension UIImageView {
2929
/// - email: the user's email
3030
/// - rating: expected image rating
3131
///
32+
/// 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.
33+
@available(*, deprecated, message: "Usage of the deprecated type: GravatarRatings.")
3234
@objc
3335
public func downloadGravatarWithEmail(_ email: String, rating: GravatarRatings) {
3436
downloadGravatarWithEmail(email, rating: rating, placeholderImage: .gravatarPlaceholderImage)
@@ -40,7 +42,8 @@ extension UIImageView {
4042
/// - email: the user's email
4143
/// - rating: expected image rating
4244
/// - placeholderImage: Image to be used as Placeholder
43-
///
45+
/// 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.
46+
@available(*, deprecated, message: "Usage of the deprecated type: GravatarRatings.")
4447
@objc
4548
public func downloadGravatarWithEmail(_ email: String, rating: GravatarRatings = .default, placeholderImage: UIImage = .gravatarPlaceholderImage) {
4649
let gravatarURL = Gravatar.gravatarUrl(for: email, size: gravatarDefaultSize(), rating: rating)
@@ -50,7 +53,7 @@ extension UIImageView {
5053
}
5154

5255
/// Configures the UIImageView to listen for changes to the gravatar it is displaying
53-
private func listenForGravatarChanges(forEmail trackedEmail: String) {
56+
public func listenForGravatarChanges(forEmail trackedEmail: String) {
5457
if let currentObersver = gravatarWrapper?.observer {
5558
NotificationCenter.default.removeObserver(currentObersver)
5659
gravatarWrapper = nil
@@ -88,6 +91,8 @@ extension UIImageView {
8891
/// - animate: enable/disable fade in animation
8992
/// - failure: Callback block to be invoked when an error occurs while fetching the Gravatar image
9093
///
94+
/// 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.
95+
@available(*, deprecated, message: "Usage of the deprecated type: Gravatar.")
9196
public func downloadGravatar(_ gravatar: Gravatar?, placeholder: UIImage, animate: Bool, failure: ((Error?) -> Void)? = nil) {
9297
guard let gravatar = gravatar else {
9398
self.image = placeholder
@@ -138,6 +143,7 @@ extension UIImageView {
138143
/// P.s.:
139144
/// Hope buddah, and the code reviewer, can forgive me for this hack.
140145
///
146+
@available(*, deprecated, message: "Usage of the deprecated type: GravatarRatings.")
141147
@objc public func overrideGravatarImageCache(_ image: UIImage, rating: GravatarRatings, email: String) {
142148
guard let gravatarURL = Gravatar.gravatarUrl(for: email, size: gravatarDefaultSize(), rating: rating) else {
143149
return

Tests/WordPressUITests/Extensions/GravatarTest.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,42 @@ import XCTest
22
@testable import WordPressUI
33

44
class GravatarTest: XCTestCase {
5+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
56
func testUnknownGravatarUrlMatchesURLWithSubdomainAndQueryParameters() {
67
let url = URL(string: "https://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=256&r=G")!
78
let gravatar = Gravatar(url)
89
XCTAssertNil(gravatar)
910
}
1011

12+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
1113
func testUnknownGravatarUrlMatchesURLWithoutSubdomains() {
1214
let url = URL(string: "https://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536")!
1315
let gravatar = Gravatar(url)
1416
XCTAssertNil(gravatar)
1517
}
1618

19+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
1720
func testIsUnknownGravatarUrlMatchesURLWithHttpSchema() {
1821
let url = URL(string: "http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536")!
1922
let gravatar = Gravatar(url)
2023
XCTAssertNil(gravatar)
2124
}
2225

26+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
2327
func testGravatarRejectsIncorrectPath() {
2428
let url = URL(string: "http://0.gravatar.com/5b415e3c9c245e557af9f580eeb8760a")!
2529
let gravatar = Gravatar(url)
2630
XCTAssertNil(gravatar)
2731
}
2832

33+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
2934
func testGravatarRejectsIncorrectHost() {
3035
let url = URL(string: "http://0.argvatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")!
3136
let gravatar = Gravatar(url)
3237
XCTAssertNil(gravatar)
3338
}
3439

40+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
3541
func testGravatarRemovesQueryParameters() {
3642
let url = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a?d=http://0.gravatar.com/5b415e3c9c245e557af9f580eeb8760a")!
3743
let expected = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")!
@@ -40,6 +46,7 @@ class GravatarTest: XCTestCase {
4046
XCTAssertEqual(gravatar!.canonicalURL, expected)
4147
}
4248

49+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
4350
func testGravatarForcesHTTPS() {
4451
let url = URL(string: "http://0.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")!
4552
let expected = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")!
@@ -48,6 +55,7 @@ class GravatarTest: XCTestCase {
4855
XCTAssertEqual(gravatar!.canonicalURL, expected)
4956
}
5057

58+
@available(*, deprecated, message: "Deprecated because of Gravatar usage")
5159
func testGravatarAppendsSizeQuery() {
5260
let url = URL(string: "http://0.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a")!
5361
let expected = URL(string: "https://secure.gravatar.com/avatar/5b415e3c9c245e557af9f580eeb8760a?s=128&d=404")!

WordPressUI.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'WordPressUI'
5-
s.version = '1.15.1'
5+
s.version = '1.16.0'
66

77
s.summary = 'Home of reusable WordPress UI components.'
88
s.description = <<-DESC

0 commit comments

Comments
 (0)