Permalink
Browse files

Merge https://github.com/fusenigk/AppSales-Mobile

  • Loading branch information...
2 parents 8283888 + bf0c3aa commit 7f8c0f4b770f190d906493a087e8e6bdf2ce21eb Ole Zorn committed Aug 19, 2011
Showing with 21 additions and 8 deletions.
  1. +21 −8 Classes/ReportDownloadOperation.m
@@ -57,13 +57,18 @@ - (void)main
[moc setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
ASAccount *account = (ASAccount *)[moc objectWithID:accountObjectID];
-
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray *cookies = [cookieStorage cookiesForURL:[NSURL URLWithString:@"https://itunesconnect.apple.com"]];
- for (NSHTTPCookie *cookie in cookies) {
+ for (NSHTTPCookie *cookie in cookies) {
[cookieStorage deleteCookie:cookie];
}
-
+
+ cookies = [cookieStorage cookiesForURL:[NSURL URLWithString:@"https://reportingitc.apple.com"]];
+ for (NSHTTPCookie *cookie in cookies) {
+ [cookieStorage deleteCookie:cookie];
+ }
+
+
dispatch_async(dispatch_get_main_queue(), ^ {
_account.downloadStatus = NSLocalizedString(@"Logging in...", nil);
_account.downloadProgress = 0.0;
@@ -78,7 +83,7 @@ - (void)main
NSError *loginPageError = nil;
NSData *loginPageData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:loginURL] returningResponse:&loginPageResponse error:&loginPageError];
NSString *loginPage = [[[NSString alloc] initWithData:loginPageData encoding:NSUTF8StringEncoding] autorelease];
-
+
if ([loginPage rangeOfString:signoutSentinel].location == NSNotFound) {
// find the login action
NSScanner *loginPageScanner = [NSScanner scannerWithString:loginPage];
@@ -130,7 +135,8 @@ - (void)main
NSError *error = nil;
NSString *salesAction = @"https://reportingitc.apple.com";
NSString *salesRedirectPage = [NSString stringWithContentsOfURL:[NSURL URLWithString:salesAction] usedEncoding:NULL error:&error];
- if (error) {
+
+ if (error) {
dispatch_async(dispatch_get_main_queue(), ^ {
[[NSNotificationCenter defaultCenter] postNotificationName:ASReportDownloadFailedNotification
object:self
@@ -174,6 +180,7 @@ - (void)main
// get the form field names needed to download the report
NSString *salesPage = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://reportingitc.apple.com/sales.faces"] usedEncoding:NULL error:NULL];
+
if (salesPage.length == 0) {
dispatch_async(dispatch_get_main_queue(), ^ {
[[NSNotificationCenter defaultCenter] postNotificationName:ASReportDownloadFailedNotification
@@ -200,6 +207,7 @@ - (void)main
// parse days available
NSMutableArray *availableDays = [[[self extractFormOptionsFromPage:salesPage formID:@"theForm:datePickerSourceSelectElement"] mutableCopy] autorelease];
+
if (availableDays == nil) {
dispatch_async(dispatch_get_main_queue(), ^ {
[[NSNotificationCenter defaultCenter] postNotificationName:ASReportDownloadFailedNotification
@@ -275,8 +283,8 @@ - (void)main
NSString *label = [Report identifierForDate:existingReportDate];
[existingDailyReportLabels addObject:label];
}
- [availableDays removeObjectsInArray:existingDailyReportLabels];
-
+
+ [availableDays removeObjectsInArray:existingDailyReportLabels];
NSFetchRequest *existingWeeklyReportsRequest = [[[NSFetchRequest alloc] init] autorelease];
[existingWeeklyReportsRequest setEntity:[NSEntityDescription entityForName:@"WeeklyReport" inManagedObjectContext:moc]];
[existingWeeklyReportsRequest setPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND endDate IN %@", account, [NSSet setWithArray:availableWeekDates]]];
@@ -316,7 +324,9 @@ - (void)main
daySelectName, @"selectName", nil];
NSString *originalFilename = nil;
- NSData *dailyReportData = [self downloadReportFromiTCWithInfo:downloadInfo viewState:&viewState originalFilename:&originalFilename];
+
+ NSData *dailyReportData = [self downloadReportFromiTCWithInfo:downloadInfo viewState:&viewState originalFilename:&originalFilename];
+
NSData *uncompressedDailyReportData = [dailyReportData gzipInflate];
NSString *dailyReportCSV = [[[NSString alloc] initWithData:uncompressedDailyReportData encoding:NSUTF8StringEncoding] autorelease];
@@ -650,6 +660,9 @@ - (NSData *)downloadReportFromiTCWithInfo:(NSDictionary *)downloadInfo viewState
nil];
NSHTTPURLResponse *downloadResponse = nil;
NSData *requestResponseData = [self dataFromSynchronousPostRequestWithURL:[NSURL URLWithString:@"https://reportingitc.apple.com/sales.faces"] bodyDictionary:postDict response:&downloadResponse];
+
+ NSData *uncompressedDailyReportData = [requestResponseData gzipInflate];
+ NSString *dailyReportCSV = [[[NSString alloc] initWithData:uncompressedDailyReportData encoding:NSUTF8StringEncoding] autorelease];
NSDictionary *responseHeaders = [downloadResponse allHeaderFields];
NSString *originalFilename = [responseHeaders objectForKey:@"Filename"];
if (!originalFilename) originalFilename = [responseHeaders objectForKey:@"filename"];

0 comments on commit 7f8c0f4

Please sign in to comment.