Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
DoubanAPIEngine/DoubanAPIEngine/Sources/Model2/Movie/DOUMovie.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// DOUMovie.h | ||
// DoubanAPIEngine | ||
// | ||
// Created by GUO Lin on 12/5/12. | ||
// Copyright (c) 2012 Douban Inc. All rights reserved. | ||
// | ||
|
||
#import "DOUObject.h" | ||
|
||
@interface DOUMovie : DOUObject | ||
|
||
@property (nonatomic, copy) NSString *identifier; | ||
@property (nonatomic, copy) NSString *title; | ||
@property (nonatomic, copy) NSString *originalTitle; | ||
@property (nonatomic, copy) NSString *rating; | ||
@property (nonatomic, copy) NSString *stars; | ||
|
||
@property (nonatomic, copy) NSString *publishTimeStr; | ||
@property (nonatomic, retain) NSDate *publishTime; | ||
|
||
@property (nonatomic, copy) NSString *largeImage; | ||
@property (nonatomic, copy) NSString *smallImage; | ||
@property (nonatomic, copy) NSString *mediumImage; | ||
|
||
@property (nonatomic, assign) NSInteger wishCount; | ||
@property (nonatomic, assign) NSInteger collectionCount; | ||
|
||
|
||
@end |
88 changes: 88 additions & 0 deletions
88
DoubanAPIEngine/DoubanAPIEngine/Sources/Model2/Movie/DOUMovie.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// DOUMovie.m | ||
// DoubanAPIEngine | ||
// | ||
// Created by GUO Lin on 12/5/12. | ||
// Copyright (c) 2012 Douban Inc. All rights reserved. | ||
// | ||
|
||
#import "DOUMovie.h" | ||
#import "DOUObject+Utils.h" | ||
|
||
|
||
@implementation DOUMovie | ||
|
||
@dynamic identifier; | ||
@dynamic title; | ||
@dynamic originalTitle; | ||
@dynamic stars; | ||
@dynamic rating; | ||
|
||
@dynamic publishTimeStr; | ||
@dynamic publishTime; | ||
|
||
@dynamic largeImage; | ||
@dynamic smallImage; | ||
@dynamic mediumImage; | ||
|
||
@dynamic wishCount; | ||
@dynamic collectionCount; | ||
|
||
|
||
- (NSString *)identifier { | ||
return [self.dictionary objectForKey:@"id"]; | ||
} | ||
|
||
- (NSString *)originalTitle { | ||
return [self.dictionary objectForKey:@"orignal_title"]; | ||
} | ||
|
||
- (NSString *)title { | ||
return [self.dictionary objectForKey:@"title"]; | ||
} | ||
|
||
|
||
- (NSString *)stars { | ||
return [self.dictionary objectForKey:@"stars"]; | ||
} | ||
|
||
|
||
- (NSString *)rating { | ||
return [self.dictionary objectForKey:@"rating"]; | ||
} | ||
|
||
|
||
- (NSString *)publishTimeStr { | ||
return [self.dictionary objectForKey:@"pubdate"]; | ||
} | ||
|
||
|
||
- (NSDate *)publishTime { | ||
return [[self class] dateOfString:self.publishTimeStr]; | ||
} | ||
|
||
|
||
- (NSString *)largeImage { | ||
return [[self.dictionary objectForKey:@"images"] objectForKey:@"large"]; | ||
} | ||
|
||
- (NSString *)smallImage { | ||
return [[self.dictionary objectForKey:@"images"] objectForKey:@"small"]; | ||
} | ||
|
||
- (NSString *)mediumImage { | ||
return [[self.dictionary objectForKey:@"images"] objectForKey:@"medium"]; | ||
} | ||
|
||
|
||
|
||
- (NSInteger)wishCount { | ||
return [[self.dictionary objectForKey:@"wish"] integerValue]; | ||
} | ||
|
||
- (NSInteger)collectionCount { | ||
return [[self.dictionary objectForKey:@"collection"] integerValue]; | ||
} | ||
|
||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
DoubanAPIEngine/DoubanAPIEngine/Sources/Model2/Movie/DOUMovieArray.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DOUMovieArray.h | ||
// DoubanAPIEngine | ||
// | ||
// Created by GUO Lin on 12/5/12. | ||
// Copyright (c) 2012 Douban Inc. All rights reserved. | ||
// | ||
|
||
#import "DOUObjectArray.h" | ||
|
||
@interface DOUMovieArray : DOUObjectArray | ||
|
||
@end |
23 changes: 23 additions & 0 deletions
23
DoubanAPIEngine/DoubanAPIEngine/Sources/Model2/Movie/DOUMovieArray.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// DOUMovieArray.m | ||
// DoubanAPIEngine | ||
// | ||
// Created by GUO Lin on 12/5/12. | ||
// Copyright (c) 2012 Douban Inc. All rights reserved. | ||
// | ||
|
||
#import "DOUMovieArray.h" | ||
#import "DOUMovie.h" | ||
|
||
@implementation DOUMovieArray | ||
|
||
+ (Class)objectClass { | ||
return [DOUMovie class]; | ||
} | ||
|
||
+ (NSString *)objectName { | ||
return @"movies"; | ||
} | ||
|
||
|
||
@end |
49 changes: 49 additions & 0 deletions
49
DoubanAPIEngine/DoubanAPIEngineTests/Model2/DOUMovieTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// DOUCommentTests.m | ||
// DoubanApiClient | ||
// | ||
// Created by Lin GUO on 5/19/12. | ||
// Copyright (c) 2012 Douban Inc. All rights reserved. | ||
// | ||
|
||
#import <SenTestingKit/SenTestingKit.h> | ||
#import "DOUMovie.h" | ||
#import "DOUMovieArray.h" | ||
|
||
|
||
@interface DOUMovieTests : SenTestCase | ||
|
||
@end | ||
|
||
|
||
@implementation DOUMovieTests | ||
|
||
- (void)testMovieArray { | ||
NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"MovieArray" ofType:@"json"]; | ||
if (!filePath) | ||
STAssertTrue(FALSE, @"path fail"); | ||
|
||
NSString *string = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; | ||
DOUMovieArray *movies = [[DOUMovieArray alloc] initWithString:string]; | ||
|
||
STAssertTrue(movies.count == 20, @"count"); | ||
STAssertTrue(movies.start == 0, @"start"); | ||
STAssertTrue(movies.total == 1, @"total"); | ||
STAssertTrue([movies.objectArray count] == 1, @"objectArray"); | ||
|
||
for (DOUMovie *movie in movies.objectArray) { | ||
if ([movie.identifier isEqualToString:@"20280228"]) { | ||
STAssertTrue([movie.title isEqualToString:@"我们可以结婚吗"], @"title"); | ||
STAssertTrue([movie.originalTitle isEqualToString:@"우리가 결혼할 수 있을까"], @"title"); | ||
STAssertTrue([movie.rating isEqualToString:@"8.4"], @"rating"); | ||
STAssertTrue([movie.stars isEqualToString:@"45"], @"stars"); | ||
STAssertTrue([movie.publishTimeStr isEqualToString:@"2012-10-29"], @"publishdata"); | ||
STAssertTrue(movie.wishCount == 400, @"wish"); | ||
STAssertTrue(movie.collectionCount == 117, @"collection"); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
@end |
22 changes: 22 additions & 0 deletions
22
DoubanAPIEngine/DoubanAPIEngineTests/Resources/Model2/MovieArray.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"count": 20, | ||
"start": 0, | ||
"total": 1, | ||
"movies": [ | ||
{ | ||
"rating": "8.4", | ||
"stars": "45", | ||
"pubdate": "2012-10-29", | ||
"title": "我们可以结婚吗", | ||
"images": { | ||
"large": "http://img3.douban.com/lpic/s23130731.jpg", | ||
"small": "http://img3.douban.com/lpic/s23130731.jpg", | ||
"medium": "http://img3.douban.com/mpic/s23130731.jpg" | ||
}, | ||
"wish": 400, | ||
"id": "20280228", | ||
"orignal_title": "우리가 결혼할 수 있을까", | ||
"collection": 117 | ||
} | ||
] | ||
} |