diff --git a/Spectttator/SPComment.h b/Spectttator/SPComment.h index 7ad522b..bc7265d 100644 --- a/Spectttator/SPComment.h +++ b/Spectttator/SPComment.h @@ -7,7 +7,9 @@ // #import -#import "SPPlayer.h" +#import "SPObject.h" + +@class SPPlayer; /** The `SPComment` class provides a programmatic interface for interacting with Dribbble comments. @@ -31,12 +33,12 @@ @interface SPComment : SPObject /// The text of the comment. -@property (readonly, nonatomic) NSString *body; +@property (copy, nonatomic, readonly) NSString *body; /// The number of players who liked the comment. -@property (readonly, nonatomic) NSUInteger likesCount; +@property (nonatomic, readonly) NSUInteger likesCount; /** The player who posted the comment. @see SPPlayer */ -@property (readonly, nonatomic) SPPlayer *player; +@property (retain, nonatomic, readonly) SPPlayer *player; @end diff --git a/Spectttator/SPComment.m b/Spectttator/SPComment.m index 523696a..c44d959 100644 --- a/Spectttator/SPComment.m +++ b/Spectttator/SPComment.m @@ -7,23 +7,24 @@ // #import "SPComment.h" +#import "SPPlayer.h" -@implementation SPComment +@interface SPComment() +@property (copy, nonatomic, readwrite) NSString *body; +@property (nonatomic, readwrite) NSUInteger likesCount; +@property (retain, nonatomic, readwrite) SPPlayer *player; +@end -@synthesize body = _body; -@synthesize likesCount = _likesCount; -@synthesize player = _player; +@implementation SPComment - (id)initWithDictionary:(NSDictionary *)dictionary{ if((self = [super initWithDictionary:dictionary])){ - _body = [[dictionary stringSafelyFromKey:@"body"] retain]; - _likesCount = [dictionary uintSafelyFromKey:@"likes_count"]; + self.body = [[dictionary stringSafelyFromKey:@"body"] retain]; + self.likesCount = [dictionary uintSafelyFromKey:@"likes_count"]; NSDictionary *player = [dictionary objectSafelyFromKey:@"player"]; if(player != nil){ - _player = [[SPPlayer alloc] initWithDictionary:player]; - }else{ - _player = nil; + self.player = [[[SPPlayer alloc] initWithDictionary:player] autorelease]; } } diff --git a/Spectttator/SPMethods.h b/Spectttator/SPMethods.h index 5e97218..81c3f41 100644 --- a/Spectttator/SPMethods.h +++ b/Spectttator/SPMethods.h @@ -7,7 +7,8 @@ // #import -#import "SPPagination.h" + +@class SPPagination; #if TARGET_OS_IPHONE #define SPImage UIImage diff --git a/Spectttator/SPMethods.m b/Spectttator/SPMethods.m index 8d059de..9dd9ac1 100644 --- a/Spectttator/SPMethods.m +++ b/Spectttator/SPMethods.m @@ -7,10 +7,10 @@ // #import "SPMethods.h" - #import "SPPlayer.h" #import "SPComment.h" #import "SPShot.h" +#import "SPPagination.h" #import "AFJSONRequestOperation.h" #import "AFImageRequestOperation.h" #import "AFHTTPRequestOperation.h" diff --git a/Spectttator/SPObject.h b/Spectttator/SPObject.h index 3b6ec2c..20827e9 100644 --- a/Spectttator/SPObject.h +++ b/Spectttator/SPObject.h @@ -12,9 +12,9 @@ @interface SPObject : NSObject /// The unique id of the object. -@property (readonly, nonatomic) NSUInteger identifier; +@property (readonly, nonatomic, readonly) NSUInteger identifier; /// The date the object was created. -@property (readonly, nonatomic) NSDate *createdAt; +@property (readonly, nonatomic, readonly) NSDate *createdAt; ///---------------------------- /// @name Initializing a SPObject Object diff --git a/Spectttator/SPObject.m b/Spectttator/SPObject.m index c1e20c0..533f750 100644 --- a/Spectttator/SPObject.m +++ b/Spectttator/SPObject.m @@ -8,22 +8,22 @@ #import "SPObject.h" -@implementation SPObject +@interface SPObject() +@property (readonly, nonatomic, readwrite) NSUInteger identifier; +@property (readonly, nonatomic, readwrite) NSDate *createdAt; +@end -@synthesize identifier = _identifier; -@synthesize createdAt = _createdAt; +@implementation SPObject - (id)initWithDictionary:(NSDictionary *)dictionary{ if((self = [super init])){ - _identifier = [dictionary uintSafelyFromKey:@"id"]; + self.identifier = [dictionary uintSafelyFromKey:@"id"]; NSString *createdAt = [dictionary stringSafelyFromKey:@"created_at"]; if(createdAt != nil){ NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss ZZZZ"]; - _createdAt = [[formatter dateFromString:createdAt] retain]; + self.createdAt = [[formatter dateFromString:createdAt] retain]; [formatter release]; - }else{ - _createdAt = nil; } } diff --git a/Spectttator/SPPagination.h b/Spectttator/SPPagination.h index 490ddeb..10e0f60 100644 --- a/Spectttator/SPPagination.h +++ b/Spectttator/SPPagination.h @@ -8,8 +8,8 @@ #import -#define SPMaxPerPage 50 -#define SPDefaultPerPage 15 +extern NSUInteger const SPPerPageDefault; +extern NSUInteger const SPPerPageMax; /** Most Dribbble api calls take `page` and `per_page` to define which page of data to return and how many items should be contained in the return. @@ -26,7 +26,7 @@ NSString *username = @"inscopeapps"; [SPRequest shotsForPlayer:user - withPagination:[SPPagination perPage:20] + withPagination:SPPerPageMax runOnMainThread:NO withBlock:^(NSArray *shots, SPPagination *pagination){ NSLog(@"Received shot data for %@", user); @@ -42,13 +42,13 @@ @interface SPPagination : NSObject /// The current page number. -@property(readonly) NSUInteger page; +@property(nonatomic, readonly) NSUInteger page; /// The total number of pages. -@property(readonly) NSUInteger pages; +@property(nonatomic, readonly) NSUInteger pages; /// The number of items per-page. -@property(readonly) NSUInteger perPage; +@property(nonatomic, readonly) NSUInteger perPage; /// The total number of items. -@property(readonly) NSUInteger total; +@property(nonatomic, readonly) NSUInteger total; ///---------------------------- /// @name Initializing a SPPagination Object diff --git a/Spectttator/SPPagination.m b/Spectttator/SPPagination.m index a05b34e..5ff550a 100644 --- a/Spectttator/SPPagination.m +++ b/Spectttator/SPPagination.m @@ -9,12 +9,17 @@ #import "SPPagination.h" #import "SPMethods.h" -@implementation SPPagination +NSUInteger const SPPerPageDefault = 15; +NSUInteger const SPPerPageMax = 50; + +@interface SPPagination() +@property(nonatomic, readwrite) NSUInteger page; +@property(nonatomic, readwrite) NSUInteger pages; +@property(nonatomic, readwrite) NSUInteger perPage; +@property(nonatomic, readwrite) NSUInteger total; +@end -@synthesize page = _page; -@synthesize pages = _pages; -@synthesize perPage = _perPage; -@synthesize total = _total; +@implementation SPPagination + (NSDictionary *)page:(NSUInteger)page{ return [SPPagination page:page perPage:NSNotFound]; @@ -41,10 +46,10 @@ + (id)paginationWithDictionary:(NSDictionary *)dictionary{ - (id)initWithDictionary:(NSDictionary *)dictionary{ if((self = [super init])){ - _page = [dictionary uintSafelyFromKey:@"page"]; - _pages = [dictionary uintSafelyFromKey:@"pages"]; - _perPage = [dictionary uintSafelyFromKey:@"per_page"]; - _total = [dictionary uintSafelyFromKey:@"total"]; + self.page = [dictionary uintSafelyFromKey:@"page"]; + self.pages = [dictionary uintSafelyFromKey:@"pages"]; + self.perPage = [dictionary uintSafelyFromKey:@"per_page"]; + self.total = [dictionary uintSafelyFromKey:@"total"]; } return self; } diff --git a/Spectttator/SPPlayer.h b/Spectttator/SPPlayer.h index f1ab81a..fff52b9 100644 --- a/Spectttator/SPPlayer.h +++ b/Spectttator/SPPlayer.h @@ -33,42 +33,42 @@ @interface SPPlayer : SPObject /// The real name of the player. -@property (readonly, nonatomic) NSString *name; +@property (copy, nonatomic, readonly) NSString *name; /// The username of the player. -@property (readonly, nonatomic) NSString *username; +@property (copy, nonatomic, readonly) NSString *username; /// The url of the player's profile. -@property (readonly, nonatomic) NSURL *url; +@property (retain, nonatomic, readonly) NSURL *url; /// The url of the player's avatar. -@property (readonly, nonatomic) NSURL *avatarUrl; +@property (retain, nonatomic, readonly) NSURL *avatarUrl; /// The location of the player. -@property (readonly, nonatomic) NSString *location; +@property (copy, nonatomic, readonly) NSString *location; /// The player's twitter name. -@property (readonly, nonatomic) NSString *twitterScreenName; +@property (copy, nonatomic, readonly) NSString *twitterScreenName; /** The id of this player who drafted this player. If this player was not drafted the value is `NSNotFound`. */ -@property (readonly, nonatomic) NSUInteger draftedByPlayerId; +@property (nonatomic, readonly) NSUInteger draftedByPlayerId; /// The number of shots the player has posted. -@property (readonly, nonatomic) NSUInteger shotsCount; +@property (nonatomic, readonly) NSUInteger shotsCount; /// The number of players the player has drafted. -@property (readonly, nonatomic) NSUInteger drafteesCount; +@property (nonatomic, readonly) NSUInteger drafteesCount; /// The number of people the player follows. -@property (readonly, nonatomic) NSUInteger followersCount; +@property (nonatomic, readonly) NSUInteger followersCount; /// The number of followers the player has. -@property (readonly, nonatomic) NSUInteger followingCount; +@property (nonatomic, readonly) NSUInteger followingCount; /// The number of comments the player has posted. -@property (readonly, nonatomic) NSUInteger commentsCount; +@property (nonatomic, readonly) NSUInteger commentsCount; /// The number of comments the player's shots have received. -@property (readonly, nonatomic) NSUInteger commentsReceivedCount; +@property (nonatomic, readonly) NSUInteger commentsReceivedCount; /// The number of shots the player has liked. -@property (readonly, nonatomic) NSUInteger likesCount; +@property (nonatomic, readonly) NSUInteger likesCount; /// The number of likes the player's shots have received. -@property (readonly, nonatomic) NSUInteger likesReceivedCount; +@property (nonatomic, readonly) NSUInteger likesReceivedCount; /// The number of rebounds the player has posted. -@property (readonly, nonatomic) NSUInteger reboundsCount; +@property (nonatomic, readonly) NSUInteger reboundsCount; /// The number of rebounds the player's shots have received. -@property (readonly, nonatomic) NSUInteger reboundsReceivedCount; +@property (nonatomic, readonly) NSUInteger reboundsReceivedCount; ///---------------------------- /// @name Avatar diff --git a/Spectttator/SPPlayer.m b/Spectttator/SPPlayer.m index 1c312a2..fb0c155 100644 --- a/Spectttator/SPPlayer.m +++ b/Spectttator/SPPlayer.m @@ -8,25 +8,27 @@ #import "SPPlayer.h" -@implementation SPPlayer +@interface SPPlayer() +@property (copy, nonatomic, readwrite) NSString *name; +@property (copy, nonatomic, readwrite) NSString *username; +@property (retain, nonatomic, readwrite) NSURL *url; +@property (retain, nonatomic, readwrite) NSURL *avatarUrl; +@property (copy, nonatomic, readwrite) NSString *location; +@property (copy, nonatomic, readwrite) NSString *twitterScreenName; +@property (nonatomic, readwrite) NSUInteger draftedByPlayerId; +@property (nonatomic, readwrite) NSUInteger shotsCount; +@property (nonatomic, readwrite) NSUInteger drafteesCount; +@property (nonatomic, readwrite) NSUInteger followersCount; +@property (nonatomic, readwrite) NSUInteger followingCount; +@property (nonatomic, readwrite) NSUInteger commentsCount; +@property (nonatomic, readwrite) NSUInteger commentsReceivedCount; +@property (nonatomic, readwrite) NSUInteger likesCount; +@property (nonatomic, readwrite) NSUInteger likesReceivedCount; +@property (nonatomic, readwrite) NSUInteger reboundsCount; +@property (nonatomic, readwrite) NSUInteger reboundsReceivedCount; +@end -@synthesize name = _name; -@synthesize username = _username; -@synthesize url = _url; -@synthesize avatarUrl = _avatarUrl; -@synthesize location = _location; -@synthesize twitterScreenName = _twitterScreenName; -@synthesize draftedByPlayerId = _draftedByPlayerId; -@synthesize shotsCount = _shotsCount; -@synthesize drafteesCount = _drafteesCount; -@synthesize followersCount = _followersCount; -@synthesize followingCount = _followingCount; -@synthesize commentsCount = _commentsCount; -@synthesize commentsReceivedCount = _commentsReceivedCount; -@synthesize likesCount = _likesCount; -@synthesize likesReceivedCount = _likesReceivedCount; -@synthesize reboundsCount = _reboundsCount; -@synthesize reboundsReceivedCount = _reboundsReceivedCount; +@implementation SPPlayer - (void)avatarRunOnMainThread:(BOOL)runOnMainThread withBlock:(void (^)(SPImage *image))block{ @@ -37,23 +39,23 @@ - (void)avatarRunOnMainThread:(BOOL)runOnMainThread - (id)initWithDictionary:(NSDictionary *)dictionary{ if((self = [super initWithDictionary:dictionary])){ - _name = [[dictionary stringSafelyFromKey:@"name"] retain]; - _username = [[dictionary stringSafelyFromKey:@"username"] retain]; - _url = [[dictionary URLSafelyFromKey:@"url"] retain]; - _avatarUrl = [[dictionary URLSafelyFromKey:@"avatar_url"] retain]; - _location = [[dictionary stringSafelyFromKey:@"location"] retain]; - _twitterScreenName = [[dictionary stringSafelyFromKey:@"twitter_screen_name"] retain]; - _draftedByPlayerId = [dictionary uintSafelyFromKey:@"drafted_by_player_id"]; - _shotsCount = [dictionary uintSafelyFromKey:@"shots_count"]; - _drafteesCount = [dictionary uintSafelyFromKey:@"draftees_count"]; - _followersCount = [dictionary uintSafelyFromKey:@"followers_count"]; - _followingCount = [dictionary uintSafelyFromKey:@"following_count"]; - _commentsCount = [dictionary uintSafelyFromKey:@"comments_count"]; - _commentsReceivedCount = [dictionary uintSafelyFromKey:@"comments_received_count"]; - _likesCount = [dictionary uintSafelyFromKey:@"likes_count"]; - _likesReceivedCount = [dictionary uintSafelyFromKey:@"likes_received_count"]; - _reboundsCount = [dictionary uintSafelyFromKey:@"rebounds_count"]; - _reboundsReceivedCount = [dictionary uintSafelyFromKey:@"rebounds_received_count"]; + self.name = [dictionary stringSafelyFromKey:@"name"]; + self.username = [dictionary stringSafelyFromKey:@"username"]; + self.url = [dictionary URLSafelyFromKey:@"url"]; + self.avatarUrl = [dictionary URLSafelyFromKey:@"avatar_url"]; + self.location = [dictionary stringSafelyFromKey:@"location"]; + self.twitterScreenName = [[dictionary stringSafelyFromKey:@"twitter_screen_name"] retain]; + self.draftedByPlayerId = [dictionary uintSafelyFromKey:@"drafted_by_player_id"]; + self.shotsCount = [dictionary uintSafelyFromKey:@"shots_count"]; + self.drafteesCount = [dictionary uintSafelyFromKey:@"draftees_count"]; + self.followersCount = [dictionary uintSafelyFromKey:@"followers_count"]; + self.followingCount = [dictionary uintSafelyFromKey:@"following_count"]; + self.commentsCount = [dictionary uintSafelyFromKey:@"comments_count"]; + self.commentsReceivedCount = [dictionary uintSafelyFromKey:@"comments_received_count"]; + self.likesCount = [dictionary uintSafelyFromKey:@"likes_count"]; + self.likesReceivedCount = [dictionary uintSafelyFromKey:@"likes_received_count"]; + self.reboundsCount = [dictionary uintSafelyFromKey:@"rebounds_count"]; + self.reboundsReceivedCount = [dictionary uintSafelyFromKey:@"rebounds_received_count"]; } return self; diff --git a/Spectttator/SPRequest.h b/Spectttator/SPRequest.h index 2e53eb5..eccdede 100644 --- a/Spectttator/SPRequest.h +++ b/Spectttator/SPRequest.h @@ -23,8 +23,7 @@ extern NSString *const SPListPopular; #import - NSString *username = @"inscopeapps"; - + NSString *username = @"kgn"; [SPRequest shotsForPlayerLikes:username withPagination:[SPPagination perPage:10] runOnMainThread:NO diff --git a/Spectttator/SPShot.h b/Spectttator/SPShot.h index e046adb..01b6723 100644 --- a/Spectttator/SPShot.h +++ b/Spectttator/SPShot.h @@ -7,8 +7,10 @@ // #import -#import "SPPagination.h" -#import "SPPlayer.h" +#import "SPObject.h" + +@class SPPagination; +@class SPPlayer; /** The `SPShot` class provides a programmatic interface for interacting with Dribbble shots. @@ -40,36 +42,36 @@ @interface SPShot : SPObject /// The title of the shot. -@property (readonly, nonatomic) NSString *title; +@property (copy, nonatomic, readonly) NSString *title; /// The full url to the shot. -@property (readonly, nonatomic) NSURL *url; +@property (retain, nonatomic, readonly) NSURL *url; /// The short url to the shot. -@property (readonly, nonatomic) NSURL *shortUrl; +@property (retain, nonatomic, readonly) NSURL *shortUrl; /// The url to the shot's image. -@property (readonly, nonatomic) NSURL *imageUrl; +@property (retain, nonatomic, readonly) NSURL *imageUrl; /// The url to the shot's teaser image. -@property (readonly, nonatomic) NSURL *imageTeaserUrl; +@property (retain, nonatomic, readonly) NSURL *imageTeaserUrl; /// The width of the shot. -@property (readonly, nonatomic) NSUInteger width; +@property (nonatomic, readonly) NSUInteger width; /// The height of the shot. -@property (readonly, nonatomic) NSUInteger height; +@property (nonatomic, readonly) NSUInteger height; /// The number of views the shot has. -@property (readonly, nonatomic) NSUInteger viewsCount; +@property (nonatomic, readonly) NSUInteger viewsCount; /// The number of likes the shot has. -@property (readonly, nonatomic) NSUInteger likesCount; +@property (nonatomic, readonly) NSUInteger likesCount; /// The number of comments the shot has. -@property (readonly, nonatomic) NSUInteger commentsCount; +@property (nonatomic, readonly) NSUInteger commentsCount; /// The number of rebounds the shot has. -@property (readonly, nonatomic) NSUInteger reboundsCount; +@property (nonatomic, readonly) NSUInteger reboundsCount; /** The id of this shot this shot is a rebound of. If it is not a rebound this value is `NSNotFound`. */ -@property (readonly, nonatomic) NSUInteger reboundSourceId; +@property (nonatomic, readonly) NSUInteger reboundSourceId; /** The player who posted the shot. @see SPPlayer */ -@property (readonly, nonatomic) SPPlayer *player; +@property (retain, nonatomic, readonly) SPPlayer *player; ///---------------------------- diff --git a/Spectttator/SPShot.m b/Spectttator/SPShot.m index 3b13bb6..606d1ec 100644 --- a/Spectttator/SPShot.m +++ b/Spectttator/SPShot.m @@ -8,22 +8,26 @@ #import "SPShot.h" #import "SPComment.h" +#import "SPPagination.h" +#import "SPPlayer.h" -@implementation SPShot +@interface SPShot() +@property (copy, nonatomic, readwrite) NSString *title; +@property (retain, nonatomic, readwrite) NSURL *url; +@property (retain, nonatomic, readwrite) NSURL *shortUrl; +@property (retain, nonatomic, readwrite) NSURL *imageUrl; +@property (retain, nonatomic, readwrite) NSURL *imageTeaserUrl; +@property (nonatomic, readwrite) NSUInteger width; +@property (nonatomic, readwrite) NSUInteger height; +@property (nonatomic, readwrite) NSUInteger viewsCount; +@property (nonatomic, readwrite) NSUInteger likesCount; +@property (nonatomic, readwrite) NSUInteger commentsCount; +@property (nonatomic, readwrite) NSUInteger reboundsCount; +@property (nonatomic, readwrite) NSUInteger reboundSourceId; +@property (retain, nonatomic, readwrite) SPPlayer *player; +@end -@synthesize title = _title; -@synthesize url = _url; -@synthesize shortUrl = _shortUrl; -@synthesize imageUrl = _imageUrl; -@synthesize imageTeaserUrl = _imageTeaserUrl; -@synthesize width = _width; -@synthesize height = _height; -@synthesize viewsCount = _viewsCount; -@synthesize likesCount = _likesCount; -@synthesize commentsCount = _commentsCount; -@synthesize reboundsCount = _reboundsCount; -@synthesize reboundSourceId = _reboundSourceId; -@synthesize player = _player; +@implementation SPShot - (void)imageRunOnMainThread:(BOOL)runOnMainThread withBlock:(void (^)(SPImage *image))block{ @@ -63,24 +67,22 @@ - (void)commentsWithPagination:(NSDictionary *)pagination - (id)initWithDictionary:(NSDictionary *)dictionary{ if((self = [super initWithDictionary:dictionary])){ - _title = [[dictionary stringSafelyFromKey:@"title"] retain]; - _url = [[dictionary URLSafelyFromKey:@"url"] retain]; - _shortUrl = [[dictionary URLSafelyFromKey:@"short_url"] retain]; - _imageUrl = [[dictionary URLSafelyFromKey:@"image_url"] retain]; - _imageTeaserUrl = [[dictionary URLSafelyFromKey:@"image_teaser_url"] retain]; - _width = [dictionary uintSafelyFromKey:@"width"]; - _height = [dictionary uintSafelyFromKey:@"height"]; - _viewsCount = [dictionary uintSafelyFromKey:@"views_count"]; - _likesCount = [dictionary uintSafelyFromKey:@"likes_count"]; - _commentsCount = [dictionary uintSafelyFromKey:@"comments_count"]; - _reboundsCount = [dictionary uintSafelyFromKey:@"rebounds_count"]; - _reboundSourceId = [dictionary uintSafelyFromKey:@"rebound_source_id"]; + self.title = [dictionary stringSafelyFromKey:@"title"]; + self.url = [dictionary URLSafelyFromKey:@"url"]; + self.shortUrl = [dictionary URLSafelyFromKey:@"short_url"]; + self.imageUrl = [dictionary URLSafelyFromKey:@"image_url"]; + self.imageTeaserUrl = [dictionary URLSafelyFromKey:@"image_teaser_url"]; + self.width = [dictionary uintSafelyFromKey:@"width"]; + self.height = [dictionary uintSafelyFromKey:@"height"]; + self.viewsCount = [dictionary uintSafelyFromKey:@"views_count"]; + self.likesCount = [dictionary uintSafelyFromKey:@"likes_count"]; + self.commentsCount = [dictionary uintSafelyFromKey:@"comments_count"]; + self.reboundsCount = [dictionary uintSafelyFromKey:@"rebounds_count"]; + self.reboundSourceId = [dictionary uintSafelyFromKey:@"rebound_source_id"]; NSDictionary *player = [dictionary objectSafelyFromKey:@"player"]; if(player != nil){ - _player = [[SPPlayer alloc] initWithDictionary:player]; - }else{ - _player = nil; + self.player = [[[SPPlayer alloc] initWithDictionary:player] autorelease]; } }