Skip to content
Browse files

default image support added

  • Loading branch information...
1 parent d73f1e7 commit fc792fcf6c2ec0e02816662a30b9b8cc4e8fa95e Magnus Ernstsson committed Oct 29, 2010
View
41 Impl/GravatarUIImageFactory.m
@@ -47,7 +47,7 @@ -(void)setConnection:(NSURLConnection *)newConnection {
#pragma mark -
#pragma mark Internal implementation
-#pragma mark - Class
+#pragma mark - Class
+(NSString *)md5:(NSString *)str {
const char *cStr = [str UTF8String];
@@ -157,50 +157,67 @@ -(void)cancelRequest {
[self cleanUp];
}
--(void)requestUIImageByEmail:(NSString *)anEmail {
+-(void)requestUIImageByEmail:(NSString *)anEmail
+ defaultImage:(NSString *)defaultImage {
self.email = anEmail;
[self requestUIImageByGravatarId:[GravatarUIImageFactory
- calculateGravatarId:anEmail]];
+ calculateGravatarId:anEmail]
+ defaultImage:defaultImage];
}
--(void)requestUIImageByEmail:(NSString *)anEmail size:(NSInteger)size {
+-(void)requestUIImageByEmail:(NSString *)anEmail
+ defaultImage:(NSString *)defaultImage
+ size:(NSInteger)size {
self.email = anEmail;
[self requestUIImageByGravatarId:[GravatarUIImageFactory
- calculateGravatarId:anEmail] size:size];
+ calculateGravatarId:anEmail]
+ defaultImage:defaultImage
+ size:size];
}
--(void)requestUIImageByGravatarId:(NSString *)gravatarId size:(NSInteger) size {
+-(void)requestUIImageByGravatarId:(NSString *)gravatarId
+ defaultImage:(NSString *)defaultImage
+ size:(NSInteger)size {
self.gravatarid = gravatarId;
- if ((size > 0) && size < 512) {
+ if ((size > 0) && (size < 512)) {
[self makeRequest:
- [NSString stringWithFormat:@"http://www.gravatar.com/avatar/%@?s=%i",
- gravatarId, size]];
+ [NSString stringWithFormat:@"http://www.gravatar.com/avatar/%@?s=%i&d=%@",
+ gravatarId, size, defaultImage]];
} else {
[self handleErrorWithCode:GravatarServerArgumentError];
}
}
--(void)requestUIImageByGravatarId:(NSString *)gravatarId {
+-(void)requestUIImageByGravatarId:(NSString *)gravatarId
+ defaultImage:(NSString *)defaultImage {
self.gravatarid = gravatarId;
[self makeRequest:
- [NSString stringWithFormat:@"http://www.gravatar.com/avatar/%@",
- gravatarId]];
+ [NSString stringWithFormat:@"http://www.gravatar.com/avatar/%@&d=%@",
+ gravatarId, defaultImage]];
}
#pragma mark - Class
NSString * const GravatarServerErrorDomain = @"GravatarServerErrorDomain";
+NSString * const gravatarServerImageDefault = @"";
+NSString * const gravatarServerImage404 = @"404";
+NSString * const gravatarServerImageMysteryMan = @"mm";
+NSString * const gravatarServerImageIdenticon = @"identicon";
+NSString * const gravatarServerImageMonsterId = @"monsterid";
+NSString * const gravatarServerImageWavatar = @"wavatar";
+NSString * const gravatarServerImageRetro = @"retro";
+
+(GravatarUIImageFactory *)gravatarUIImageFactoryWithDelegate:
(id<GravatarServiceDelegate>)delegate {
View
10 Interface/GravatarService.h
@@ -26,4 +26,12 @@ typedef enum {
GravatarServerServerError = 3,
GravatarServerArgumentError = 4,
GravatarServerConnectionError = 5,
-} GravatarServerError;
+} GravatarServerError;
+
+extern NSString * const gravatarServerImageDefault;
+extern NSString * const gravatarServerImage404;
+extern NSString * const gravatarServerImageMysteryMan;
+extern NSString * const gravatarServerImageIdenticon;
+extern NSString * const gravatarServerImageMonsterId;
+extern NSString * const gravatarServerImageWavatar;
+extern NSString * const gravatarServerImageRetro;
View
16 Interface/GravatarServiceFactory.h
@@ -16,17 +16,21 @@
}
+(id<GravatarService>)requestUIImageByGravatarId:(NSString *)gravtarId
- size:(NSInteger)size
- delegate:(id<GravatarServiceDelegate>)delegate;
+defaultImage:(NSString *)defaultImage
+size:(NSInteger)size
+delegate:(id<GravatarServiceDelegate>)delegate;
+(id<GravatarService>)requestUIImageByGravatarId:(NSString *)gravtarId
- delegate:(id<GravatarServiceDelegate>)delegate;
+defaultImage:(NSString *)defaultImage
+delegate:(id<GravatarServiceDelegate>)delegate;
+(id<GravatarService>)requestUIImageByEmail:(NSString *)gravtarId
- size:(NSInteger)size
- delegate:(id<GravatarServiceDelegate>)delegate;
+defaultImage:(NSString *)defaultImage
+size:(NSInteger)size
+delegate:(id<GravatarServiceDelegate>)delegate;
+(id<GravatarService>)requestUIImageByEmail:(NSString *)gravtarId
- delegate:(id<GravatarServiceDelegate>)delegate;
+defaultImage:(NSString *)defaultImage
+delegate:(id<GravatarServiceDelegate>)delegate;
@end
View
12 Interface/GravatarServiceFactory.m
@@ -16,49 +16,57 @@ @implementation GravatarServiceFactory
#pragma mark - Class
+(id<GravatarService>)requestUIImageByGravatarId:(NSString *)gravtarId
+ defaultImage:(NSString *)defaultImage
size:(NSInteger)size
delegate:(id<GravatarServiceDelegate>)delegate {
GravatarUIImageFactory *service = [GravatarUIImageFactory
gravatarUIImageFactoryWithDelegate:delegate];
[service requestUIImageByGravatarId:gravtarId
+ defaultImage:defaultImage
size:size];
return service;
}
+(id<GravatarService>)requestUIImageByGravatarId:(NSString *)gravtarId
+ defaultImage:(NSString *)defaultImage
delegate:(id<GravatarServiceDelegate>)delegate {
GravatarUIImageFactory *service = [GravatarUIImageFactory
gravatarUIImageFactoryWithDelegate:delegate];
- [service requestUIImageByGravatarId:gravtarId];
+ [service requestUIImageByGravatarId:gravtarId
+ defaultImage:defaultImage];
return service;
}
+(id<GravatarService>)requestUIImageByEmail:(NSString *)gravtarId
+ defaultImage:(NSString *)defaultImage
size:(NSInteger)size
delegate:(id<GravatarServiceDelegate>)delegate {
GravatarUIImageFactory *service = [GravatarUIImageFactory
gravatarUIImageFactoryWithDelegate:delegate];
[service requestUIImageByEmail:gravtarId
+ defaultImage:defaultImage
size:size];
return service;
}
+(id<GravatarService>)requestUIImageByEmail:(NSString *)gravtarId
+ defaultImage:(NSString *)defaultImage
delegate:(id<GravatarServiceDelegate>)delegate {
GravatarUIImageFactory *service = [GravatarUIImageFactory
gravatarUIImageFactoryWithDelegate:delegate];
- [service requestUIImageByEmail:gravtarId];
+ [service requestUIImageByEmail:gravtarId
+ defaultImage:defaultImage];
return service;
}
View
14 Interface/GravatarUIImageFactory.h
@@ -31,12 +31,18 @@
+(GravatarUIImageFactory *)gravatarUIImageFactoryWithDelegate:
(id<GravatarServiceDelegate>)delegate;
--(void)requestUIImageByGravatarId:(NSString *)gravatarId size:(NSInteger)size;
+-(void)requestUIImageByGravatarId:(NSString *)gravatarId
+ defaultImage:(NSString *)defaultImage
+ size:(NSInteger)size;
--(void)requestUIImageByGravatarId:(NSString *)gravatarId;
+-(void)requestUIImageByGravatarId:(NSString *)gravatarId
+ defaultImage:(NSString *)defaultImage;
--(void)requestUIImageByEmail:(NSString *)gravatarId size:(NSInteger)size;
+-(void)requestUIImageByEmail:(NSString *)gravatarId
+ defaultImage:(NSString *)defaultImage
+ size:(NSInteger)size;
--(void)requestUIImageByEmail:(NSString *)gravatarId;
+-(void)requestUIImageByEmail:(NSString *)gravatarId
+ defaultImage:(NSString *)defaultImage;
@end

0 comments on commit fc792fc

Please sign in to comment.
Something went wrong with that request. Please try again.