Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
devedup committed Jun 30, 2016
2 parents 0fb0028 + b293763 commit ac70cb3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
5 changes: 3 additions & 2 deletions Classes/DevedUpKit/FKDUDiskCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Copyright (c) 2013 DevedUp Ltd. All rights reserved. http://www.devedup.com
//


#import <Foundation/Foundation.h>

//You can use these as convenience and readability instead of passing a number in maxAgeMinutes
typedef enum {
FKDUMaxAgeNeverCache = 0,
Expand All @@ -17,8 +20,6 @@ typedef enum {
FKDUMaxAgeInfinite = NSIntegerMax
} FKDUMaxAge;

#import <Foundation/Foundation.h>

@protocol FKDUDiskCache <NSObject>

@required
Expand Down
55 changes: 48 additions & 7 deletions Classes/Model/FKFlickrAPIMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,66 @@

@protocol FKFlickrAPIMethod <NSObject>

/* The name of the method used by flickr */
/**
* The name of the method used by flickr
*
* @return The name of the method used by flickr
*/
- (NSString *) name;

/* All the args that you have injected into the object into a dictionary */
/**
* All the args that you have injected into the object into a dictionary
*
* @return dictionary of args
*/
- (NSDictionary *) args;

/* Are the args passed valid? */
/**
* Are the args passed valid?
*
* @param error the error if the args are not valie
*
* @return true if they are valid
*/
- (BOOL) isValid:(NSError **)error;

/* Get a readable description for the error code passed */
/**
* Get a readable description for the error code passed
*
* @param error the error code you want info of
*
* @return a displayable error
*/
- (NSString *) descriptionForError:(NSInteger)error;

/* Does this need a login? */
/**
* Does this method require you to be logged in . i.e. need a login?
*
* @return true if you need to login first
*/
- (BOOL) needsLogin;

/* Do you need to sign this request */
/**
* Do you need to sign this request
*
* @return true if you need to sign this request
*/
- (BOOL) needsSigning;

/* Permissions needed for this request */
/**
* Permissions needed for this request
*
* @return the FkPermission you need to access this request
*/
- (FKPermission) requiredPerms;

@optional

/**
* Set the page to be access on this method. This is used when loading pages of data
*
* @param page the page you want to access
*/
- (void) setPage:(NSString *)page;

@end
17 changes: 3 additions & 14 deletions Classes/Network/FKFlickrNetworkOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,13 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

NSData *data = self.receivedData;

static NSInteger prefixBytes = -1;
static NSInteger suffixBytes = 1;
if (-1 == prefixBytes) {
NSString *responsePrefix = @"jsonFlickrApi(";
prefixBytes = [responsePrefix length];
}

NSData *subData = nil;
if (data.length > prefixBytes) {
subData =[data subdataWithRange:NSMakeRange(prefixBytes, data.length - prefixBytes - suffixBytes)];
}

//Cache the response
if (data && data.length > 0) {
if (0 != self.maxAgeMinutes) {
[self.diskCache storeData:subData forKey:self.cacheKey];
[self.diskCache storeData:data forKey:self.cacheKey];
}
[self processResponseData:subData];
[self processResponseData:data];
} else {
NSString *errorString = @"No data was returned from Flickr to process";
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: errorString};
Expand All @@ -155,6 +143,7 @@ - (NSMutableURLRequest *) createRequest:(NSError **)error {
NSMutableDictionary *newArgs = self.args ? [NSMutableDictionary dictionaryWithDictionary:self.args] : [NSMutableDictionary dictionary];
newArgs[@"method"] = self.apiMethod;
newArgs[@"format"] = @"json";
newArgs[@"nojsoncallback"] = @"1";

FKURLBuilder *urlBuilder = [[FKURLBuilder alloc] init];

Expand Down

0 comments on commit ac70cb3

Please sign in to comment.