|
7 | 7 | // |
8 | 8 |
|
9 | 9 | #import "CSFakedDataRequestor.h" |
| 10 | +#import "AKRouter.h" |
10 | 11 |
|
11 | 12 | @implementation CSFakedDataRequestor |
12 | 13 |
|
13 | 14 | - (void) requestRoute:(NSString *) routeName |
14 | | - withParams:(NSDictionary *) params |
15 | | - success:(void(^)(AFHTTPRequestOperation *operation, id responseObject)) successBlock |
16 | | - failure:(void(^)(AFHTTPRequestOperation *operation, id responseObject)) failureBlock; |
| 15 | + withParams:(NSDictionary *) params |
| 16 | + success:(void(^)(AFHTTPRequestOperation *operation, id responseObject)) successBlock |
| 17 | + failure:(void(^)(AFHTTPRequestOperation *operation, id responseObject)) failureBlock; |
17 | 18 | { |
18 | | - NSDictionary *route = [self routes][routeName]; |
19 | | - NSString *method = route[@"method"]; |
20 | | - NSString *path = route[@"path"]; |
21 | | - |
22 | | - NSDictionary *data; |
23 | | - |
24 | | - if([method isEqualToString:@"GET"]) { |
25 | | - if ([path rangeOfString:@"feed_items"].location != NSNotFound) { |
26 | | - data = [self feedItemsResponse]; |
27 | | - } else if ([path rangeOfString:@"feeds"].location != NSNotFound) { |
28 | | - //for now, the feed defaults and search return the same values |
29 | | - data = [self feedsResponse]; |
| 19 | + |
| 20 | + NSString *path = [[AKRouter shared] pathFor:routeName params:params]; |
| 21 | + AKRequestMethod method = [[AKRouter shared] methodFor:routeName]; |
| 22 | + |
| 23 | + NSDictionary *data; |
| 24 | + |
| 25 | + if(method == kAKRequestMethodGET) { |
| 26 | + if ([path rangeOfString:@"feed_items"].location != NSNotFound) { |
| 27 | + data = [self feedItemsResponse]; |
| 28 | + } else if ([path rangeOfString:@"feeds"].location != NSNotFound) { |
| 29 | + //for now, the feed defaults and search return the same values |
| 30 | + data = [self feedsResponse]; |
| 31 | + } else { |
| 32 | + //this path is not handled by the response faker |
| 33 | + data = @{}; |
| 34 | + } |
30 | 35 | } else { |
31 | | - //this path is not handled by the response faker |
32 | | - data = @{}; |
| 36 | + //post/other requests not supported right now |
| 37 | + data = @{}; |
33 | 38 | } |
34 | | - } else { |
35 | | - //post/other requests not supported right now |
36 | | - data = @{}; |
37 | | - } |
38 | | - |
39 | | - if (successBlock) successBlock(nil, data); |
| 39 | + |
| 40 | + if (successBlock) successBlock(nil, data); |
40 | 41 | } |
41 | 42 |
|
42 | 43 | //these feeds are used for both the search and the defaults endpoints |
43 | 44 | //their ids should match the feed_id fields on the feedItemsResponse |
44 | 45 | - (NSDictionary *) feedsResponse |
45 | 46 | { |
46 | | - NSArray *items = [NSArray arrayWithObjects:@{@"id": @1, |
| 47 | + NSArray *items = [NSArray arrayWithObjects:@{@"id": @1, |
47 | 48 | @"name": @"Cloudspace Feed", |
48 | 49 | @"url": @"http://www.engadget.com/rss.xml", |
49 | 50 | @"icon": @"http://s3.amazonaws.com/rss.cloudspace.com/feed/1/icon.png", //note: this image does not work on 3-11-2014 |
50 | 51 | @"feed_items": @[]}, |
51 | | - @{@"id": @2, |
52 | | - @"name": @"EasyReader Feed", |
53 | | - @"url": @"http://www.engadget.com/rss.xml", |
54 | | - @"icon": @"http://s3.amazonaws.com/rss.cloudspace.com/feed/2/icon.png", //note: this image does not work on 3-11-2014 |
55 | | - @"feed_items": @[]}, nil]; |
| 52 | + @{@"id": @2, |
| 53 | + @"name": @"EasyReader Feed", |
| 54 | + @"url": @"http://www.engadget.com/rss.xml", |
| 55 | + @"icon": @"http://s3.amazonaws.com/rss.cloudspace.com/feed/2/icon.png", //note: this image does not work on 3-11-2014 |
| 56 | + @"feed_items": @[]}, nil]; |
56 | 57 | return @{@"feeds": items}; |
57 | 58 | } |
58 | 59 |
|
@@ -148,17 +149,17 @@ - (NSDictionary *) feedItemsResponse |
148 | 149 | @"created_at": @"2014-03-05T22:32:41+00:00", |
149 | 150 | @"updated_at": @"2014-03-05T22:32:41+00:00", |
150 | 151 | @"published_at": @"2014-03-04T19:52:21+00:00"}, nil]; |
151 | | - |
152 | | - NSRange subarrayRange; |
153 | | - if ( !self.requestCounter ) self.requestCounter = 1; |
154 | | - if ( self.requestCounter == 1 ){ |
155 | | - subarrayRange = NSMakeRange(0,4); |
156 | | - } else { |
157 | | - subarrayRange = NSMakeRange(self.requestCounter*2,2); |
158 | | - } |
159 | | - self.requestCounter++; |
160 | | - |
161 | | - return @{@"feed_items": [items subarrayWithRange:subarrayRange]}; |
| 152 | + |
| 153 | + NSRange subarrayRange; |
| 154 | + if ( !self.requestCounter ) self.requestCounter = 1; |
| 155 | + if ( self.requestCounter == 1 ){ |
| 156 | + subarrayRange = NSMakeRange(0,4); |
| 157 | + } else { |
| 158 | + subarrayRange = NSMakeRange(self.requestCounter*2,2); |
| 159 | + } |
| 160 | + self.requestCounter++; |
| 161 | + |
| 162 | + return @{@"feed_items": [items subarrayWithRange:subarrayRange]}; |
162 | 163 | } |
163 | 164 |
|
164 | 165 |
|
|
0 commit comments