forked from lint/TFDidThatSay
		
	More descriptive error messages
This commit is contained in:
		@ -6,7 +6,7 @@
 | 
				
			|||||||
+ (void)getUndeleteDataWithID:(NSString *)ident isComment:(BOOL)isComment timeout:(CGFloat)timeout extraData:(NSDictionary *)extra completionTarget:(id)target completionSelector:(SEL)sel {
 | 
					+ (void)getUndeleteDataWithID:(NSString *)ident isComment:(BOOL)isComment timeout:(CGFloat)timeout extraData:(NSDictionary *)extra completionTarget:(id)target completionSelector:(SEL)sel {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
 | 
						NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
 | 
				
			||||||
	NSOperationQueue *queue = [[NSOperationQueue alloc] init];
 | 
						//NSOperationQueue *queue = [[NSOperationQueue alloc] init];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (isComment){
 | 
						if (isComment){
 | 
				
			||||||
		[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
 | 
							[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
 | 
				
			||||||
@ -17,27 +17,31 @@
 | 
				
			|||||||
	[request setHTTPMethod:@"GET"];
 | 
						[request setHTTPMethod:@"GET"];
 | 
				
			||||||
	[request setTimeoutInterval:timeout];
 | 
						[request setTimeoutInterval:timeout];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
 | 
						NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
 | 
				
			||||||
 | 
						//[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		NSString *author = @"[author]";
 | 
							NSString *author = @"[author]";
 | 
				
			||||||
		NSString *body = @"[body]";
 | 
							NSString *body = @"[body]";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (data != nil && error == nil){
 | 
							if (data) {
 | 
				
			||||||
			id jsonData = [[NSJSONSerialization JSONObjectWithData:data options:0 error:&error] objectForKey:@"data"];
 | 
								id jsonData = [[NSJSONSerialization JSONObjectWithData:data options:0 error:&error] objectForKey:@"data"];
 | 
				
			||||||
			if ([jsonData count] != 0){
 | 
								if (jsonData && [jsonData count] != 0) {
 | 
				
			||||||
				author = [jsonData[0] objectForKey:@"author"];
 | 
									author = [jsonData[0] objectForKey:@"author"];
 | 
				
			||||||
				body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[0] objectForKey:@"selftext"];
 | 
									body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[0] objectForKey:@"selftext"];
 | 
				
			||||||
				if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
 | 
									if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
 | 
				
			||||||
					body = @"[pushshift was unable to archive this]";
 | 
										body = [NSString stringWithFormat:@"[pushshift was unable to archive this %@]", isComment ? @"comment" : @"post"];
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				body = @"[pushshift has not archived this yet]";
 | 
									body = [NSString stringWithFormat:@"[no data for this %@ was returned by pushshift]", isComment ? @"comment" : @"post"];
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else if (error != nil || data == nil){
 | 
					 | 
				
			||||||
			body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		NSMutableDictionary *result =  [@{@"author" : author, @"body" : body} mutableCopy];
 | 
							if (error) {
 | 
				
			||||||
 | 
								body = [NSString stringWithFormat:@"[an error occurred while attempting retrieve data from the pushshift api]\n\nHTTP Status Code: %li\n\nError Description: %@",
 | 
				
			||||||
 | 
								(long)((NSHTTPURLResponse *)response).statusCode, [error localizedDescription]];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:@{@"author" : author, @"body" : body}];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (extra){
 | 
							if (extra){
 | 
				
			||||||
			[result addEntriesFromDictionary:extra];
 | 
								[result addEntriesFromDictionary:extra];
 | 
				
			||||||
@ -45,9 +49,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		[target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
 | 
							[target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
 | 
				
			||||||
	}];
 | 
						}];
 | 
				
			||||||
 | 
						[dataTask resume];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
+(BOOL) shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly{
 | 
					+ (BOOL)shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!isDeletedOnly){
 | 
						if (!isDeletedOnly){
 | 
				
			||||||
		return YES;
 | 
							return YES;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user