From 5e8d96a96ce86aa654f3a0ac82be013499472100 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 10 May 2018 11:57:39 -0400 Subject: [PATCH] Consolidation --- .../LoadHandling/FreeBee/MFFreebeeHandler.h | 1 + .../LoadHandling/FreeBee/MFFreebeeHandler.m | 52 ++++++++----------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.h b/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.h index 9ab7393..a737d45 100644 --- a/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.h +++ b/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.h @@ -44,6 +44,7 @@ typedef void(^FreebeeLoadFinishedHandler)(MVMCoreOperation* _Nullable freebeeOpe - (BOOL)isFreeBeeAuthorizedValidUrl:(nullable NSURL*)url; - (nullable NSString*)urlForidFromConfigDict:(nonnull NSString*)urlId; +// Tries to get the data using freebee. If freebee is not enabled, gets the data without freebee. - (nullable NSData*)freebee_dataWithContentsOfURL:(NSURL *_Nullable)url; - (nullable NSCachedURLResponse*)freebee_dataWithImageURL:(NSURL *_Nullable)imageURL; diff --git a/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.m b/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.m index 698043b..ef3a0fa 100644 --- a/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.m +++ b/MVMCore/MVMCore/LoadHandling/FreeBee/MFFreebeeHandler.m @@ -230,25 +230,29 @@ typedef NS_ENUM(NSUInteger, FreeBeeCampaignState) { } #pragma mark FreeBee Helper for NSData -- (nullable NSData*)freebee_dataWithContentsOfURL:(NSURL *)url { - - NSData* data = nil; - NSDictionary* proxyDict = [self proxyDictionaryforUrl:url]; + +- (nullable NSData *)freebeeDataWithURL:(NSURL *)url response:(NSURLResponse **)response { + NSData *data = nil; + NSDictionary *proxyDict = [self proxyDictionaryforUrl:url]; if ([self isFreeBeeEnabled] && [self isValidCampaign] && proxyDict && ![self isExpired] && [self isFreeBeeEnabledForCurrentModule]) { + + MVMCoreLog(@"Free Data Url, %@", url); + NSError *error = nil; + data = [self sendSynchronousRequest:url returningResponse:response error:&error]; + if (error) { + data = nil; + } + MVMCoreLog(@"freebee_dataWithContentsOfURL:Free Data, %lu", (unsigned long)data.length); + } + return data; +} - MVMCoreLog(@"Free Data Url, %@", url); - NSURLResponse* response = nil; - NSError* error = nil; - data = [self sendSynchronousRequest:url returningResponse:&response error:&error]; - - if (error) - data = nil; - - MVMCoreLog(@"freebee_dataWithContentsOfURL:Free Data, %lu", (unsigned long)data.length); - } else { +- (nullable NSData*)freebee_dataWithContentsOfURL:(NSURL *)url { + NSData *data = [self freebeeDataWithURL:url response:nil]; + if (!data) { data = [NSData dataWithContentsOfURL:url]; } return data; @@ -256,23 +260,9 @@ typedef NS_ENUM(NSUInteger, FreeBeeCampaignState) { - (nullable NSCachedURLResponse*)freebee_dataWithImageURL:(NSURL *)imageURL { - NSData* data = nil; - NSDictionary* proxyDict = [self proxyDictionaryforUrl:imageURL]; - - if ([self isFreeBeeEnabled] && - [self isValidCampaign] && proxyDict && - ![self isExpired] && [self isFreeBeeEnabledForCurrentModule]) { - - MVMCoreLog(@"Free Image Data Url, %@", imageURL); - NSURLResponse* response = nil; - NSError* error = nil; - data = [self sendSynchronousRequest:imageURL returningResponse:&response error:&error]; - - if (error) { - data = nil; - } - - MVMCoreLog(@"freebee_dataWithImageURL:Free Image Data, %lu", (unsigned long)data.length); + NSURLResponse *response = nil; + NSData *data = [self freebeeDataWithURL:imageURL response:&response]; + if (data) { NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data]; return cachedResponse; }