@@ -22,33 +22,6 @@ private class GravatarNotificationWrapper {
2222///
2323extension UIImageView {
2424
25- /// Helper Enum that specifies all of the available Gravatar Image Ratings
26- /// TODO: Convert into a pure Swift String Enum. It's done this way to maintain ObjC Compatibility
27- ///
28- @objc
29- public enum GravatarRatings : Int {
30- case g
31- case pg
32- case r
33- case x
34- case `default`
35-
36- func stringValue( ) -> String {
37- switch self {
38- case . default:
39- fallthrough
40- case . g:
41- return " g "
42- case . pg:
43- return " pg "
44- case . r:
45- return " r "
46- case . x:
47- return " x "
48- }
49- }
50- }
51-
5225 /// Downloads and sets the User's Gravatar, given his email.
5326 /// TODO: This is a convenience method. Please, remove once all of the code has been migrated over to Swift.
5427 ///
@@ -70,7 +43,7 @@ extension UIImageView {
7043 ///
7144 @objc
7245 public func downloadGravatarWithEmail( _ email: String , rating: GravatarRatings = . default, placeholderImage: UIImage = . gravatarPlaceholderImage) {
73- let gravatarURL = gravatarUrl ( for: email, size: gravatarDefaultSize ( ) , rating: rating)
46+ let gravatarURL = Gravatar . gravatarUrl ( for: email, size: gravatarDefaultSize ( ) , rating: rating)
7447
7548 listenForGravatarChanges ( forEmail: email)
7649 downloadImage ( from: gravatarURL, placeholderImage: placeholderImage)
@@ -167,7 +140,7 @@ extension UIImageView {
167140 /// Hope buddah, and the code reviewer, can forgive me for this hack.
168141 ///
169142 @objc public func overrideGravatarImageCache( _ image: UIImage , rating: GravatarRatings , email: String ) {
170- guard let gravatarURL = gravatarUrl ( for: email, size: gravatarDefaultSize ( ) , rating: rating) else {
143+ guard let gravatarURL = Gravatar . gravatarUrl ( for: email, size: gravatarDefaultSize ( ) , rating: rating) else {
171144 return
172145 }
173146
@@ -191,35 +164,6 @@ extension UIImageView {
191164
192165 // MARK: - Private Helpers
193166
194- /// Returns the Gravatar URL, for a given email, with the specified size + rating.
195- ///
196- /// - Parameters:
197- /// - email: the user's email
198- /// - size: required download size
199- /// - rating: image rating filtering
200- ///
201- /// - Returns: Gravatar's URL
202- ///
203- private func gravatarUrl( for email: String , size: Int , rating: GravatarRatings ) -> URL ? {
204- let hash = gravatarHash ( of: email)
205- let targetURL = String ( format: " %@/%@?d=404&s=%d&r=%@ " , Defaults . baseURL, hash, size, rating. stringValue ( ) )
206- return URL ( string: targetURL)
207- }
208-
209- /// Returns the gravatar hash of an email
210- ///
211- /// - Parameter email: the email associated with the gravatar
212- /// - Returns: hashed email
213- ///
214- /// This really ought to be in a different place, like Gravatar.swift, but there's
215- /// lots of duplication around gravatars -nh
216- private func gravatarHash( of email: String ) -> String {
217- return email
218- . lowercased ( )
219- . trimmingCharacters ( in: . whitespaces)
220- . md5Hash ( )
221- }
222-
223167 /// Returns the required gravatar size. If the current view's size is zero, falls back to the default size.
224168 ///
225169 private func gravatarDefaultSize( ) -> Int {
@@ -235,13 +179,12 @@ extension UIImageView {
235179 ///
236180 private struct Defaults {
237181 static let imageSize = 80
238- static let baseURL = " https://gravatar.com/avatar "
239182 static var gravatarWrapperKey = " gravatarWrapperKey "
240183 static let emailKey = " email "
241184 static let imageKey = " image "
242185 }
243186}
244187
245- extension NSNotification . Name {
188+ public extension NSNotification . Name {
246189 static let GravatarImageUpdateNotification = NSNotification . Name ( rawValue: " GravatarImageUpdateNotification " )
247190}
0 commit comments