From 7747dcdfae068f33ac3bd22ac7c6d064cfbe4431 Mon Sep 17 00:00:00 2001 From: myellen Date: Thu, 19 Jun 2014 16:40:53 -0400 Subject: [PATCH 1/2] Update ENAPIRequest.m Changed cache policy for NSUrlRequests. Fixes problem of receiving the same responses for a given request e.g. receiving the same session_id every time you create a dynamic playlist. --- ENAPILibrary/ENAPILibrary/ENAPIRequest.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ENAPILibrary/ENAPILibrary/ENAPIRequest.m b/ENAPILibrary/ENAPILibrary/ENAPIRequest.m index 3b8e2ee..bdc6264 100755 --- a/ENAPILibrary/ENAPILibrary/ENAPIRequest.m +++ b/ENAPILibrary/ENAPILibrary/ENAPIRequest.m @@ -174,6 +174,8 @@ - (void)initiateGetRequest { [request setTimeoutInterval:requestTimeoutInterval]; + [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + self.connection =[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (self.connection == nil) { @@ -194,6 +196,8 @@ - (void)initiatePostRequest { [request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary] forHTTPHeaderField:@"Content-Type"]; + [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; From 0933cc7dea036c57abd686abf05073b792f63967 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 19 Jun 2014 19:45:38 -0400 Subject: [PATCH 2/2] Change caching option to be a per-request flag. --- .../contents.xcworkspacedata | 7 ++ .../xcshareddata/ENAPILibrary.xccheckout | 41 +++++++++++ .../UserInterfaceState.xcuserstate | Bin 0 -> 8485 bytes .../xcschemes/ENAPILibrary.xcscheme | 69 ++++++++++++++++++ .../xcschemes/xcschememanagement.plist | 27 +++++++ ENAPILibrary/ENAPILibrary/ENAPIRequest.h | 32 +++++++- ENAPILibrary/ENAPILibrary/ENAPIRequest.m | 42 ++++++++++- 7 files changed, 213 insertions(+), 5 deletions(-) create mode 100644 ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcshareddata/ENAPILibrary.xccheckout create mode 100644 ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcuserdata/maxyellen.xcuserdatad/UserInterfaceState.xcuserstate create mode 100644 ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/ENAPILibrary.xcscheme create mode 100644 ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..8471c03 --- /dev/null +++ b/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcshareddata/ENAPILibrary.xccheckout b/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcshareddata/ENAPILibrary.xccheckout new file mode 100644 index 0000000..c6d688e --- /dev/null +++ b/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcshareddata/ENAPILibrary.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + FB5E9F3C-8700-4AC7-B417-28D7F33CDB9B + IDESourceControlProjectName + ENAPILibrary + IDESourceControlProjectOriginsDictionary + + C00DEDE6-CD91-4851-B65D-250053E807CA + https://github.com/myellen/enios.git + + IDESourceControlProjectPath + ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace + IDESourceControlProjectRelativeInstallPathDictionary + + C00DEDE6-CD91-4851-B65D-250053E807CA + ../../.. + + IDESourceControlProjectURL + https://github.com/myellen/enios.git + IDESourceControlProjectVersion + 110 + IDESourceControlProjectWCCIdentifier + C00DEDE6-CD91-4851-B65D-250053E807CA + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + C00DEDE6-CD91-4851-B65D-250053E807CA + IDESourceControlWCCName + my_enios_fork + + + + diff --git a/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcuserdata/maxyellen.xcuserdatad/UserInterfaceState.xcuserstate b/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcuserdata/maxyellen.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000000000000000000000000000000000000..56b0663a377b9052588b7bf85b5d7678ee599b54 GIT binary patch literal 8485 zcmcIpd3;k<_CNO~&DP}QWoeemQfS#}DQ)Qj2;HG9W$8j`fs(cl8c36pq=izdM?e%r z#~<#44z!>wf++hU$mW8I$R>k0ILtUA@?#WdbX*3Q`|_H!aq#!^kD2Dv=06KsZ8;WgL}`{4k*4hP{79EG>w zBwT?%!JpwX_zQdvSK$k|24BKo;cKEGN}?iaq9Kt)OLT-IdcqS6v63z%j`SkENgvXe z^e0IqnG7St$-QJeDI^ofL^6p?CPic_DJL_DgE+|?GMCIF4WyAQB8$nxMko%W;sX(COb>2w$!K}XU&noq~jLOOvK(J8cy)=+`YqO)l& z_0tC0Naxc9w3$9Y7tGl9=ezAqetjbdW^nD&(llv3jK^; zrC-wP^eg&z`aS(;Nu0aEtl(1sm8Q8t#EE&=tBtcZ@&2OkPiJ@Ar1Lf$UuX*)81v(o*E&6nPIHcpAgP0p~%zVtrl|F zgdl}`AshOyhY>ImG9e3%7=>1}uZJASg*?c|d$1Sw!+4B43kA$4#=uw@2jfMrsB-v( z3ij(2Tx`pY0s@-RRLPgka=L_}g9Z&M@iD9zROeXGB)D9Hdr*zgD7ZZJf_G3|Q>EZ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J + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/xcschememanagement.plist b/ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..01cdf02 --- /dev/null +++ b/ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + ENAPILibrary.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 7EE1165316A3212F00A62D4D + + primary + + + 7EE1166416A3213000A62D4D + + primary + + + + + diff --git a/ENAPILibrary/ENAPILibrary/ENAPIRequest.h b/ENAPILibrary/ENAPILibrary/ENAPIRequest.h index aab6618..01c6fad 100755 --- a/ENAPILibrary/ENAPILibrary/ENAPIRequest.h +++ b/ENAPILibrary/ENAPILibrary/ENAPIRequest.h @@ -88,7 +88,6 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve + (NSArray *)securedEndpoints; + (BOOL)isSecuredEndpoint:(NSString *)endpoint; - /** * Execute a Echo Nest Web Service GET request and represent the JSON response as a dictionary object. @param endpoint The Echo Nest webservice endpoint. @@ -100,6 +99,19 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve andParameters:(NSDictionary *)parameters andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock; +/** + * Execute a Echo Nest Web Service GET request and represent the JSON response as a dictionary object. + @param endpoint The Echo Nest webservice endpoint. + @param parameters The parameters for this endpoint as key/value pairs. + @param completionBlock The block of code to be executed on completion of the request, the request instance is returned as a parameter to allow access to the response and/or error information. + @param allowCachedData Whether or not a cached response is allowed. The default value is YES. + @return Returns the request instance, intended to be used for debugging or canceling an individual request. + */ ++ (ENAPIRequest *)GETWithEndpoint:(NSString *)endpoint + andParameters:(NSDictionary *)parameters + andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock + allowCachedData:(BOOL)allowCachedData; + /** * Execute a Echo Nest Web Service POST request and represent the JSON response as a dictionary object. @param endpoint The Echo Nest webservice endpoint. @@ -111,6 +123,19 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve andParameters:(NSDictionary *)parameters andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock; +/** + * Execute a Echo Nest Web Service POST request and represent the JSON response as a dictionary object. + @param endpoint The Echo Nest webservice endpoint. + @param parameters The parameters for this endpoint as key/value pairs. + @param completionBlock The block of code to be executed on completion of the request, the request instance is returned as a parameter to allow access to the response data and/or error information. + @param allowCachedData Whether or not a cached response is allowed. The default value is YES. + @return returns The request instance, intended to be used for debugging or canceling an individual request. + */ ++ (ENAPIRequest *)POSTWithEndpoint:(NSString *)endpoint + andParameters:(NSDictionary *)parameters + andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock + allowCachedData:(BOOL)allowCachedData; + /** * Cancels all active requests. */ @@ -176,5 +201,10 @@ static NSString __attribute__((unused)) * const ECHONEST_API_URL = @"http://deve */ @property (nonatomic, strong, readonly) NSData *data; +/** + * Whether or not cached data is allowed for the response. + */ +@property (readonly) BOOL cachedDataAllowed; + @end diff --git a/ENAPILibrary/ENAPILibrary/ENAPIRequest.m b/ENAPILibrary/ENAPILibrary/ENAPIRequest.m index bdc6264..a6e0570 100755 --- a/ENAPILibrary/ENAPILibrary/ENAPIRequest.m +++ b/ENAPILibrary/ENAPILibrary/ENAPIRequest.m @@ -70,6 +70,8 @@ @implementation ENAPIRequest @synthesize urlResponse = _urlResponse; @synthesize connection = _connection; +@synthesize cachedDataAllowed = _cachedDataAllowed; + static NSString *EN_API_KEY = nil; static NSString *EN_CONSUMER_KEY = nil; static NSString *EN_SHARED_SECRET = nil; @@ -80,6 +82,13 @@ @implementation ENAPIRequest - (ENAPIRequest *)initWithEndpoint:(NSString *)endpoint andParameters:(NSDictionary *)parameters andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock { + return [self initWithEndpoint:endpoint andParameters:parameters andCompletionBlock:completionBlock allowCachedData:YES]; +} + +- (ENAPIRequest *)initWithEndpoint:(NSString *)endpoint + andParameters:(NSDictionary *)parameters + andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock + allowCachedData:(BOOL)allowCachedData { self = [super init]; if (self) { @@ -87,6 +96,7 @@ - (ENAPIRequest *)initWithEndpoint:(NSString *)endpoint //CHECK_API_KEY self.completionBlock = completionBlock; _endpoint = endpoint; + _cachedDataAllowed = allowCachedData; [self.parameters addEntriesFromDictionary:parameters]; [self.parameters setValue:[ENAPIRequest apiKey] forKey:@"api_key"]; [self.parameters setValue:@"json" forKey:@"format"]; @@ -174,7 +184,7 @@ - (void)initiateGetRequest { [request setTimeoutInterval:requestTimeoutInterval]; - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + if (!self.cachedDataAllowed) [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; self.connection =[[NSURLConnection alloc] initWithRequest:request delegate:self]; @@ -196,7 +206,7 @@ - (void)initiatePostRequest { [request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary] forHTTPHeaderField:@"Content-Type"]; - [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + if (!self.cachedDataAllowed) [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; @@ -248,9 +258,21 @@ + (ENAPIRequest *)GETWithEndpoint:(NSString *)endpoint andParameters:(NSDictionary *)parameters andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock { + return [[self class] GETWithEndpoint:endpoint + andParameters:parameters + andCompletionBlock:completionBlock + allowCachedData:YES]; +} + ++ (ENAPIRequest *)GETWithEndpoint:(NSString *)endpoint + andParameters:(NSDictionary *)parameters + andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock + allowCachedData:(BOOL)allowCachedData { + ENAPIRequest *request = [[ENAPIRequest alloc] initWithEndpoint:endpoint andParameters:parameters - andCompletionBlock:completionBlock]; + andCompletionBlock:completionBlock + allowCachedData:allowCachedData]; [request initiateGetRequest]; return request; @@ -260,9 +282,21 @@ + (ENAPIRequest *)POSTWithEndpoint:(NSString *)endpoint andParameters:(NSDictionary *)parameters andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock { + return [[self class] POSTWithEndpoint:endpoint + andParameters:parameters + andCompletionBlock:completionBlock + allowCachedData:YES]; +} + ++ (ENAPIRequest *)POSTWithEndpoint:(NSString *)endpoint + andParameters:(NSDictionary *)parameters + andCompletionBlock:(ENAPIRequestCompletionBlock)completionBlock + allowCachedData:(BOOL)allowCachedData { + ENAPIRequest *request = [[ENAPIRequest alloc] initWithEndpoint:endpoint andParameters:parameters - andCompletionBlock:completionBlock]; + andCompletionBlock:completionBlock + allowCachedData:allowCachedData]; [request initiatePostRequest]; return request; }