-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPSRFlickrPhoto.m
70 lines (55 loc) · 1.6 KB
/
PSRFlickrPhoto.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// PSRFlickrPhoto.m
// PhotosViewer
//
// Created by n.shubenkov on 29/08/14.
// Copyright (c) 2014 n.shubenkov. All rights reserved.
//
#import "PSRFlickrPhoto.h"
@interface PSRFlickrPhoto()
@property (nonatomic,readwrite, strong) NSDictionary *info;
@end
@implementation PSRFlickrPhoto
+ (NSArray *)photosWithInfoes:(NSArray *)infoes
{
NSMutableArray *parsedPhotos = [NSMutableArray arrayWithCapacity:infoes.count];
for (int i = 0; i <infoes.count; i++) {
NSDictionary *info = infoes[i];
}
[infoes enumerateObjectsUsingBlock:^(NSDictionary *anInfo, NSUInteger idx, BOOL *stop) {
PSRFlickrPhoto *aPhoto = [self photoWithInfo:anInfo];
[parsedPhotos addObject:aPhoto];
}];
//imitate long parsing process
[NSThread sleepForTimeInterval:2];
return parsedPhotos;
}
+ (instancetype)photoWithInfo:(NSDictionary *)info
{
return [[self alloc]initWithInfo:info];
}
- (instancetype)initWithInfo:(NSDictionary *)info
{
if (self = [super init]){
_info = info;
}
return self;
}
- (NSURL *)highQualityURL
{
return [self urlForQualityTag:@"b"];
}
- (NSURL *)lowQualityURL
{
return [self urlForQualityTag:@"s"];
}
- (NSString *)title
{
return self.info[@"title"];
}
- (NSURL *)urlForQualityTag:(NSString *)qualityTag
{
NSString *photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_%@.jpg", [self.info objectForKey:@"farm"], [self.info objectForKey:@"server"], [self.info objectForKey:@"id"], [self.info objectForKey:@"secret"], qualityTag];
return [NSURL URLWithString:photoURLString];
}
@end