Advertisement
tamasys

refreshItems PodioKit

Feb 10th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)refreshItems {
  2.     NSInteger userId = [[[PKAPIClient sharedClient].oauthToken.refData pk_objectForKey:@"id"] integerValue];
  3.    
  4.     //Dictionary-ise the user details
  5.     NSDictionary *userDict = [[NSDictionary alloc] initWithObjectsAndKeys:
  6.                               @(userId), @"id",
  7.                               @"user", @"type",
  8.                               nil];
  9.     // Dictionary-ise the filters, including the dictionary-ised user details
  10.     NSDictionary *filterDict = [[NSDictionary alloc] initWithObjectsAndKeys:
  11.                                 userDict, @"created_by",
  12.                                 nil];
  13.    
  14.     PKRequest *request = [PKItemAPI requestForItemsInAppWithId:cCallsAppID
  15.                                                         viewId:cCallsViewID
  16.                                                        filters:filterDict
  17.                                                         offset:0
  18.                                                          limit:0];
  19.    
  20.     // Attach an object mapping to the request
  21.     request.objectMapping = [PSItemMapping mapping];
  22.     request.objectDataPathComponents = @[@"items"];
  23.  
  24.     [request startWithCompletionBlock:^(NSError *error, PKRequestResult *result) {
  25.         if (error == nil) {
  26.             // Success
  27.             self.items = result.resultData; //Result data contains the mapped objects
  28.             NSLog(@"resultData: %@", result.resultData);
  29.                 // resultData: (null)
  30.             NSLog(@"items: %@", self.items);
  31.                 // items: (null)
  32.             NSLog(@"count of items: %lu", (unsigned long)[self.items count]);
  33.                 // count of items: 0
  34.             NSLog(@"parsedData: %@", result.parsedData);
  35.                 //parsedData: { filtered = 2; items = {...}; total = 11526; }
  36.             [self.tableView reloadData];
  37.         } else {
  38.             // Failure
  39.             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
  40.                                                             message:@"Failed to load data."
  41.                                                            delegate:nil
  42.                                                   cancelButtonTitle:@"OK"
  43.                                                   otherButtonTitles:nil];
  44.             [alert show];
  45.         }
  46.     }];
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement