Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TFHelper.m 2.4KB

4 anos atrás
4 anos atrás
4 anos atrás
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. +(BOOL) shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly{
  38. if (!isDeletedOnly){
  39. return YES;
  40. } else {
  41. if ([content isEqualToString:@"[deleted]"] || [content isEqualToString:@"[removed]"]){
  42. return YES;
  43. } else if ([content hasPrefix:@"[pushshift"] || [content hasPrefix:@"[an error occured"]){
  44. return YES;
  45. }
  46. }
  47. return NO;
  48. }
  49. @end