您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

50 行
2.0KB

  1. #import "TFHelper.h"
  2. @implementation TFHelper
  3. +(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel{
  4. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  5. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  6. if (isComment){
  7. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
  8. } else {
  9. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", ident]]];
  10. }
  11. [request setHTTPMethod:@"GET"];
  12. [request setTimeoutInterval:timeout];
  13. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  14. NSString *author = @"[author]";
  15. NSString *body = @"[body]";
  16. if (data != nil && error == nil){
  17. id jsonData = [[NSJSONSerialization JSONObjectWithData:data options:0 error:&error] objectForKey:@"data"];
  18. if ([jsonData count] != 0){
  19. author = [jsonData[0] objectForKey:@"author"];
  20. body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[0] objectForKey:@"selftext"];
  21. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  22. body = @"[pushshift was unable to archive this]";
  23. }
  24. } else {
  25. body = @"[pushshift has not archived this yet]";
  26. }
  27. } else if (error != nil || data == nil){
  28. body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
  29. }
  30. NSMutableDictionary *result = [@{@"author" : author, @"body" : body} mutableCopy];
  31. if (extra){
  32. [result addEntriesFromDictionary:extra];
  33. }
  34. [target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
  35. }];
  36. }
  37. @end