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 0000000..56b0663 Binary files /dev/null and b/ENAPILibrary/ENAPILibrary.xcodeproj/project.xcworkspace/xcuserdata/maxyellen.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/ENAPILibrary.xcscheme b/ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/ENAPILibrary.xcscheme new file mode 100644 index 0000000..774a643 --- /dev/null +++ b/ENAPILibrary/ENAPILibrary.xcodeproj/xcuserdata/maxyellen.xcuserdatad/xcschemes/ENAPILibrary.xcscheme @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 3b8e2ee..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,6 +184,8 @@ - (void)initiateGetRequest { [request setTimeoutInterval:requestTimeoutInterval]; + if (!self.cachedDataAllowed) [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + self.connection =[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (self.connection == nil) { @@ -194,6 +206,8 @@ - (void)initiatePostRequest { [request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary] forHTTPHeaderField:@"Content-Type"]; + if (!self.cachedDataAllowed) [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; + NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; @@ -244,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; @@ -256,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; }