Skip to content

Commit

Permalink
cleaning up the code with new obj-c language features
Browse files Browse the repository at this point in the history
  • Loading branch information
kgn committed Aug 19, 2012
1 parent 9a99941 commit 550316c
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 138 deletions.
10 changes: 6 additions & 4 deletions Spectttator/SPComment.h
Expand Up @@ -7,7 +7,9 @@
//

#import <Foundation/Foundation.h>
#import "SPPlayer.h"
#import "SPObject.h"

@class SPPlayer;

/** The `SPComment` class provides a programmatic interface for interacting
with Dribbble comments.
Expand All @@ -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
19 changes: 10 additions & 9 deletions Spectttator/SPComment.m
Expand Up @@ -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];
}
}

Expand Down
3 changes: 2 additions & 1 deletion Spectttator/SPMethods.h
Expand Up @@ -7,7 +7,8 @@
//

#import <Foundation/Foundation.h>
#import "SPPagination.h"

@class SPPagination;

#if TARGET_OS_IPHONE
#define SPImage UIImage
Expand Down
2 changes: 1 addition & 1 deletion Spectttator/SPMethods.m
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Spectttator/SPObject.h
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Spectttator/SPObject.m
Expand Up @@ -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;
}
}

Expand Down
14 changes: 7 additions & 7 deletions Spectttator/SPPagination.h
Expand Up @@ -8,8 +8,8 @@

#import <Foundation/Foundation.h>

#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.
Expand All @@ -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);
Expand All @@ -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
Expand Down
23 changes: 14 additions & 9 deletions Spectttator/SPPagination.m
Expand Up @@ -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];
Expand All @@ -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;
}
Expand Down
34 changes: 17 additions & 17 deletions Spectttator/SPPlayer.h
Expand Up @@ -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
Expand Down
72 changes: 37 additions & 35 deletions Spectttator/SPPlayer.m
Expand Up @@ -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{
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions Spectttator/SPRequest.h
Expand Up @@ -23,8 +23,7 @@ extern NSString *const SPListPopular;
#import <Spectttator/Spectttator.h>
NSString *username = @"inscopeapps";
NSString *username = @"kgn";
[SPRequest shotsForPlayerLikes:username
withPagination:[SPPagination perPage:10]
runOnMainThread:NO
Expand Down

0 comments on commit 550316c

Please sign in to comment.