From d0bb175693e4746371b95f42a533dc238c65660e Mon Sep 17 00:00:00 2001 From: shiami Date: Wed, 11 Dec 2013 23:55:07 +0800 Subject: [PATCH] Add video type for media. --- NRGramKit/Model/IGMedia.h | 2 ++ NRGramKit/Model/IGMedia.m | 7 ++++++- NRGramKit/Model/IGVideo.h | 20 ++++++++++++++++++++ NRGramKit/Model/IGVideo.m | 25 +++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 NRGramKit/Model/IGVideo.h create mode 100644 NRGramKit/Model/IGVideo.m diff --git a/NRGramKit/Model/IGMedia.h b/NRGramKit/Model/IGMedia.h index 3ea1e7e..526a662 100644 --- a/NRGramKit/Model/IGMedia.h +++ b/NRGramKit/Model/IGMedia.h @@ -9,6 +9,7 @@ #import #import "IGComment.h" #import "IGImage.h" +#import "IGVideo.h" #import "IGLocation.h" #import "IGUser.h" #import "IGTag.h" @@ -31,6 +32,7 @@ @property (nonatomic, retain) NSArray* tags; @property (nonatomic, retain) NSArray* likes; @property (nonatomic, retain) IGImage * image; +@property (nonatomic, retain) IGVideo * video; @property (nonatomic, retain) IGLocation * location; @property (nonatomic, retain) IGUser * user; +(IGMedia*)mediaWithDictionary:(NSDictionary*)dict; diff --git a/NRGramKit/Model/IGMedia.m b/NRGramKit/Model/IGMedia.m index 9c68783..2e84e66 100644 --- a/NRGramKit/Model/IGMedia.m +++ b/NRGramKit/Model/IGMedia.m @@ -26,7 +26,12 @@ +(IGMedia*)mediaWithDictionary:(NSDictionary*)dict if([media.received_time longValue]==0) media.received_time = [NSNumber numberWithLong:(long)[[NSDate date] timeIntervalSince1970]]; - media.image = [IGImage imageWithDictionary:[dict objectForKey:@"images"]]; + if ([media.type isEqualToString:@"image"]) { + media.image = [IGImage imageWithDictionary:[dict objectForKey:@"images"]]; + } else if ([media.type isEqualToString:@"video"]) { + media.video = [IGVideo videoWithDictionary:[dict objectForKey:@"videos"]]; + } + media.user = [IGUser userWithDictionary:[dict objectForKey:@"user"]]; NSMutableArray* tagArray = [[NSMutableArray alloc]init]; diff --git a/NRGramKit/Model/IGVideo.h b/NRGramKit/Model/IGVideo.h new file mode 100644 index 0000000..02c1924 --- /dev/null +++ b/NRGramKit/Model/IGVideo.h @@ -0,0 +1,20 @@ +// +// IGVideo.h +// NRGramKit +// +// Created by shiami on 12/11/13. +// Copyright (c) 2013 NextRoot. All rights reserved. +// + +#import + +@interface IGVideo : NSObject { + +} + +@property (nonatomic, retain) NSString * low_resolution; +@property (nonatomic, retain) NSString * standard_resolution; +@property (nonatomic, retain) NSString * thumbnail; ++(IGVideo*)videoWithDictionary:(NSDictionary*)dict; + +@end diff --git a/NRGramKit/Model/IGVideo.m b/NRGramKit/Model/IGVideo.m new file mode 100644 index 0000000..535d970 --- /dev/null +++ b/NRGramKit/Model/IGVideo.m @@ -0,0 +1,25 @@ +// +// IGVideo.m +// NRGramKit +// +// Created by shiami on 12/11/13. +// Copyright (c) 2013 NextRoot. All rights reserved. +// + +#import "IGVideo.h" + +@implementation IGVideo ++(IGVideo *)videoWithDictionary:(NSDictionary *)dict +{ + IGVideo* video = [[IGVideo alloc]init]; + NSDictionary* thumbnailDictionary = [dict objectForKey:@"thumbnail"]; + NSDictionary* standardDictionary = [dict objectForKey:@"standard_resolution"]; + NSDictionary* lowDictionary = [dict objectForKey:@"low_resolution"]; + + video.low_resolution =[lowDictionary objectForKey:@"url"]; + video.standard_resolution =[standardDictionary objectForKey:@"url"]; + video.thumbnail =[thumbnailDictionary objectForKey:@"url"]; + + return video; +} +@end